Skip to content

Commit

Permalink
Merge pull request #1 from istrupin/dotnetcore-support
Browse files Browse the repository at this point in the history
Dotnetcore support
  • Loading branch information
istrupin authored Apr 27, 2020
2 parents 5b9531c + 6835a31 commit f7e0971
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 276 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ build/
[Bb]in/
[Oo]bj/


# Visual Studio 2015/2017 cache/options directory
.vs/

# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aq.ExpressionJsonSerializer\Aq.ExpressionJsonSerializer.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace Aq.ExpressionJsonSerializer.Tests
namespace Aq.ExpressionJsonSerializer.Test
{
[TestClass]
public class ExpressionJsonSerializerTest
Expand Down Expand Up @@ -79,7 +79,7 @@ public void Decrement()
[TestMethod]
public void DivisionWithCast()
{
TestExpression((Expression<Func<Context, float>>) (c => (float) c.A / c.B));
TestExpression((Expression<Func<Context, float>>) (c => (float)c.A / c.B));
}

[TestMethod]
Expand Down Expand Up @@ -133,7 +133,7 @@ public void Constant()
[TestMethod]
public void Lambda()
{
TestExpression((Expression<Func<Context, int>>) (c => ((Func<Context, int>) (_ => _.A))(c)));
TestExpression((Expression<Func<Context, int>>) (c => ((Func<Context, int>) (_ => _.A)) (c)));
}

[TestMethod]
Expand All @@ -157,7 +157,7 @@ public void Negation()
[TestMethod]
public void New()
{
TestExpression((Expression<Func<Context, object>>) (c => new object()));
TestExpression((Expression<Func<Context, object>>) (c => new object()));
}

[TestMethod]
Expand Down Expand Up @@ -187,7 +187,7 @@ public void TypeAs()
[TestMethod]
public void TypeOf()
{
TestExpression((Expression<Func<Context, bool>>) (c => typeof (Context) == c.GetType()));
TestExpression((Expression<Func<Context, bool>>) (c => typeof(Context) == c.GetType()));
}

[TestMethod]
Expand All @@ -199,7 +199,7 @@ public void TypeIs()
[TestMethod]
public void MethodResultCast()
{
TestExpression((Expression<Func<Context, int>>) (c => (int) c.Method3()));
TestExpression((Expression<Func<Context, int>>) (c => (int)c.Method3()));
}

private sealed class Context
Expand All @@ -212,7 +212,8 @@ public int this[string key]
{
get
{
switch (key) {
switch (key)
{
case "A": return this.A;
case "B": return this.B;
case "C": return this.C ?? 0;
Expand All @@ -226,21 +227,30 @@ public int this[string key]
public object Method3() { return this.A; }
}

private static JsonSerializerSettings CreateSerializerSettings()
{
var settings = new JsonSerializerSettings();
settings.PreserveReferencesHandling = PreserveReferencesHandling.None;
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
return settings;
}

private static void TestExpression(LambdaExpression source)
{
var random = new Random();
int u;
var context = new Context {
var context = new Context
{
A = random.Next(),
B = random.Next(),
C = (u = random.Next(0, 2)) == 0 ? null : (int?) u,
C = (u = random.Next(0, 2)) == 0 ? null : (int?)u,
Array = new[] { random.Next() },
Func = () => u
};

var settings = new JsonSerializerSettings();
var settings = CreateSerializerSettings();
settings.Converters.Add(new ExpressionJsonConverter(
Assembly.GetAssembly(typeof (ExpressionJsonSerializerTest))
Assembly.GetAssembly(typeof(ExpressionJsonSerializerTest))
));

var json = JsonConvert.SerializeObject(source, settings);
Expand All @@ -254,7 +264,7 @@ private static void TestExpression(LambdaExpression source)

private static string ExpressionResult(LambdaExpression expr, Context context)
{
return JsonConvert.SerializeObject(expr.Compile().DynamicInvoke(context));
return JsonConvert.SerializeObject(expr.Compile().DynamicInvoke(context), CreateSerializerSettings());
}
}
}

This file was deleted.

36 changes: 0 additions & 36 deletions Aq.ExpressionJsonSerializer.Tests/Properties/AssemblyInfo.cs

This file was deleted.

19 changes: 12 additions & 7 deletions Aq.ExpressionJsonSerializer.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aq.ExpressionJsonSerializer", "Aq.ExpressionJsonSerializer\Aq.ExpressionJsonSerializer.csproj", "{F6FD2AAC-7409-48A1-80C5-112CCAF4FA1A}"
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aq.ExpressionJsonSerializer", "Aq.ExpressionJsonSerializer\Aq.ExpressionJsonSerializer.csproj", "{F6FD2AAC-7409-48A1-80C5-112CCAF4FA1A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aq.ExpressionJsonSerializer.Tests", "Aq.ExpressionJsonSerializer.Tests\Aq.ExpressionJsonSerializer.Tests.csproj", "{348525AE-72C1-4250-81D2-79D244856F7C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aq.ExpressionJsonSerializer.Tests", "Aq.ExpressionJsonSerializer.Test\Aq.ExpressionJsonSerializer.Tests.csproj", "{98257E4E-4391-44E6-8FEA-8331B43221E0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,12 +17,15 @@ Global
{F6FD2AAC-7409-48A1-80C5-112CCAF4FA1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6FD2AAC-7409-48A1-80C5-112CCAF4FA1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6FD2AAC-7409-48A1-80C5-112CCAF4FA1A}.Release|Any CPU.Build.0 = Release|Any CPU
{348525AE-72C1-4250-81D2-79D244856F7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{348525AE-72C1-4250-81D2-79D244856F7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{348525AE-72C1-4250-81D2-79D244856F7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{348525AE-72C1-4250-81D2-79D244856F7C}.Release|Any CPU.Build.0 = Release|Any CPU
{98257E4E-4391-44E6-8FEA-8331B43221E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98257E4E-4391-44E6-8FEA-8331B43221E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98257E4E-4391-44E6-8FEA-8331B43221E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98257E4E-4391-44E6-8FEA-8331B43221E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E579E7FD-CCD3-4849-95BF-9A743EBE4CCC}
EndGlobalSection
EndGlobal
Loading

0 comments on commit f7e0971

Please sign in to comment.