コード例 #1
0
        public void Test()
        {
            RegisterStrictMock <ITypeRetriever>()
            .Expect(e => e.GetPublicTypesOfLoadedAssemblies())
            .Return(new[] { typeof(T) });

            CompositeObjectTestData.SetupMockAttributeValueSerializerProvider(RegisterStrictMock <IAttributeValueSerializerProvider>());

            Mocks.ReplayAll();

            var provider = Resolve <BusinessObjectDefinitionProvider>();

            var compositeObjectTypeId = CompositeObjectTestData.ClassBinding[typeof(T)];
            var definition            = provider.GetCompositeObjectDefinition(compositeObjectTypeId);

            Assert.AreEqual(compositeObjectTypeId, definition.CompositeObjectTypeId);
            var attributes = definition.Attributes;

            Assert.AreEqual(CompositeObjectTestData.TestAttributes.Count, attributes.Count);
            foreach (var testAttribute in CompositeObjectTestData.TestAttributes)
            {
                var attribute = attributes[testAttribute.Value.Name];
                Assert.AreEqual(testAttribute.Value.Name, attribute.Name);
                Assert.AreEqual(testAttribute.Key, attribute.AttributeType);
                Assert.IsInstanceOf(testAttribute.Value.SerializerType, attribute.Serializer);
            }

            Mocks.VerifyAll();
        }
コード例 #2
0
        public void Static_NotNull()
        {
            CompositeObjectTestData.SetupMockAttributeValueSerializerProvider(RegisterStrictMock <IAttributeValueSerializerProvider>());

            Mocks.ReplayAll();

            var factory = Resolve <Protobuf.AttributeValues.AttributeValueFactory>();

            var attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.Int32Property, CompositeObjectTestData.TestValues.Int32Value);

            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(Int32)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.Int32Value), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.NullableInt32Property,
                                            CompositeObjectTestData.TestValues.NullableInt32Value);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(Int32?)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.NullableInt32Value), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.Int64Property, CompositeObjectTestData.TestValues.Int64Value);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(Int64)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.Int64Value), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.NullableInt64Property,
                                            CompositeObjectTestData.TestValues.NullableInt64Value);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(Int64?)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.NullableInt64Value), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.DoubleProperty, CompositeObjectTestData.TestValues.DoubleValue);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(Double)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.DoubleValue), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.NullableDoubleProperty,
                                            CompositeObjectTestData.TestValues.NullableDoubleValue);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(Double?)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.NullableDoubleValue), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.GuidProperty, CompositeObjectTestData.TestValues.GuidValue);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(Guid)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.GuidValue), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.NullableGuidProperty, CompositeObjectTestData.TestValues.NullableGuidValue);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(Guid?)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.NullableGuidValue), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.DateTimeOffsetProperty,
                                            CompositeObjectTestData.TestValues.DateTimeOffsetValue);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(DateTimeOffset)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.DateTimeOffsetValue), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.NullableDateTimeOffsetProperty,
                                            CompositeObjectTestData.TestValues.NullableDateTimeOffsetValue);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(DateTimeOffset?)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.NullableDateTimeOffsetValue), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.StringProperty, CompositeObjectTestData.TestValues.StringValue);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(String)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.StringValue), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.EnumProperty, CompositeObjectTestData.TestValues.EnumValue);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(TestEnum)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.EnumValue), attributeValue.Value);

            attributeValue = factory.Create(() => TestCompositeBusinessObjectStatic.NullableEnumProperty, CompositeObjectTestData.TestValues.NullableEnumValue);
            Assert.AreEqual(CompositeObjectTestData.TestAttributes[typeof(TestEnum?)].Name, attributeValue.Name);
            Assert.AreEqual(testSerializer.Serialize(CompositeObjectTestData.TestValues.NullableEnumValue), attributeValue.Value);

            Mocks.VerifyAll();
        }