private static TestCaseData CreateTestCase(Type type, TypeMetaInformation expected, string testName) { return(new TestCaseData(type, expected) { TestName = testName }); }
private static TypeMetaInformation GetGenericTypeMeta(TypeMetaInformation typeParameter) { return(new TypeMetaInformation { TypeName = "GenericClass", OriginalTypeName = "GenericClass", GenericTypeArguments = new[] { typeParameter }, Properties = new[] { new PropertyMetaInformation { Name = "String", IsEditable = true, AvailableValues = new string[0], Type = TypeMetaInformation.ForSimpleType("String") }, new PropertyMetaInformation { Name = "Value", IsEditable = true, AvailableValues = new string[0], Type = typeParameter, }, new PropertyMetaInformation { Name = "Values", IsEditable = true, AvailableValues = new string[0], Type = new TypeMetaInformation { TypeName = "List", OriginalTypeName = "List", IsArray = true, Properties = new PropertyMetaInformation[0], GenericTypeArguments = new[] { typeParameter } } }, new PropertyMetaInformation { Name = "MoreValues", IsEditable = true, AvailableValues = new string[0], Type = new TypeMetaInformation { TypeName = "Dictionary", OriginalTypeName = "Dictionary", IsArray = true, Properties = new PropertyMetaInformation[0], GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("String"), typeParameter } } }, } }); }
public static TypeMetaInformation BuildTypeMetaInformation(object? @object, Type type, Type originalType, IPropertyDescriptionBuilder propertyDescriptionBuilder, ICustomPropertyConfigurationProvider? propertyConfigurationProvider, Type[]? usedTypes = null) { usedTypes = (usedTypes ?? new Type[0]).ToArray(); if (usedTypes.Contains(type)) return null; usedTypes = usedTypes.Concat(new[] {type}).ToArray(); var originalTypeName = new Regex(@"`.*").Replace(originalType.Name, ""); type = propertyConfigurationProvider?.TryGetConfiguration(type)?.ResolvedType ?? type; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) return TypeMetaInformation.ForSimpleType(type.GetGenericArguments()[0].Name, isNullable : true); if (IsSimpleType(type)) return TypeMetaInformation.ForSimpleType(type.Name, originalTypeName); var typeName = new Regex(@"`.*").Replace(type.Name, ""); if (typeof(IEnumerable).IsAssignableFrom(type)) { var genericArguments = type.HasElementType ? new[] {type.GetElementType()} : type.GetGenericArguments(); return new TypeMetaInformation { TypeName = typeName, OriginalTypeName = originalTypeName, IsArray = true, Properties = new PropertyMetaInformation[0], GenericTypeArguments = genericArguments .Select(x => BuildTypeMetaInformation(null, x, x, propertyDescriptionBuilder, @object == null ? null : propertyConfigurationProvider, usedTypes)) .ToArray(), }; } return new TypeMetaInformation { TypeName = typeName, OriginalTypeName = originalTypeName, Properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Select(x => BuildPropertyInfo(@object, x, propertyDescriptionBuilder, propertyConfigurationProvider, usedTypes)) .ToArray(), GenericTypeArguments = type.GetGenericArguments() .Select(x => BuildTypeMetaInformation(null, x, x, propertyDescriptionBuilder, @object == null ? null : propertyConfigurationProvider, usedTypes)) .ToArray(), }; }
private static IEnumerable <ITestCaseData> EnumerableTestCasesProvider() { yield return(CreateTestCase(typeof(string[]), new TypeMetaInformation { TypeName = "String[]", OriginalTypeName = "String[]", IsArray = true, Properties = new PropertyMetaInformation[0], GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("String") } }, "ArrayOfStrings")); yield return(CreateTestCase(typeof(List <int?>), new TypeMetaInformation { TypeName = "List", OriginalTypeName = "List", IsArray = true, Properties = new PropertyMetaInformation[0], GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("Int32", isNullable: true) }, }, "ArrayOfNullableInts")); yield return(CreateTestCase(typeof(HashSet <Guid>), new TypeMetaInformation { TypeName = "HashSet", OriginalTypeName = "HashSet", IsArray = true, Properties = new PropertyMetaInformation[0], GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("Guid") }, }, "HashSetOfStrings")); yield return(CreateTestCase(typeof(Dictionary <string, decimal>), new TypeMetaInformation { TypeName = "Dictionary", OriginalTypeName = "Dictionary", IsArray = true, Properties = new PropertyMetaInformation[0], GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("String"), TypeMetaInformation.ForSimpleType("Decimal") }, }, "Dictionary<string, decimal>")); }
private static TypeMetaInformation GetTestClassWithCustomPrimitivesShape() { return(new TypeMetaInformation { TypeName = "TestClassWithCustomPrimitives", OriginalTypeName = "TestClassWithCustomPrimitives", GenericTypeArguments = new TypeMetaInformation[0], Properties = new[] { new PropertyMetaInformation { Type = null, Name = "BaseClass", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("DateTime", "LocalTime", isNullable: true), Name = "LocalTime", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("String", "TimeUuid"), Name = "TimeUuid", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("String", "TimeUuid"), Name = "NullableTimeUuid", IsEditable = true, AvailableValues = new string[0], }, } }); }
private static IEnumerable <ITestCaseData> PrimitivesTestCasesProvider() { yield return(CreateTestCase(typeof(int), TypeMetaInformation.ForSimpleType("Int32"), "Int")); yield return(CreateTestCase(typeof(int?), TypeMetaInformation.ForSimpleType("Int32", isNullable: true), "NullableInt")); yield return(CreateTestCase(typeof(long), TypeMetaInformation.ForSimpleType("Int64"), "Long")); yield return(CreateTestCase(typeof(long?), TypeMetaInformation.ForSimpleType("Int64", isNullable: true), "NullableLong")); yield return(CreateTestCase(typeof(decimal), TypeMetaInformation.ForSimpleType("Decimal"), "Decimal")); yield return(CreateTestCase(typeof(decimal?), TypeMetaInformation.ForSimpleType("Decimal", isNullable : true), "NullableDecimal")); yield return(CreateTestCase(typeof(byte), TypeMetaInformation.ForSimpleType("Byte"), "Byte")); yield return(CreateTestCase(typeof(byte?), TypeMetaInformation.ForSimpleType("Byte", isNullable: true), "NullableByte")); yield return(CreateTestCase(typeof(char), TypeMetaInformation.ForSimpleType("Char"), "Char")); yield return(CreateTestCase(typeof(char?), TypeMetaInformation.ForSimpleType("Char", isNullable: true), "NullableChar")); yield return(CreateTestCase(typeof(bool), TypeMetaInformation.ForSimpleType("Boolean"), "Bool")); yield return(CreateTestCase(typeof(bool?), TypeMetaInformation.ForSimpleType("Boolean", isNullable: true), "NullableBool")); yield return(CreateTestCase(typeof(DateTime), TypeMetaInformation.ForSimpleType("DateTime"), "DateTime")); yield return(CreateTestCase(typeof(DateTime?), TypeMetaInformation.ForSimpleType("DateTime", isNullable : true), "NullableDateTime")); yield return(CreateTestCase(typeof(Guid), TypeMetaInformation.ForSimpleType("Guid"), "Guid")); yield return(CreateTestCase(typeof(Guid?), TypeMetaInformation.ForSimpleType("Guid", isNullable : true), "NullableGuid")); yield return(CreateTestCase(typeof(string), TypeMetaInformation.ForSimpleType("String"), "String")); }
private static IEnumerable <ITestCaseData> EnumTestCasesProvider() { yield return(CreateTestCase(typeof(TestEnum), TypeMetaInformation.ForSimpleType("TestEnum"), "Enum")); yield return(CreateTestCase(typeof(TestEnum?), TypeMetaInformation.ForSimpleType("TestEnum", isNullable : true), "NullableEnum")); }
public void Test_Primitives(Type type, TypeMetaInformation expected) { CheckResult(PropertyHelpers.BuildTypeMetaInformation(null, type, type, new SamplePropertyDescriptionBuilder(), new CustomPropertyConfigurationProvider()), expected); }
private void CheckResult(TypeMetaInformation actual, TypeMetaInformation expected) { actual.Should().BeEquivalentTo(expected, x => x.RespectingRuntimeTypes()); }
public async Task Test_List() { var result = await client.GetTypesDescription(); var schemaDescription = new SchemaDescription { SchemaName = "SampleSchema", DownloadLimit = 100_000, DownloadLimitForSuperUser = 100_000, CountLimit = 10_000, CountLimitForSuperUser = 10_000, AllowReadAll = true, AllowDelete = false, AllowEdit = true, AllowSort = true, }; result.Should().ContainEquivalentOf(new ObjectIdentifier { Identifier = "TestClass", SchemaDescription = schemaDescription, }); var meta = await client.GetTypeMeta("TestClass"); testClassShape.Properties[5].Type = new TypeMetaInformation { TypeName = "Object", OriginalTypeName = "Byte[]", Properties = new PropertyMetaInformation[0], GenericTypeArguments = new TypeMetaInformation[0], }; testClassShape.Properties[6].Type.Properties[0].Type = new TypeMetaInformation { TypeName = "BaseClass", OriginalTypeName = "BaseClass", Properties = new PropertyMetaInformation[0], GenericTypeArguments = new TypeMetaInformation[0], }; testClassShape.Properties[6].Type.Properties[1].Type = new TypeMetaInformation { TypeName = "LocalTime", OriginalTypeName = "LocalTime", GenericTypeArguments = new TypeMetaInformation[0], Properties = new[] { new PropertyMetaInformation { Name = "TotalNanoseconds", IsEditable = true, AvailableValues = new string[0], Type = TypeMetaInformation.ForSimpleType("Int64") }, new PropertyMetaInformation { Name = "Hour", AvailableValues = new string[0], Type = TypeMetaInformation.ForSimpleType("Int32") }, new PropertyMetaInformation { Name = "Minute", AvailableValues = new string[0], Type = TypeMetaInformation.ForSimpleType("Int32") }, new PropertyMetaInformation { Name = "Second", AvailableValues = new string[0], Type = TypeMetaInformation.ForSimpleType("Int32") }, new PropertyMetaInformation { Name = "Nanoseconds", AvailableValues = new string[0], Type = TypeMetaInformation.ForSimpleType("Int32") }, } }; testClassShape.Properties[6].Type.Properties[2].Type.TypeName = "TimeUuid"; testClassShape.Properties[6].Type.Properties[3].Type.TypeName = "TimeUuid"; testClassShape.Properties[6].Type.Properties[3].Type.IsNullable = true; meta.Should().BeEquivalentTo(new ObjectDescription { Identifier = "TestClass", SchemaDescription = schemaDescription, TypeMetaInformation = testClassShape, }); }
public void SetUp() { client = new ApiClient(); var testClassWithCustomPrimitivesShape = GetTestClassWithCustomPrimitivesShape(); var testClassWithAllPrimitivesShape = new TypeMetaInformation { TypeName = "TestClassWithAllPrimitives", OriginalTypeName = "TestClassWithAllPrimitives", GenericTypeArguments = new TypeMetaInformation[0], Properties = new[] { new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("String"), Name = "String", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Guid"), Name = "Guid", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Guid", isNullable: true), Name = "NullableGuid", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Boolean"), Name = "Bool", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Boolean", isNullable: true), Name = "NullableBool", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Byte"), Name = "Byte", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Byte", isNullable: true), Name = "NullableByte", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Char"), Name = "Char", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Char", isNullable: true), Name = "NullableChar", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Int16"), Name = "Short", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Int16", isNullable: true), Name = "NullableShort", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Int32"), Name = "Int", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Int32", isNullable: true), Name = "NullableInt", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Int64"), Name = "Long", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Int64", isNullable: true), Name = "NullableLong", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Decimal"), Name = "Decimal", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("Decimal", isNullable: true), Name = "NullableDecimal", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("DateTime"), Name = "DateTime", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("DateTime", isNullable: true), Name = "NullableDateTime", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("DateTimeOffset"), Name = "DateTimeOffset", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("DateTimeOffset", isNullable: true), Name = "NullableDateTimeOffset", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("TestEnum"), Name = "Enum", IsEditable = true, AvailableValues = new[] { "FirstValue", "SecondValue" }, }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("TestEnum", isNullable: true), Name = "NullableEnum", IsEditable = true, AvailableValues = new[] { "FirstValue", "SecondValue" }, }, new PropertyMetaInformation { Type = new TypeMetaInformation { TypeName = "Int32[]", OriginalTypeName = "Int32[]", IsArray = true, GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("Int32") }, Properties = new PropertyMetaInformation[0], }, Name = "Array", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = new TypeMetaInformation { TypeName = "List", OriginalTypeName = "List", IsArray = true, GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("Int32") }, Properties = new PropertyMetaInformation[0], }, Name = "List", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = new TypeMetaInformation { TypeName = "Dictionary", OriginalTypeName = "Dictionary", IsArray = true, GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("String"), TypeMetaInformation.ForSimpleType("Int32") }, Properties = new PropertyMetaInformation[0], }, Name = "Dictionary", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = new TypeMetaInformation { TypeName = "HashSet", OriginalTypeName = "HashSet", IsArray = true, GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("String") }, Properties = new PropertyMetaInformation[0], }, Name = "HashSet", IsEditable = true, AvailableValues = new string[0], }, } }; testClassShape = new TypeMetaInformation { TypeName = "TestClass", OriginalTypeName = "TestClass", GenericTypeArguments = new TypeMetaInformation[0], Properties = new[] { new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("String"), Name = "Id", IsEditable = true, IsIdentity = true, IsSearchable = true, AvailableFilters = new[] { ObjectFieldFilterOperator.Equals, ObjectFieldFilterOperator.DoesNotEqual }, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = testClassWithAllPrimitivesShape, Name = "Content", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = new TypeMetaInformation { TypeName = "ClassForSerialization", OriginalTypeName = "Byte[]", GenericTypeArguments = new TypeMetaInformation[0], Properties = new[] { new PropertyMetaInformation { Type = testClassWithAllPrimitivesShape, Name = "Content", IsEditable = true, AvailableValues = new string[0], } } }, Name = "Serialized", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = new TypeMetaInformation { TypeName = "Byte[]", OriginalTypeName = "Byte[]", IsArray = true, GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("Byte") }, Properties = new PropertyMetaInformation[0], }, Name = "File", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = TypeMetaInformation.ForSimpleType("DifficultEnum"), Name = "DifficultEnum", IsEditable = true, AvailableValues = new[] { "A", "B" } }, new PropertyMetaInformation { Type = null, Name = "DifficultSerialized", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Type = testClassWithCustomPrimitivesShape, Name = "CustomContent", IsEditable = true, AvailableValues = new string[0], }, new PropertyMetaInformation { Name = "GenericIntValues", IsEditable = true, AvailableValues = new string[0], Type = GetGenericTypeMeta(TypeMetaInformation.ForSimpleType("Int32")) }, new PropertyMetaInformation { Name = "GenericStringValues", IsEditable = true, AvailableValues = new string[0], Type = GetGenericTypeMeta(TypeMetaInformation.ForSimpleType("String")) }, new PropertyMetaInformation { Name = "BaseClass", IsEditable = true, AvailableValues = new string[0], Type = new TypeMetaInformation { TypeName = "BaseClass[]", OriginalTypeName = "BaseClass[]", IsArray = true, Properties = new PropertyMetaInformation[0], GenericTypeArguments = new[] { TypeMetaInformation.ForSimpleType("BaseClass") }, } }, new PropertyMetaInformation { Name = "NotEditable", Type = TypeMetaInformation.ForSimpleType("DifficultEnum"), AvailableValues = new[] { "A", "B" } } }, }; }