diff --git a/test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs b/test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs index e8b5b463..da3f5c29 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +using System.Xml.Linq; using FluentAssertions; +using Newtonsoft.Json; using Xunit; namespace System.Linq.Dynamic.Core.Tests @@ -98,5 +100,27 @@ public void DynamicClass_SettingNewProperty_ByIndex_Should_Work() var value = item["X"] as string; value.Should().Be(newTest); } + + [Fact] + public void DynamicClass_SerializeToJson_Should_Work() + { + // Arrange + var props = new[] + { + new DynamicProperty("Name", typeof(string)), + new DynamicProperty("Birthday", typeof(DateTime)) + }; + var type = DynamicClassFactory.CreateType(props); + + var dynamicClass = (DynamicClass) Activator.CreateInstance(type); + dynamicClass.SetDynamicPropertyValue("Name", "Albert"); + dynamicClass.SetDynamicPropertyValue("Birthday", new DateTime(1879, 3, 14)); + + // Act + var json = JsonConvert.SerializeObject(dynamicClass); + + // Assert + json.Should().Be("{\"Name\":\"Albert\",\"Birthday\":\"1879-03-14T00:00:00\"}"); + } } } \ No newline at end of file