Skip to content

Instantly share code, notes, and snippets.

@mkoertgen
Created February 15, 2015 20:15
Show Gist options
  • Save mkoertgen/89bf63ca7509890e86ed to your computer and use it in GitHub Desktop.
Save mkoertgen/89bf63ca7509890e86ed to your computer and use it in GitHub Desktop.
A learning test for SerializeLinq
using System;
using System.Linq.Expressions;
using FluentAssertions;
using NUnit.Framework;
using Serialize.Linq.Serializers;
namespace Hello.SerializeLinq
{
[TestFixture]
// ReSharper disable once InconsistentNaming
class SerializeLinq_Should
{
[Test]
public void Support_serializing_simple_funcs_on_classes()
{
Expression<Func<Person, Person>> expected = p => new Person(p) { Name = "test"};
var serializer = new ExpressionSerializer(new JsonSerializer());
serializer.CanSerializeText.Should().BeTrue();
var output = serializer.SerializeText(expected);
var actual = serializer.DeserializeText(output) as Expression<Func<Person,Person>>;
actual.Should().NotBeNull();
var p0 = new Person {Name = "<none>"};
var p1 = expected.Compile().Invoke(p0);
var p2 = actual.Compile().Invoke(p0);
p1.ShouldBeEquivalentTo(p2);
}
class Person
{
public Person(Person person = null)
{
if (person != null) Name = person.Name;
}
public string Name { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment