Created
February 15, 2015 20:15
-
-
Save mkoertgen/89bf63ca7509890e86ed to your computer and use it in GitHub Desktop.
A learning test for SerializeLinq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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