public void TestRoundtripIVoidMethodNoParameters() { var expected = new SharpRemote.TypeModel(); expected.Add <IVoidMethodNoParameters>(assumeByReference: true); var actual = Roundtrip(expected); var actualDescription = actual.Get <IVoidMethodNoParameters>(); actualDescription.AssemblyQualifiedName.Should().Be(typeof(IVoidMethodNoParameters).AssemblyQualifiedName); actualDescription.IsBuiltIn.Should().BeFalse(); actualDescription.IsClass.Should().BeFalse(); actualDescription.IsInterface.Should().BeTrue(); actualDescription.IsValueType.Should().BeFalse(); actualDescription.IsEnum.Should().BeFalse(); actualDescription.IsEnumerable.Should().BeFalse(); actualDescription.Type.Should().Be <IVoidMethodNoParameters>("because the type should've been resolved"); actualDescription.Fields.Should().BeEmpty(); actualDescription.Properties.Should().BeEmpty(); actualDescription.Methods.Should().HaveCount(1); var method = actualDescription.Methods[0]; method.Name.Should().Be(nameof(IVoidMethodNoParameters.Do)); method.Parameters.Should().BeEmpty(); method.ReturnParameter.Should().NotBeNull(); var returnParameter = method.ReturnParameter; returnParameter.ParameterType.Should().NotBeNull(); returnParameter.ParameterType.Type.Should().Be(typeof(void)); }
public void TestByReferenceType() { var model = new SharpRemote.TypeModel(); var type = model.Add <IByReferenceType>(); type.AssemblyQualifiedName.Should().Be(typeof(IByReferenceType).AssemblyQualifiedName); type.SerializationType.Should().Be(SerializationType.ByReference); type.IsClass.Should().BeFalse(); type.IsBuiltIn.Should().BeFalse(); type.IsEnum.Should().BeFalse(); type.IsInterface.Should().BeTrue(); type.IsSealed.Should().BeFalse(); type.IsValueType.Should().BeFalse(); type.Fields.Should().BeEmpty("because by reference types cannot have fields"); type.Methods.Should().BeEmpty("because special methods can only be accessed via their property"); type.Properties.Should().HaveCount(1); var property = type.Properties[0]; property.Name.Should().Be("Value"); property.GetMethod.Should().NotBeNull(); property.GetMethod.Name.Should().Be("get_Value"); property.GetMethod.ReturnParameter.Should().NotBeNull(); property.SetMethod.Should().BeNull(); property.PropertyType.AssemblyQualifiedName.Should().Be(typeof(int).AssemblyQualifiedName); }
public void TestAddInt() { var model = new SharpRemote.TypeModel(); var intType = model.Add <int>(); intType.Should().NotBeNull(); var valueType = intType.BaseType; valueType.Should().NotBeNull(); valueType.Type.Should().Be <ValueType>(); var objectType = valueType.BaseType; objectType.Should().NotBeNull(); objectType.Type.Should().Be <object>(); ((TypeDescription)intType).Id.Should().BeGreaterThan(0); ((TypeDescription)valueType).Id.Should().BeGreaterThan(0); ((TypeDescription)objectType).Id.Should().BeGreaterThan(0); ((TypeDescription)intType).BaseTypeId.Should().Be(((TypeDescription)valueType).Id); ((TypeDescription)valueType).BaseTypeId.Should().Be(((TypeDescription)objectType).Id); model.Get <int>().Should().BeSameAs(intType); model.Get <ValueType>().Should().BeSameAs(valueType); model.Get <object>().Should().BeSameAs(objectType); }
private SharpRemote.TypeModel Roundtrip(SharpRemote.TypeModel expected) { var actual = _serializer.Roundtrip(expected); actual.TryResolveTypes(); return(actual); }
public void TestRoundtripFieldUInt32() { var expected = new SharpRemote.TypeModel(); expected.Add <FieldUInt32>(); var actual = Roundtrip(expected); var actualDescription = actual.Get <FieldUInt32>(); actualDescription.AssemblyQualifiedName.Should().Be(typeof(FieldUInt32).AssemblyQualifiedName); actualDescription.IsClass.Should().BeFalse(); actualDescription.IsBuiltIn.Should().BeFalse(); actualDescription.IsEnum.Should().BeFalse(); actualDescription.IsGenericType.Should().BeFalse(); actualDescription.IsInterface.Should().BeFalse(); actualDescription.IsSealed.Should().BeTrue(); actualDescription.IsValueType.Should().BeTrue(); actualDescription.Type.Should().Be <FieldUInt32>("because the type should've been resolved"); actualDescription.Properties.Should().BeEmpty(); actualDescription.Methods.Should().BeEmpty(); actualDescription.Fields.Should().HaveCount(1); var actualField = actualDescription.Fields[0]; actualField.Name.Should().Be(nameof(FieldUInt32.Value)); actualField.FieldType.Should().NotBeNull(); actualField.FieldType.Type.Should().Be <UInt32>(); }
public void TestContains1() { var model = new SharpRemote.TypeModel(); model.Contains <string>().Should().BeFalse(); model.Add <string>(); model.Contains <string>().Should().BeTrue(); }
public void TestRoundtripEmpty() { var expected = new SharpRemote.TypeModel(); var actual = Roundtrip(expected); actual.Should().NotBeNull(); actual.Types.Should().BeEmpty(); }
public void TestAddTwice() { var model = new SharpRemote.TypeModel(); var type1 = model.Add <string>(); var type2 = model.Add <string>(); type2.Should().BeSameAs(type1); model.Types.Count(x => x.AssemblyQualifiedName == typeof(string).AssemblyQualifiedName).Should().Be(1); }
public void TestEnum() { var model = new SharpRemote.TypeModel(); model.Add <uint>(); new Action(() => model.Add <UInt32Enum>()).ShouldNotThrow(); model.Types.Should().Contain(x => x.Type == typeof(uint)); model.Types.Should().Contain(x => x.Type == typeof(UInt32Enum)); }
public void TestAddTwice() { var model = new SharpRemote.TypeModel(); var type1 = model.Add <string>(); var type2 = model.Add <string>(); type2.Should().BeSameAs(type1); model.Types.Should().HaveCount(1); }
public void TestAddType1() { var model = new SharpRemote.TypeModel(); model.Add(typeof(void)); model.Types.Should().HaveCount(1); var type = model.Types.First(); type.AssemblyQualifiedName.Should().Be(typeof(void).AssemblyQualifiedName); }
public void TestAddObject() { var model = new SharpRemote.TypeModel(); var description = model.Add <object>(); description.Should().NotBeNull(); description.AssemblyQualifiedName.Should().Be(typeof(object).AssemblyQualifiedName); model.Types.Should().HaveCount(1); model.Types.Should().Equal(new[] { description }); }
public void TestAddVoid() { var model = new SharpRemote.TypeModel(); var description = model.Add(typeof(void)); description.Should().NotBeNull(); description.AssemblyQualifiedName.Should().Be(typeof(void).AssemblyQualifiedName); ((TypeDescription)description).Id.Should().BeGreaterThan(0); model.GetId(typeof(void)).Should().Be(((TypeDescription)description).Id); model.Types.Should().Contain((TypeDescription)description); }
public void TestFieldIEnumerable() { var model = new SharpRemote.TypeModel(); var description = model.Add <FieldIEnumerable>(); var field = description.Fields[0]; field.Name.Should().Be(nameof(FieldIEnumerable.Values)); field.FieldType.SerializationType.Should().Be(SerializationType.ByValue, "because all enumerations are serialized by value"); field.FieldType.IsEnum.Should().BeFalse(); field.FieldType.IsEnumerable.Should().BeTrue(); }
public void TestHierarchy() { var model = new SharpRemote.TypeModel(); model.Add <BaseClass>(); model.Add <Tree>(); model.Add <Birke>(); model.Types.Should().Contain(x => x.Type == typeof(BaseClass)); model.Types.Should().Contain(x => x.Type == typeof(Tree)); model.Types.Should().Contain(x => x.Type == typeof(Birke)); }
public void TestBuiltInType([ValueSource(nameof(BuiltInTypes))] Type type) { var model = new SharpRemote.TypeModel(); var description = model.Add(type); description.SerializationType.Should().Be(SerializationType.ByValue); description.IsBuiltIn.Should().BeTrue(); description.IsClass.Should().Be(type.IsClass); description.IsSealed.Should().Be(type.IsSealed); description.IsEnum.Should().Be(type.IsEnum); description.IsInterface.Should().Be(type.IsInterface); description.IsValueType.Should().Be(type.IsValueType); }
public void TestIInt32Method() { var model = new SharpRemote.TypeModel(); var type = model.Add <IInt32Method>(assumeByReference: true); type.SerializationType.Should().Be(SerializationType.ByReference); type.Methods.Should().HaveCount(1); var method = type.Methods[0]; method.Name.Should().Be(nameof(IInt32Method.DoStuff)); method.IsAsync.Should().BeFalse(); method.Parameters.Should().BeEmpty(); method.ReturnType.Type.Should().Be <int>(); }
public void TestRecursiveClass() { var model = new SharpRemote.TypeModel(); var type = model.Add <RecursiveClass>(); type.Fields.Should().HaveCount(2); var field = type.Fields[0]; field.Name.Should().Be("Left"); field.FieldType.Should().BeSameAs(type, "because a recursive type model shall reference the very same object"); field = type.Fields[1]; field.Name.Should().Be("Right"); field.FieldType.Should().BeSameAs(type, "because a recursive type model shall reference the very same object"); }
public void TestFieldStruct() { var model = new SharpRemote.TypeModel(); var type = model.Add <FieldStruct>(); type.AssemblyQualifiedName.Should().Be(typeof(FieldStruct).AssemblyQualifiedName); type.SerializationType.Should().Be(SerializationType.ByValue); type.Properties.Should().BeEmpty("because the type doesn't have any properties"); type.Methods.Should().BeEmpty("because the methods of DataContract types are uninteresting"); type.IsClass.Should().BeFalse("because the type is a struct"); type.IsEnum.Should().BeFalse("because the type is a struct"); type.IsValueType.Should().BeTrue("because the type is a struct"); type.IsInterface.Should().BeFalse("because the type is a struct"); type.IsSealed.Should().BeTrue("because structs are always sealed"); type.Fields.Should().HaveCount(3); var field1 = type.Fields[0]; field1.Name.Should().Be(nameof(FieldStruct.A)); field1.FieldType.AssemblyQualifiedName.Should().Be(typeof(double).AssemblyQualifiedName); field1.FieldType.SerializationType.Should().Be(SerializationType.ByValue); field1.FieldType.IsBuiltIn.Should().BeTrue(); ((FieldDescription)field1).FieldTypeId.Should().Be(model.GetId <double>()); var field2 = type.Fields[1]; field2.Name.Should().Be(nameof(FieldStruct.B)); field2.FieldType.AssemblyQualifiedName.Should().Be(typeof(int).AssemblyQualifiedName); field2.FieldType.SerializationType.Should().Be(SerializationType.ByValue); field2.FieldType.IsBuiltIn.Should().BeTrue(); ((FieldDescription)field2).FieldTypeId.Should().Be(model.GetId <int>()); var field3 = type.Fields[2]; field3.Name.Should().Be(nameof(FieldStruct.C)); field3.FieldType.AssemblyQualifiedName.Should().Be(typeof(string).AssemblyQualifiedName); field3.FieldType.SerializationType.Should().Be(SerializationType.ByValue); field3.FieldType.IsBuiltIn.Should().BeTrue(); ((FieldDescription)field3).FieldTypeId.Should().Be(model.GetId <string>()); model.Types.Should().Contain(new object[] { type, //< FieldStruct field1.FieldType, //< double field2.FieldType, //< int field3.FieldType //< string }); }
private IReadOnlyList <ITypeModelDifference> FindDifferences(Type expected, Type actual) { var expectedTypeModel = new SharpRemote.TypeModel(); var expectedType = expectedTypeModel.Add(expected); var actualTypeModel = new SharpRemote.TypeModel(); var actualType = actualTypeModel.Add(actual); var typeResolver = new TestResolver(); typeResolver.Add(expected.AssemblyQualifiedName, actual); actualTypeModel.TryResolveTypes(typeResolver); return(((TypeDescription)expectedType).FindDifferences((TypeDescription)actualType).ToList()); //return expectedTypeModel.FindDifferences(actualTypeModel); }
public void TestByteArray() { var model = new SharpRemote.TypeModel(); var type = model.Add <byte[]>(); type.IsGenericType.Should().BeFalse("because arrays were invented before generics and therefore don't count as being generic"); type.Fields.Should().BeEmpty(); type.Properties.Should().BeEmpty(); type.Methods.Should().BeEmpty(); type.GenericArguments.Should().HaveCount(1); var elementType = type.GenericArguments[0]; elementType.Should().NotBeNull(); elementType.AssemblyQualifiedName.Should().Be(typeof(byte).AssemblyQualifiedName); elementType.Type.Should().Be <byte>(); }
public void TestIReturnsTask() { var model = new SharpRemote.TypeModel(); var type = model.Add <IReturnsTask>(assumeByReference: true); type.Methods.Should().HaveCount(1); var method = type.Methods[0]; method.Name.Should().Be(nameof(IReturnsTask.DoStuff)); method.IsAsync.Should().BeTrue(); var returnType = method.ReturnType; returnType.Type.Should().Be <Task>(); returnType.IsGenericType.Should().BeFalse(); returnType.GenericArguments.Should().BeEmpty(); }
public void TestListString() { var model = new SharpRemote.TypeModel(); var type = model.Add <List <string> >(); type.IsGenericType.Should().BeTrue(); type.Fields.Should().BeEmpty(); type.Properties.Should().BeEmpty(); type.Methods.Should().BeEmpty(); type.GenericArguments.Should().HaveCount(1); var elementType = type.GenericArguments[0]; elementType.Should().NotBeNull(); elementType.AssemblyQualifiedName.Should().Be(typeof(string).AssemblyQualifiedName); elementType.Type.Should().Be <string>(); }
public void TestIVoidMethodInt64Parameter() { var model = new SharpRemote.TypeModel(); var type = model.Add <IVoidMethodInt64Parameter>(assumeByReference: true); type.SerializationType.Should().Be(SerializationType.ByReference); type.Methods.Should().HaveCount(1); var method = type.Methods[0]; method.Name.Should().Be(nameof(IVoidMethodInt64Parameter.Do)); method.ReturnType.Type.Should().Be(typeof(void)); method.Parameters.Should().HaveCount(1); method.Parameters[0].Name.Should().Be("value"); method.Parameters[0].IsIn.Should().BeFalse(); method.Parameters[0].IsOut.Should().BeFalse(); method.Parameters[0].IsRetval.Should().BeFalse(); method.Parameters[0].Position.Should().Be(0); method.Parameters[0].ParameterType.Type.Should().Be <Int64>(); }
public void TestRoundtripPropertyStruct() { var expected = new SharpRemote.TypeModel(); expected.Add <PropertyStruct>(); var actual = Roundtrip(expected); var actualDescription = actual.Get <PropertyStruct>(); actualDescription.AssemblyQualifiedName.Should().Be(typeof(PropertyStruct).AssemblyQualifiedName); actualDescription.Type.Should().Be <PropertyStruct>("because the type should've been resolved"); actualDescription.Fields.Should().BeEmpty(); actualDescription.Methods.Should().BeEmpty(); actualDescription.Properties.Should().HaveCount(1); var actualProperty = actualDescription.Properties[0]; actualProperty.Name.Should().Be(nameof(PropertyStruct.Value)); actualProperty.PropertyType.Should().NotBeNull("because the type of the property should've been reserved"); actualProperty.PropertyType.Type.Should().Be <string>(); }
public void TestFieldEnum() { var model = new SharpRemote.TypeModel(); var type = model.Add <FieldInt32Enum>(); type.Properties.Should().BeEmpty("because the type doesn't have any properties"); type.Methods.Should().BeEmpty("because the methods of DataContract types are uninteresting"); type.IsClass.Should().BeFalse("because the type is a struct"); type.IsEnum.Should().BeFalse("because the type is a struct"); type.IsValueType.Should().BeTrue("because the type is a struct"); type.IsInterface.Should().BeFalse("because the type is a struct"); type.IsSealed.Should().BeTrue("because structs are always sealed"); type.Fields.Should().HaveCount(1); var field1 = type.Fields[0]; field1.Name.Should().Be(nameof(FieldInt32Enum.Value)); field1.FieldType.AssemblyQualifiedName.Should().Be(typeof(Int32Enum).AssemblyQualifiedName); field1.FieldType.SerializationType.Should().Be(SerializationType.ByValue); field1.FieldType.IsEnum.Should().BeTrue(); }
public void TestRoundtripByteArray() { var expected = new SharpRemote.TypeModel(); expected.Add <byte[]>(); var actual = Roundtrip(expected); actual.Should().NotBeNull(); actual.Contains <byte[]>().Should().BeTrue(); actual.Contains <byte>().Should().BeTrue(); actual.Contains <Array>().Should().BeTrue(); var byteArrayDescription = actual.Get <byte[]>(); byteArrayDescription.IsGenericType.Should() .BeFalse("because arrays are special and don't count as generic types"); byteArrayDescription.GenericArguments.Should().HaveCount(1); var byteDescription = byteArrayDescription.GenericArguments[0]; byteDescription.Should().BeSameAs(actual.Get <byte>()); }
public void TestInt32Enum() { var model = new SharpRemote.TypeModel(); var type = model.Add <Int32Enum>(); type.IsEnum.Should().BeTrue(); type.StorageType.Type.Should().Be <Int32>(); type.EnumValues.Should().HaveCount(3); type.EnumValues[0].Value.Should().Be(Int32Enum.B); type.EnumValues[0].Name.Should().Be("B"); type.EnumValues[0].NumericValue.Should().Be((long)Int32Enum.B); type.EnumValues[1].Value.Should().Be(Int32Enum.C); type.EnumValues[1].Name.Should().Be("C"); type.EnumValues[1].NumericValue.Should().Be((long)Int32Enum.C); type.EnumValues[2].Value.Should().Be(Int32Enum.A); type.EnumValues[2].Name.Should().Be("A"); type.EnumValues[2].NumericValue.Should().Be((long)Int32Enum.A); }
public void TestRoundtripFieldObjectStruct() { var expected = new SharpRemote.TypeModel(); expected.Add <FieldObjectStruct>(); var actual = Roundtrip(expected); var actualDescription = actual.Get <FieldObjectStruct>(); actualDescription.AssemblyQualifiedName.Should().Be(typeof(FieldObjectStruct).AssemblyQualifiedName); actualDescription.Type.Should().Be <FieldObjectStruct>("because the type should've been resolved"); actualDescription.Properties.Should().BeEmpty(); actualDescription.Methods.Should().BeEmpty(); actualDescription.Fields.Should().HaveCount(1); var field = actualDescription.Fields[0]; field.Name.Should().Be(nameof(FieldObjectStruct.Value)); field.FieldType.Should().NotBeNull(); field.FieldType.AssemblyQualifiedName.Should().Be(typeof(object).AssemblyQualifiedName); field.FieldType.Type.Should().Be <object>(); }
public void TestUInt64Enum() { var model = new SharpRemote.TypeModel(); var type = model.Add <UInt64Enum>(); type.IsEnum.Should().BeTrue(); type.StorageType.Type.Should().Be <UInt64>(); type.EnumValues.Should().HaveCount(3); type.EnumValues[0].Value.Should().Be(UInt64Enum.A); type.EnumValues[0].Name.Should().Be("A"); type.EnumValues[0].NumericValue.Should().Be(unchecked ((long)UInt64Enum.A)); type.EnumValues[1].Value.Should().Be(UInt64Enum.B); type.EnumValues[1].Name.Should().Be("B"); type.EnumValues[1].NumericValue.Should().Be(unchecked ((long)UInt64Enum.B)); type.EnumValues[2].Value.Should().Be(UInt64Enum.C); type.EnumValues[2].Name.Should().Be("C"); type.EnumValues[2].NumericValue.Should().Be(unchecked ((long)UInt64Enum.C)); }