Example #1
0
        public void GetEntityKeyValue_ThrowsForNullKeys()
        {
            // Arrange
            var           entityInstance = new { Key = (string)null };
            EdmEntityType entityType     = new EdmEntityType("NS", "Name");

            entityType.AddKeys(entityType.AddStructuralProperty("Key", EdmPrimitiveTypeKind.String));

            ResourceContext entityContext = new ResourceContext(_writeContext, entityType.AsReference(), entityInstance);

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(
                () => ConventionsHelpers.GetEntityKeyValue(entityContext),
                "Key property 'Key' of type 'NS.Name' is null. Key properties cannot have null values.");
        }
Example #2
0
        public void GetEntityKeyValue_SingleKey_DifferentDataTypes(object value, object expectedValue)
        {
            // Arrange
            EdmEntityType entityType = new EdmEntityType("NS", "Name");

            entityType.AddKeys(entityType.AddStructuralProperty("Property", EdmPrimitiveTypeKind.String));
            var entityInstance = new { Property = value };

            ResourceContext entityContext = new ResourceContext(_writeContext, entityType.AsReference(), entityInstance);

            // Act
            var keyValue = ConventionsHelpers.GetEntityKeyValue(entityContext);

            // Assert
            Assert.Equal(expectedValue, keyValue);
        }
Example #3
0
        public void GetEntityKeyValue_DerivedType()
        {
            // Arrange
            var           entityInstance = new { Key = "key" };
            EdmEntityType baseEntityType = new EdmEntityType("NS", "Name");

            baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key", EdmPrimitiveTypeKind.String));
            EdmEntityType derivedEntityType = new EdmEntityType("NS", "Derived", baseEntityType);

            ResourceContext entityContext = new ResourceContext(_writeContext, derivedEntityType.AsReference(), entityInstance);

            // Act
            var keyValue = ConventionsHelpers.GetEntityKeyValue(entityContext);

            // Assert
            Assert.Equal("'key'", keyValue);
        }
Example #4
0
        public void GetEntityKeyValue_MultipleKeys_ForDateAndTimeOfDay()
        {
            // Arrange
            var           entityInstance = new { Key1 = new Date(2015, 12, 2), Key2 = new TimeOfDay(4, 3, 2, 1) };
            EdmEntityType entityType     = new EdmEntityType("NS", "Name");

            entityType.AddKeys(entityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.Date));
            entityType.AddKeys(entityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.TimeOfDay));

            ResourceContext entityContext = new ResourceContext(_writeContext,
                                                                entityType.AsReference(), entityInstance);

            // Act
            var keyValue = ConventionsHelpers.GetEntityKeyValue(entityContext);

            // Assert
            Assert.Equal("Key1=2015-12-02,Key2=04:03:02.0010000", keyValue);
        }
Example #5
0
        public void GetEntityKeyValue_MultipleKeys()
        {
            // Arrange
            var           entityInstance = new { Key1 = "key1", Key2 = 2, Key3 = true };
            EdmEntityType entityType     = new EdmEntityType("NS", "Name");

            entityType.AddKeys(entityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.String));
            entityType.AddKeys(entityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.Int32));
            entityType.AddKeys(entityType.AddStructuralProperty("Key3", EdmPrimitiveTypeKind.Boolean));

            ResourceContext entityContext = new ResourceContext(_writeContext, entityType.AsReference(), entityInstance);

            // Act
            var keyValue = ConventionsHelpers.GetEntityKeyValue(entityContext);

            // Assert
            Assert.Equal("Key1='key1',Key2=2,Key3=true", keyValue);
        }
Example #6
0
        public void GetEntityKeyValue_MultipleKeys_DerivedType_ForDateAndTimeOfDay()
        {
            // Arrange
            var           entityInstance = new { Key1 = new Date(2015, 2, 26), Key2 = new TimeOfDay(1, 2, 3, 4) };
            EdmEntityType baseEntityType = new EdmEntityType("NS", "Name");

            baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.Date));
            baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.TimeOfDay));
            EdmEntityType derivedEntityType = new EdmEntityType("NS", "Derived", baseEntityType);

            ResourceContext entityContext = new ResourceContext(_writeContext,
                                                                derivedEntityType.AsReference(), entityInstance);

            // Act
            var keyValue = ConventionsHelpers.GetEntityKeyValue(entityContext);

            // Assert
            Assert.Equal("Key1=2015-02-26,Key2=01:02:03.0040000", keyValue);
        }
        public void GetEntityKeyValue_ThrowsForNullKeys_WithMultipleKeys()
        {
            // Arrange
            var           entityInstance = new { Key1 = "abc", Key2 = "def", Key3 = (string)null };
            EdmEntityType entityType     = new EdmEntityType("NS", "Name");

            entityType.AddKeys(entityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.String));
            entityType.AddKeys(entityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.Int32));
            entityType.AddKeys(entityType.AddStructuralProperty("Key3", EdmPrimitiveTypeKind.Boolean));

            EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, entityType.AsReference(), entityInstance);

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => ConventionsHelpers.GetEntityKeyValue(entityInstanceContext),
                "Key property 'Key3' of type 'NS.Name' is null. Key properties cannot have null values.");
        }
        public void GetEntityKeyValue_SingleKey()
        {
            // Arrange
            EdmEntityType entityType = new EdmEntityType("NS", "Name");

            entityType.AddKeys(entityType.AddStructuralProperty("Property", EdmPrimitiveTypeKind.String));
            var entityInstance = new { Property = "key" };

            EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, entityType.AsReference(), entityInstance);

            // Act
            var keyValue = ConventionsHelpers.GetEntityKeyValue(entityInstanceContext);

            // Assert
            Assert.Equal("'key'", keyValue);
        }