コード例 #1
0
        public void ApplyProperty_AppliesKeyProperty_WhenPatchKeyModeIsPatch()
        {
            // Arrange
            ODataProperty property = new ODataProperty {
                Name = "Key1", Value = "Value1"
            };
            EdmEntityType entityType = new EdmEntityType("namespace", "name");

            entityType.AddKeys(new EdmStructuralProperty(entityType, "Key1", EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string))));
            EdmEntityTypeReference    entityTypeReference = new EdmEntityTypeReference(entityType, isNullable: false);
            ODataDeserializerProvider provider            = new DefaultODataDeserializerProvider(EdmCoreModel.Instance);

            var  resource     = new Mock <IDelta>(MockBehavior.Strict);
            Type propertyType = typeof(string);

            resource.Setup(r => r.TryGetPropertyType("Key1", out propertyType)).Returns(true);
            resource.Setup(r => r.TrySetPropertyValue("Key1", "Value1")).Returns(true).Verifiable();

            // Act
            ODataEntryDeserializer.ApplyProperty(property, entityTypeReference, resource.Object, provider, new ODataDeserializerContext {
                IsPatchMode = true, PatchKeyMode = PatchKeyMode.Patch
            });

            // Assert
            resource.Verify();
        }
コード例 #2
0
        public void ApplyProperty_ThrowsOnKeyProperty_WhenPatchKeyModeIsThrow()
        {
            // Arrange
            ODataProperty property = new ODataProperty {
                Name = "Key1", Value = "Value1"
            };
            EdmEntityType entityType = new EdmEntityType("namespace", "name");

            entityType.AddKeys(new EdmStructuralProperty(entityType, "Key1", EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string))));
            EdmEntityTypeReference    entityTypeReference = new EdmEntityTypeReference(entityType, isNullable: false);
            ODataDeserializerProvider provider            = new DefaultODataDeserializerProvider(EdmCoreModel.Instance);

            var resource = new Mock <IDelta>(MockBehavior.Strict);

            // Act && Assert
            Assert.Throws <InvalidOperationException>(
                () => ODataEntryDeserializer.ApplyProperty(property, entityTypeReference, resource.Object, provider, new ODataDeserializerContext {
                IsPatchMode = true, PatchKeyMode = PatchKeyMode.Throw
            }),
                "Cannot apply PATCH on key property 'Key1' on entity type 'namespace.name' when 'PatchKeyMode' is 'Throw'.");
        }