Skip to content

Commit

Permalink
test and fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
esskar committed Jun 24, 2015
1 parent e2e7d08 commit 05c8dfc
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
107 changes: 107 additions & 0 deletions src/Serialize.Linq.Tests/Issues/Issue50.cs
@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Serialize.Linq.Serializers;

namespace Serialize.Linq.Tests.Issues
{
[TestClass]
public class Issue50
{
[TestMethod]
public void SerializeArrayAsJson()
{
var list = new [] { "one", "two" };
Expression<Func<Test, bool>> expression = test => list.Contains(test.Code);

var serializer = new ExpressionSerializer(new JsonSerializer());
var value = serializer.SerializeText(expression);

Assert.IsNotNull(value);
}

[TestMethod]
public void SerializeArrayAsBinary()
{
var list = new[] { "one", "two" };
Expression<Func<Test, bool>> expression = test => list.Contains(test.Code);

var serializer = new ExpressionSerializer(new BinarySerializer());
var value = serializer.SerializeBinary(expression);

Assert.IsNotNull(value);
}

[TestMethod]
public void SerializeListAsJson()
{
var list = new List<string> { "one", "two" };
Expression<Func<Test, bool>> expression = test => list.Contains(test.Code);

var serializer = new ExpressionSerializer(new JsonSerializer())
{
AutoAddKnownTypesAsListTypes = true
};
var value = serializer.SerializeText(expression);

Assert.IsNotNull(value);
}

[TestMethod]
public void SerializeListAsBinary()
{
var list = new List<string> { "one", "two" };
Expression<Func<Test, bool>> expression = test => list.Contains(test.Code);

var serializer = new ExpressionSerializer(new BinarySerializer())
{
AutoAddKnownTypesAsListTypes = true
};
var value = serializer.SerializeBinary(expression);

Assert.IsNotNull(value);
}

[TestMethod]
public void SerializeDeserializeArrayAsJson()
{
var list = new[] { "one", "two" };
Expression<Func<Test, bool>> expression = test => list.Contains(test.Code);

var serializer = new ExpressionSerializer(new JsonSerializer());
var value = serializer.SerializeText(expression);

var actualExpression = (Expression<Func<Test, bool>>)serializer.DeserializeText(value);
var func = actualExpression.Compile();


Assert.IsTrue(func(new Test { Code = "one" }), "one failed.");
Assert.IsTrue(func(new Test { Code = "two" }), "two failed.");
Assert.IsFalse(func(new Test { Code = "three" }), "three failed.");
}

[TestMethod]
public void SerializeDeserializeArrayAsBinary()
{
var list = new[] { "one", "two" };
Expression<Func<Test, bool>> expression = test => list.Contains(test.Code);

var serializer = new ExpressionSerializer(new BinarySerializer());
var value = serializer.SerializeBinary(expression);

var actualExpression = (Expression<Func<Test, bool>>)serializer.DeserializeBinary(value);
var func = actualExpression.Compile();

Assert.IsTrue(func(new Test { Code = "one" }), "one failed.");
Assert.IsTrue(func(new Test { Code = "two" }), "two failed.");
Assert.IsFalse(func(new Test { Code = "three" }), "three failed.");
}

public class Test
{
public string Code { get; set; }
}
}
}
1 change: 1 addition & 0 deletions src/Serialize.Linq.Tests/Serialize.Linq.Tests.csproj
Expand Up @@ -106,6 +106,7 @@
<Compile Include="Issues\Issue39.cs" />
<Compile Include="Issues\Issue41.cs" />
<Compile Include="Issues\Issue43.cs" />
<Compile Include="Issues\Issue50.cs" />
<Compile Include="MemberInfoExtensionsTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down

0 comments on commit 05c8dfc

Please sign in to comment.