public void ApplyODataComplexValueForCollectionPropertyShouldError()
        {
            TestMaterializerContext context = new TestMaterializerContext();
            ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection();
            ODataProperty property = new ODataProperty() { Name = "Strings", Value = new ODataComplexValue() };

            Action test = () => this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance);
            test.ShouldThrow<InvalidOperationException>().WithMessage(DSClient.Strings.AtomMaterializer_InvalidCollectionItem(property.Name));
        }
        public void ApplyODataComplexValueForCollectionPropertyShouldError()
        {
            TestMaterializerContext            context         = new TestMaterializerContext();
            ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection();
            ODataProperty property = new ODataProperty()
            {
                Name = "Strings", Value = new ODataComplexValue()
            };

            Action test = () => this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance);

            test.ShouldThrow <InvalidOperationException>().WithMessage(DSClient.Strings.AtomMaterializer_InvalidCollectionItem(property.Name));
        }
Exemplo n.º 3
0
        public void ApplyStringValueForCollectionPropertyShouldError()
        {
            TestMaterializerContext            context         = new TestMaterializerContext();
            ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection();
            ODataProperty property = new ODataProperty()
            {
                Name = "Strings", Value = "foo"
            };

            Action test = () => this.CreateEntryMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance);

            test.ShouldThrow <InvalidOperationException>().WithMessage(DSClient.Strings.Deserialize_MixedTextWithComment);
        }
        public void ApplyODataCollectionValueToNonNullExistingCollectionProperty()
        {
            TestMaterializerContext            context         = new TestMaterializerContext();
            ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection();

            complexInstance.Strings.Add("ShouldBeCleared");
            ODataProperty property = new ODataProperty()
            {
                Name = "Strings", Value = new ODataCollectionValue()
            };

            this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance);
            complexInstance.Strings.Should().HaveCount(0);
        }
        public void ApplyODataCollectionValueToNullCollectionProperty()
        {
            TestMaterializerContext            context         = new TestMaterializerContext();
            ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection();

            complexInstance.Strings = null;
            ODataProperty property = new ODataProperty()
            {
                Name = "Strings", Value = new ODataCollectionValue()
                {
                    Items = new string[] { "foo" }, TypeName = typeof(ComplexTypeWithPrimitiveCollection).FullName
                }
            };

            this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance);
            complexInstance.Strings.Should().HaveCount(1);
            complexInstance.Strings[0].Should().Be("foo");
        }
        public void ApplyODataCollectionValueToNullCollectionProperty()
        {
            TestMaterializerContext context = new TestMaterializerContext();
            ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection();
            complexInstance.Strings = null;
            ODataProperty property = new ODataProperty() { Name = "Strings", Value = new ODataCollectionValue() { Items = new string[] { "foo" }, TypeName = typeof(ComplexTypeWithPrimitiveCollection).FullName } };

            this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance);
            complexInstance.Strings.Should().HaveCount(1);
            complexInstance.Strings[0].Should().Be("foo");
        }
        public void ApplyODataCollectionValueToNonNullExistingCollectionProperty()
        {
            TestMaterializerContext context = new TestMaterializerContext();
            ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection();
            complexInstance.Strings.Add("ShouldBeCleared");
            ODataProperty property = new ODataProperty() { Name = "Strings", Value = new ODataCollectionValue() };

            this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance);
            complexInstance.Strings.Should().HaveCount(0);
        }