Exemple #1
0
        public void BuildKeyMappingsKeySegmentTemplate_ReturnsKeyMapping_UriTemplateExpression()
        {
            // Arrange
            EdmEntityType         customerType = new EdmEntityType("NS", "Customer");
            EdmStructuralProperty idProperty   = customerType.AddStructuralProperty("customerId", EdmPrimitiveTypeKind.Int32);

            customerType.AddKeys(idProperty);

            UriTemplateExpression tempateExpression = BuildExpression("{yourId}", idProperty.Type);

            IDictionary <string, object> keys = new Dictionary <string, object>
            {
                { "customerId", tempateExpression }
            };

            // Act
            IDictionary <string, string> mapped = KeySegmentTemplate.BuildKeyMappings(keys, customerType);

            // Assert
            Assert.NotNull(mapped);
            KeyValuePair <string, string> actual = Assert.Single(mapped);

            Assert.Equal("customerId", actual.Key);
            Assert.Equal("yourId", actual.Value);
        }
Exemple #2
0
        public void BuildKeyMappingsKeySegmentTemplate_ThrowsODataException_EmptyTemplateLiteral()
        {
            // Arrange
            IDictionary <string, object> keys = new Dictionary <string, object>
            {
                { "customerId", "{}" }
            };

            // Act
            Action test = () => KeySegmentTemplate.BuildKeyMappings(keys, _customerType);

            // Assert
            ExceptionAssert.Throws <ODataException>(test, "Key template value '{}' for key segment 'customerId' is empty.");
        }
Exemple #3
0
        public void BuildKeyMappingsKeySegmentTemplate_ThrowsODataException_NullTemplateLiteral()
        {
            // Arrange
            IDictionary <string, object> keys = new Dictionary <string, object>
            {
                { "customerId", null }
            };

            // Act
            Action test = () => KeySegmentTemplate.BuildKeyMappings(keys, _customerType);

            // Assert
            ExceptionAssert.Throws <ODataException>(test, "Key template value '' for key segment 'customerId' does not start with '{' or ends with '}'.");
        }
Exemple #4
0
        public void BuildKeyMappingsKeySegmentTemplate_ThrowsODataException_NoProperty()
        {
            // Arrange
            IDictionary <string, object> keys = new Dictionary <string, object>
            {
                { "customerId", "{key}" }
            };

            IEdmStructuralProperty             nameProperty = _customerType.StructuralProperties().First(c => c.Name == "Name");
            IDictionary <string, IEdmProperty> properties   = new Dictionary <string, IEdmProperty>
            {
                { "name", nameProperty }
            };

            // Act
            Action test = () => KeySegmentTemplate.BuildKeyMappings(keys, _customerType, properties);

            // Assert
            ExceptionAssert.Throws <ODataException>(test, "Cannot find key 'customerId' in the 'NS.Customer' type.");
        }
        public void BuildKeyMappings_ReturnsKeyMapping_UriTemplateExpression()
        {
            // Arrange
            EdmEntityType         customerType = new EdmEntityType("NS", "Customer");
            EdmStructuralProperty idProperty   = customerType.AddStructuralProperty("customerId", EdmPrimitiveTypeKind.Int32);

            customerType.AddKeys(idProperty);

            // The properties of UriTemplateExpression are internal set.
            // We use the reflect to set the value.
            PropertyInfo literalText = typeof(UriTemplateExpression).GetProperty("LiteralText");

            Assert.NotNull(literalText);

            PropertyInfo expectedType = typeof(UriTemplateExpression).GetProperty("ExpectedType");

            Assert.NotNull(expectedType);

            UriTemplateExpression tempateExpression = new UriTemplateExpression();

            literalText.SetValue(tempateExpression, "{yourId}");
            expectedType.SetValue(tempateExpression, idProperty.Type);

            IDictionary <string, object> keys = new Dictionary <string, object>
            {
                { "customerId", tempateExpression }
            };

            // Arrange
            IDictionary <string, string> mapped = KeySegmentTemplate.BuildKeyMappings(keys, customerType);

            // Assert
            Assert.NotNull(mapped);
            KeyValuePair <string, string> actual = Assert.Single(mapped);

            Assert.Equal("customerId", actual.Key);
            Assert.Equal("yourId", actual.Value);
        }