diff --git a/src/System.Linq.Dynamic.Core/DynamicClassFactory.cs b/src/System.Linq.Dynamic.Core/DynamicClassFactory.cs index d705ffe3..45134023 100644 --- a/src/System.Linq.Dynamic.Core/DynamicClassFactory.cs +++ b/src/System.Linq.Dynamic.Core/DynamicClassFactory.cs @@ -465,4 +465,4 @@ private static string Escape(string str) } } } -#endif +#endif \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/DynamicClassFactoryTests.cs b/test/System.Linq.Dynamic.Core.Tests/DynamicClassFactoryTests.cs index 39d43aaf..be022a52 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DynamicClassFactoryTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DynamicClassFactoryTests.cs @@ -3,88 +3,87 @@ using FluentAssertions; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public class DynamicClassFactoryTests { - public class DynamicClassFactoryTests + [Fact] + public void CreateGenericComparerTypeForInt() + { + // Assign + var comparer = new CustomCaseInsensitiveComparer(); + var comparerGenericType = typeof(IComparer<>).MakeGenericType(typeof(int)); + var a = 1; + var b = 2; + + // Act + var type = DynamicClassFactory.CreateGenericComparerType(comparerGenericType, comparer.GetType()); + + // Assert + var instance = (IComparer)Activator.CreateInstance(type); + int greaterThan = instance.Compare(a, b); + greaterThan.Should().Be(1); + + int equal = instance.Compare(a, a); + equal.Should().Be(0); + + int lessThan = instance.Compare(b, a); + lessThan.Should().Be(-1); + } + + [Fact] + public void CreateGenericComparerTypeForString() + { + // Assign + var comparer = new CustomCaseInsensitiveComparer(); + var comparerGenericType = typeof(IComparer<>).MakeGenericType(typeof(string)); + var a = "a"; + var b = "b"; + + // Act + var type = DynamicClassFactory.CreateGenericComparerType(comparerGenericType, comparer.GetType()); + + // Assert + var instance = (IComparer)Activator.CreateInstance(type); + int greaterThan = instance.Compare(a, b); + greaterThan.Should().Be(1); + + int equal = instance.Compare(a, a); + equal.Should().Be(0); + + int lessThan = instance.Compare(b, a); + lessThan.Should().Be(-1); + } + + [Fact] + public void CreateGenericComparerTypeForDateTime() { - [Fact] - public void CreateGenericComparerTypeForInt() - { - // Assign - var comparer = new CustomCaseInsensitiveComparer(); - var comparerGenericType = typeof(IComparer<>).MakeGenericType(typeof(int)); - var a = 1; - var b = 2; - - // Act - var type = DynamicClassFactory.CreateGenericComparerType(comparerGenericType, comparer.GetType()); - - // Assert - var instance = (IComparer)Activator.CreateInstance(type); - int greaterThan = instance.Compare(a, b); - greaterThan.Should().Be(1); - - int equal = instance.Compare(a, a); - equal.Should().Be(0); - - int lessThan = instance.Compare(b, a); - lessThan.Should().Be(-1); - } - - [Fact] - public void CreateGenericComparerTypeForString() - { - // Assign - var comparer = new CustomCaseInsensitiveComparer(); - var comparerGenericType = typeof(IComparer<>).MakeGenericType(typeof(string)); - var a = "a"; - var b = "b"; - - // Act - var type = DynamicClassFactory.CreateGenericComparerType(comparerGenericType, comparer.GetType()); - - // Assert - var instance = (IComparer)Activator.CreateInstance(type); - int greaterThan = instance.Compare(a, b); - greaterThan.Should().Be(1); - - int equal = instance.Compare(a, a); - equal.Should().Be(0); - - int lessThan = instance.Compare(b, a); - lessThan.Should().Be(-1); - } - - [Fact] - public void CreateGenericComparerTypeForDateTime() - { - // Assign - var comparer = new CustomCaseInsensitiveComparer(); - var comparerGenericType = typeof(IComparer<>).MakeGenericType(typeof(DateTime)); - var a = new DateTime(2022, 1, 1); - var b = new DateTime(2023, 1, 1); - - // Act - var type = DynamicClassFactory.CreateGenericComparerType(comparerGenericType, comparer.GetType()); - - // Assert - var instance = (IComparer)Activator.CreateInstance(type); - int greaterThan = instance.Compare(a, b); - greaterThan.Should().Be(1); - - int equal = instance.Compare(a, a); - equal.Should().Be(0); - - int lessThan = instance.Compare(b, a); - lessThan.Should().Be(-1); - } + // Assign + var comparer = new CustomCaseInsensitiveComparer(); + var comparerGenericType = typeof(IComparer<>).MakeGenericType(typeof(DateTime)); + var a = new DateTime(2022, 1, 1); + var b = new DateTime(2023, 1, 1); + + // Act + var type = DynamicClassFactory.CreateGenericComparerType(comparerGenericType, comparer.GetType()); + + // Assert + var instance = (IComparer)Activator.CreateInstance(type); + int greaterThan = instance.Compare(a, b); + greaterThan.Should().Be(1); + + int equal = instance.Compare(a, a); + equal.Should().Be(0); + + int lessThan = instance.Compare(b, a); + lessThan.Should().Be(-1); } +} - public class CustomCaseInsensitiveComparer : IComparer +public class CustomCaseInsensitiveComparer : IComparer +{ + public int Compare(object x, object y) { - public int Compare(object x, object y) - { - return new CaseInsensitiveComparer().Compare(y, x); - } + return new CaseInsensitiveComparer().Compare(y, x); } -} \ No newline at end of file +} diff --git a/test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs b/test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs index da3f5c29..cb8ae77d 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs @@ -1,126 +1,386 @@ using System.Collections.Generic; -using System.Xml.Linq; +using System.Dynamic; using FluentAssertions; using Newtonsoft.Json; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public class DynamicClassTest { - public class DynamicClassTest - { - [Fact] - public void DynamicClass_GetProperties_Should_Work() - { - // Arrange - var range = new List - { - new { FieldName = "TestFieldName", Value = 3.14159 } - }; - - // Act - var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); - var item = rangeResult.First(); - - var call = () => item.GetDynamicMemberNames(); - call.Should().NotThrow(); - } - - [Fact] - public void DynamicClass_GetPropertyValue_Should_Work() - { - // Arrange - var test = "Test"; - var range = new List - { - new { FieldName = test, Value = 3.14159 } - }; - - // Act - var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); - var item = rangeResult.First(); - - var value = item.FieldName as string; - value.Should().Be(test); - } - - [Fact] - public void DynamicClass_GettingValue_ByIndex_Should_Work() - { - // Arrange - var test = "Test"; - var range = new List - { - new { FieldName = test, Value = 3.14159 } - }; - - // Act - var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); - var item = rangeResult.First(); - - var value = item["FieldName"] as string; - value.Should().Be(test); - } - - [Fact] - public void DynamicClass_SettingExistingPropertyValue_ByIndex_Should_Work() - { - // Arrange - var test = "Test"; - var newTest = "abc"; - var range = new List - { - new { FieldName = test, Value = 3.14159 } - }; - - // Act - var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); - var item = rangeResult.First(); - - item["FieldName"] = newTest; - var value = item["FieldName"] as string; - value.Should().Be(newTest); - } - - [Fact] - public void DynamicClass_SettingNewProperty_ByIndex_Should_Work() - { - // Arrange - var test = "Test"; - var newTest = "abc"; - var range = new List - { - new { FieldName = test, Value = 3.14159 } - }; - - // Act - var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); - var item = rangeResult.First(); - - item["X"] = newTest; - 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\"}"); - } + [Fact] + public void DynamicClass_GetProperties_Should_Work() + { + // Arrange + var range = new List + { + new { FieldName = "TestFieldName", Value = 3.14159 } + }; + + // Act + var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); + var item = rangeResult.First(); + + var call = () => item.GetDynamicMemberNames(); + call.Should().NotThrow(); + } + + [Fact] + public void DynamicClass_GetPropertyValue_Should_Work() + { + // Arrange + var test = "Test"; + var range = new List + { + new { FieldName = test, Value = 3.14159 } + }; + + // Act + var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); + var item = rangeResult.First(); + + var value = item.FieldName as string; + value.Should().Be(test); + } + + [Fact] + public void DynamicClass_GettingValue_ByIndex_Should_Work() + { + // Arrange + var test = "Test"; + var range = new List + { + new { FieldName = test, Value = 3.14159 } + }; + + // Act + var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); + var item = rangeResult.First(); + + var value = item["FieldName"] as string; + value.Should().Be(test); + } + + [Fact] + public void DynamicClass_SettingExistingPropertyValue_ByIndex_Should_Work() + { + // Arrange + var test = "Test"; + var newTest = "abc"; + var range = new List + { + new { FieldName = test, Value = 3.14159 } + }; + + // Act + var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); + var item = rangeResult.First(); + + item["FieldName"] = newTest; + var value = item["FieldName"] as string; + value.Should().Be(newTest); + } + + [Fact] + public void DynamicClass_SettingNewProperty_ByIndex_Should_Work() + { + // Arrange + var test = "Test"; + var newTest = "abc"; + var range = new List + { + new { FieldName = test, Value = 3.14159 } + }; + + // Act + var rangeResult = range.AsQueryable().Select("new(FieldName as FieldName)").ToDynamicList(); + var item = rangeResult.First(); + + item["X"] = newTest; + var value = item["X"] as string; + value.Should().Be(newTest); + } + + [Fact] + public void DynamicClass_SerializeToNewtonsoftJson_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\"}"); + } + + private static Type GetRuntimeType(in TValue value) + { + return typeof(TValue); + } + + [Fact] + public void DynamicClass_GetRuntimeType() + { + // Arrange + var props = new[] + { + new DynamicProperty("Name", typeof(string)), + new DynamicProperty("Birthday", typeof(DateTime)) + }; + var type = DynamicClassFactory.CreateType(props); + + // Act + var dynamicInstance = (DynamicClass)Activator.CreateInstance(type)!; + + // Assert 1 + var getType = dynamicInstance.GetType(); + getType.ToString().Should().Contain("<>f__AnonymousType"); + + // Assert 2 + var typeOf = GetRuntimeType(dynamicInstance); + typeOf.ToString().Should().Be("System.Linq.Dynamic.Core.DynamicClass"); // ??? + } + + [Fact(Skip = "fails on CI build GitHub Actions")] + public void DynamicClassArray() + { + // Arrange + var field = new + { + Name = "firstName", + Value = "firstValue" + }; + var dynamicClasses = new List(); + + var props = new DynamicProperty[] + { + new (field.Name, typeof(string)) + }; + + var type = DynamicClassFactory.CreateType(props); + + var dynamicClass = (DynamicClass)Activator.CreateInstance(type)!; + dynamicClass.SetDynamicPropertyValue(field.Name, field.Value); + + dynamicClasses.Add(dynamicClass); + + var query = dynamicClasses.AsQueryable(); + + // Act + var isValid = query.Any("firstName eq \"firstValue\""); + + // Assert + isValid.Should().BeTrue(); + } + + [Fact] + public void DynamicClassArray_Issue593_Fails() + { + // Arrange + var field = new + { + Name = "firstName", + Value = string.Concat("first", "Value") + }; + var dynamicClasses = new List(); + + var props = new DynamicProperty[] + { + new (field.Name, typeof(string)) + }; + + var type = DynamicClassFactory.CreateType(props); + + var dynamicClass = (DynamicClass)Activator.CreateInstance(type)!; + dynamicClass.SetDynamicPropertyValue(field.Name, field.Value); + + dynamicClasses.Add(dynamicClass); + + var query = dynamicClasses.AsQueryable(); + + // Act + var isValid = query.Any("firstName eq \"firstValue\""); + + // Assert + isValid.Should().BeFalse(); // This should actually be true, but fails. For solution see Issue593_Solution1 and Issue593_Solution2. + } + + [Fact] + public void DynamicClassArray_Issue593_Solution1() + { + // Arrange + var field = new + { + Name = "firstName", + Value = string.Concat("first", "Value") + }; + var dynamicClasses = new List(); + + var props = new DynamicProperty[] + { + new (field.Name, typeof(string)) + }; + + var type = DynamicClassFactory.CreateType(props); + + var dynamicClass = (DynamicClass)Activator.CreateInstance(type)!; + dynamicClass.SetDynamicPropertyValue(field.Name, field.Value); + + dynamicClasses.Add(dynamicClass); + + var query = dynamicClasses.AsQueryable(); + + // Act + var isValid = query.Any("firstName.ToString() eq \"firstValue\""); + + // Assert + isValid.Should().BeTrue(); + } + + [Fact] + public void DynamicClassArray_Issue593_Solution2() + { + // Arrange + var field = new + { + Name = "firstName", + Value = string.Concat("first", "Value") + }; + var dynamicClasses = new List(); + + var props = new DynamicProperty[] + { + new (field.Name, typeof(string)) + }; + + var type = DynamicClassFactory.CreateType(props); + + var dynamicClass = (DynamicClass)Activator.CreateInstance(type)!; + dynamicClass.SetDynamicPropertyValue(field.Name, field.Value); + + dynamicClasses.Add(dynamicClass); + + var query = dynamicClasses.AsQueryable(); + + // Act + var isValid = query.Any("string(firstName) eq \"firstValue\""); + + // Assert + isValid.Should().BeTrue(); + } + +#if NET6_0_OR_GREATER + [Fact] + public void ExpandoObject_SerializeToSystemTextJson_Should_Work() + { + // Arrange + dynamic expandoObject = new ExpandoObject(); + expandoObject.Name = "Albert"; + expandoObject.Birthday = new DateTime(1879, 3, 14); + + // Act + string json = Text.Json.JsonSerializer.Serialize(expandoObject); + + // Assert + json.Should().Be("{\"Name\":\"Albert\",\"Birthday\":\"1879-03-14T00:00:00\"}"); + } + + [Fact(Skip = "fails")] + public void DynamicClass_SerializeToSystemTextJson_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 = Text.Json.JsonSerializer.Serialize(dynamicClass); + + // Assert + json.Should().Be("{\"Name\":\"Albert\",\"Birthday\":\"1879-03-14T00:00:00\"}"); + } + + [Fact] + public void DynamicClass_SerializeToSystemTextJson_TypeOfObject_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 = Text.Json.JsonSerializer.Serialize(dynamicClass, typeof(object)); + + // Assert + json.Should().Be("{\"Name\":\"Albert\",\"Birthday\":\"1879-03-14T00:00:00\"}"); + } + + [Fact] + public void DynamicClass_SerializeToSystemTextJson_TypeOfInstanceType_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 = Text.Json.JsonSerializer.Serialize(dynamicClass, type); + + // Assert + json.Should().Be("{\"Name\":\"Albert\",\"Birthday\":\"1879-03-14T00:00:00\"}"); + } + + [Fact(Skip = "fails")] + public void DynamicClass_SerializeToSystemTextJson_TypeOfDynamicClass_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 = Text.Json.JsonSerializer.Serialize(dynamicClass, typeof(DynamicClass)); + + // Assert + json.Should().Be("{\"Name\":\"Albert\",\"Birthday\":\"1879-03-14T00:00:00\"}"); } +#endif } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs index 818037e1..73df54d7 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs @@ -1502,11 +1502,6 @@ public void DynamicExpressionParser_ParseLambda_String_TrimEnd_1_Parameter() result.Should().BeTrue(); } - public class DefaultDynamicLinqCustomTypeProviderForGenericExtensionMethod : DefaultDynamicLinqCustomTypeProvider - { - public override HashSet GetCustomTypes() => new HashSet(base.GetCustomTypes()) { typeof(Methods), typeof(MethodsItemExtension) }; - } - [Fact] public void DynamicExpressionParser_ParseLambda_GenericExtensionMethod() { @@ -1596,4 +1591,51 @@ public void DynamicExpressionParser_ParseLambda_Func2(string? paramName, string // Assert result.Should().Be(expected); } + + [Fact] + public void DynamicExpressionParser_ParseComparisonOperator_DynamicClass_For_String() + { + // Arrange + var cc = "firstValue".ToCharArray(); + var field = new + { + Name = "firstName", + Value = new string(cc) + }; + + var props = new DynamicProperty[] + { + new DynamicProperty(field.Name, typeof(string)) + }; + + var type = DynamicClassFactory.CreateType(props); + + var dynamicClass = (DynamicClass)Activator.CreateInstance(type); + dynamicClass.SetDynamicPropertyValue(field.Name, field.Value); + + // Act 1 + var parameters = new[] { Expression.Parameter(type, "x") }; + var expression = DynamicExpressionParser.ParseLambda(null, new ParsingConfig(), true, parameters, null, "firstName eq \"firstValue\""); + + var @delegate = expression.Compile(); + + var result = (bool)@delegate.DynamicInvoke(dynamicClass); + + // Assert 1 + result.Should().BeTrue(); + + // Arrange 2 + var array = new[] { field }.AsQueryable(); + + // Act 2 + var isValid = array.Select("it").Any("Value eq \"firstValue\""); + + // Assert 2 + isValid.Should().BeTrue(); + } + + public class DefaultDynamicLinqCustomTypeProviderForGenericExtensionMethod : DefaultDynamicLinqCustomTypeProvider + { + public override HashSet GetCustomTypes() => new HashSet(base.GetCustomTypes()) { typeof(Methods), typeof(MethodsItemExtension) }; + } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs index ac45d263..6ae1a84b 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Linq.Dynamic.Core.Exceptions; using System.Linq.Dynamic.Core.Tests.Helpers.Entities; +using FluentAssertions; using Newtonsoft.Json; #if EFCORE using Microsoft.EntityFrameworkCore; @@ -59,7 +60,7 @@ public void Entities_Select_EmptyObject() // Arrange PopulateTestData(5, 0); - var expected = _context.Blogs.Select(x => new {}).ToList(); + var expected = _context.Blogs.Select(x => new { }).ToList(); // Act var test = _context.Blogs.GroupBy(config, "BlogId", "new()").Select("new()").ToList(); @@ -145,5 +146,21 @@ public void Entities_Select_BlogAndPosts() Assert.Equal(expectedRow.Posts.ToList(), testRow.Posts); } } + + [Fact(Skip = "593 - this does not work")] + public void Entities_Select_DynamicClass_And_Call_Any() + { + // Arrange + PopulateTestData(5, 0); + + // Act + var result = _context.Blogs + .Select("new (BlogId, Name)") + .Cast() + .Any("Name == \"Blog2\""); + + // Assert + Assert.Equal(true, result); + } } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/InternalTests.cs b/test/System.Linq.Dynamic.Core.Tests/InternalTests.cs deleted file mode 100644 index 2be3495f..00000000 --- a/test/System.Linq.Dynamic.Core.Tests/InternalTests.cs +++ /dev/null @@ -1,58 +0,0 @@ -//#if !(NET35 || NETSTANDARD) -using System.Threading.Tasks; -//#endif - -namespace System.Linq.Dynamic.Core.Tests -{ - public class InternalTests - { -#if ABC - [Fact] - public void ClassFactory_LoadTest() - { - //Arrange - var rnd = new Random(1); - - var testPropertiesGroups = new DynamicProperty[][] { - new DynamicProperty[] { - new DynamicProperty("String1", typeof( string )), - }, - new DynamicProperty[] { - new DynamicProperty("String1", typeof( string )), - new DynamicProperty("String2", typeof( string )) - }, - new DynamicProperty[] { - new DynamicProperty("String1", typeof( string )), - new DynamicProperty("Int1", typeof( int )) - }, - new DynamicProperty[] { - new DynamicProperty("Int1", typeof( int )), - new DynamicProperty("Int2", typeof( int )) - }, - new DynamicProperty[] { - new DynamicProperty("String1", typeof( string )), - new DynamicProperty("String2", typeof( string )), - new DynamicProperty("String3", typeof( string )), - }, - }; - - Action testActionSingle = i => - { - ClassFactory.Instance.GetDynamicClass(testPropertiesGroups[0]); - }; - - Action testActionMultiple = i => { - var testProperties = testPropertiesGroups[rnd.Next(0, testPropertiesGroups.Length)]; - - ClassFactory.Instance.GetDynamicClass(testProperties); - }; - - //Act - Parallel.For(0, 100000, testActionSingle); - - Parallel.For(0, 100000, testActionMultiple); - - } -#endif - } -} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj index a4473c01..1f82ea88 100644 --- a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj +++ b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj @@ -5,7 +5,7 @@ System.Linq.Dynamic.Core.Tests full True - 10 + latest ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk {912FBF24-3CAE-4A50-B5EA-E525B9FAEC80}