public void TryTranslateFunctionImportSegmentTemplate_ReturnsFalse_WithMisMatchParameter()
        {
            // Arrange
            EdmModel model = new EdmModel();

            model.AddElement(_function);
            model.AddElement(_container);

            IDictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "name", "{nameTemp}" },
                { "title", "{titleTemp}" },
            };
            FunctionImportSegmentTemplate template = new FunctionImportSegmentTemplate(parameters, _functionImport, null);

            RouteValueDictionary          routeValues = new RouteValueDictionary(new { name = "'pt'" });
            ODataTemplateTranslateContext context     = new ODataTemplateTranslateContext
            {
                RouteValues = routeValues,
                Model       = model
            };

            // Act
            bool ok = template.TryTranslate(context);

            // Assert
            Assert.False(ok);
            Assert.Empty(context.Segments);
        }
Exemple #2
0
        public void TryTranslateFunctionImportSegmentTemplate_ReturnsNull_WithOptionalParameterMisMatch()
        {
            // Arrange
            _function.AddOptionalParameter("min", IntPrimitive);
            _function.AddOptionalParameter("max", IntPrimitive);
            EdmModel model = new EdmModel();

            model.AddElement(_function);
            model.AddElement(_container);

            IDictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "name", "{nameTemp}" },
                { "title", "{titleTemp}" },
                { "min", "{minTemp}" },
            };
            FunctionImportSegmentTemplate template = new FunctionImportSegmentTemplate(parameters, _functionImport, null);

            RouteValueDictionary          routeValues = new RouteValueDictionary(new { name = "'pt'", title = "'abc'", min = "42,max=5" });
            HttpContext                   httpContext = new DefaultHttpContext();
            ODataTemplateTranslateContext context     = new ODataTemplateTranslateContext(httpContext, routeValues, model);

            // Act
            bool ok = template.TryTranslate(context);

            // Assert
            Assert.False(ok);
            Assert.Empty(context.Segments);
        }
        public void TryTranslateActionImportSegmentTemplate_ThrowsArgumentNull_Context()
        {
            // Arrange
            FunctionImportSegmentTemplate functionImportSegment = new FunctionImportSegmentTemplate(_functionImport, null);

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => functionImportSegment.TryTranslate(null), "context");
        }
        public void TryTranslateFunctionImportSegmentTemplate_ReturnsODataFunctionImportSegment_WithOptionalParameter()
        {
            // Arrange
            _function.AddOptionalParameter("min", IntPrimitive);
            _function.AddOptionalParameter("max", IntPrimitive);
            EdmModel model = new EdmModel();

            model.AddElement(_function);
            model.AddElement(_container);

            IDictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "name", "{nameTemp}" },
                { "title", "{titleTemp}" },
                { "min", "{minTemp}" },
            };
            FunctionImportSegmentTemplate template = new FunctionImportSegmentTemplate(parameters, _functionImport, null);

            RouteValueDictionary          routeValues = new RouteValueDictionary(new { nameTemp = "'pt'", titleTemp = "'abc'", minTemp = "42" });
            ODataTemplateTranslateContext context     = new ODataTemplateTranslateContext
            {
                RouteValues = routeValues,
                Model       = model
            };

            // Act
            bool ok = template.TryTranslate(context);

            // Assert
            Assert.True(ok);
            ODataPathSegment       actual = Assert.Single(context.Segments);
            OperationImportSegment functionImportSegment = Assert.IsType <OperationImportSegment>(actual);

            Assert.Same(_function, functionImportSegment.OperationImports.First().Operation);
            Assert.Equal(3, functionImportSegment.Parameters.Count());
            Assert.Equal(new[] { "name", "title", "min" }, functionImportSegment.Parameters.Select(p => p.Name));

            Assert.Equal("pt", context.UpdatedValues["nameTemp"]);
            Assert.Equal("abc", context.UpdatedValues["titleTemp"]);
            Assert.Equal(42, context.UpdatedValues["minTemp"]);
        }
        public void TryTranslateFunctionImportSegmentTemplate_ReturnsODataFunctionImportSegment()
        {
            // Arrange
            EdmFunction        function       = new EdmFunction("NS", "MyFunctionImport", IntPrimitive, false, null, false);
            EdmEntityContainer container      = new EdmEntityContainer("NS", "Default");
            EdmFunctionImport  functionImport = new EdmFunctionImport(container, "MyFunctionImport", function);

            FunctionImportSegmentTemplate template = new FunctionImportSegmentTemplate(functionImport, null);
            ODataTemplateTranslateContext context  = new ODataTemplateTranslateContext
            {
                RouteValues = new RouteValueDictionary()
            };

            // Act
            bool ok = template.TryTranslate(context);

            // Assert
            Assert.True(ok);
            ODataPathSegment       actual = Assert.Single(context.Segments);
            OperationImportSegment functionImportSegment = Assert.IsType <OperationImportSegment>(actual);

            Assert.Same(function, functionImportSegment.OperationImports.First().Operation);
        }