Exemplo n.º 1
0
        public void TryTranslatePathTemplateSegmentTemplate_ReturnsDynamicPathSegment()
        {
            // Arrange
            RouteValueDictionary          routeValueDictionary = new RouteValueDictionary(new { dynamicproperty = "Dynamic" });
            ODataTemplateTranslateContext context = new ODataTemplateTranslateContext
            {
                RouteValues = routeValueDictionary
            };

            context.Segments.Add(new MySegment(_entityType));

            PathTemplateSegment         segment     = new PathTemplateSegment("{dynamicproperty}");
            PathTemplateSegmentTemplate pathSegment = new PathTemplateSegmentTemplate(segment);

            // Act
            Assert.True(pathSegment.TryTranslate(context));

            // Assert
            Assert.Equal(2, context.Segments.Count); // 1 - MySegment, 2 - Property Segment
            Assert.Collection(context.Segments,
                              e =>
            {
                Assert.IsType <MySegment>(e);
            },
                              e =>
            {
                DynamicPathSegment dynamicSegment = Assert.IsType <DynamicPathSegment>(e);
                Assert.Equal("Dynamic", dynamicSegment.Identifier);
            });
        }
Exemplo n.º 2
0
        public void TryTranslatePathTemplateSegmentTemplate_ReturnsNavigationPropertySegment()
        {
            // Arrange
            RouteValueDictionary          routeValueDictionary = new RouteValueDictionary(new { property = "RelatedCustomers" });
            ODataTemplateTranslateContext context = new ODataTemplateTranslateContext
            {
                RouteValues = routeValueDictionary
            };

            context.Segments.Add(new MySegment(_entityType));

            PathTemplateSegment         segment     = new PathTemplateSegment("{property}");
            PathTemplateSegmentTemplate pathSegment = new PathTemplateSegmentTemplate(segment);

            // Act
            Assert.True(pathSegment.TryTranslate(context));

            // Assert
            Assert.Equal(2, context.Segments.Count); // 1 - MySegment, 2 - Property Segment
            Assert.Collection(context.Segments,
                              e =>
            {
                Assert.IsType <MySegment>(e);
            },
                              e =>
            {
                NavigationPropertySegment propertySegment = Assert.IsType <NavigationPropertySegment>(e);
                Assert.Equal("RelatedCustomers", propertySegment.NavigationProperty.Name);
            });
        }
Exemplo n.º 3
0
        public void TryTranslatePathTemplateSegmentTemplate_ThrowsArgumentNull_Context()
        {
            // Arrange
            PathTemplateSegment         segment     = new PathTemplateSegment("{any}");
            PathTemplateSegmentTemplate pathSegment = new PathTemplateSegmentTemplate(segment);

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => pathSegment.TryTranslate(null), "context");
        }
Exemplo n.º 4
0
        [InlineData("{dynamicproperty}")] // false because no previous segment in the context
        public void TryTranslatePathTemplateSegmentTemplate_ReturnsFalse_NotSupportedTemplate(string template)
        {
            // Arrange
            PathTemplateSegment           segment     = new PathTemplateSegment(template);
            PathTemplateSegmentTemplate   pathSegment = new PathTemplateSegmentTemplate(segment);
            ODataTemplateTranslateContext context     = new ODataTemplateTranslateContext();

            // Act & Assert
            Assert.False(pathSegment.TryTranslate(context));
        }
Exemplo n.º 5
0
        public void TryTranslatePathTemplateSegmentTemplate_ReturnsFalse_PreviousSegmentNotStructuredType(string template)
        {
            // Arrange
            MySegment previousSegment = new MySegment(EdmCoreModel.Instance.GetString(false).Definition);

            PathTemplateSegment           segment     = new PathTemplateSegment(template);
            PathTemplateSegmentTemplate   pathSegment = new PathTemplateSegmentTemplate(segment);
            ODataTemplateTranslateContext context     = new ODataTemplateTranslateContext();

            context.Segments.Add(previousSegment);

            // Act & Assert
            Assert.False(pathSegment.TryTranslate(context));
        }
Exemplo n.º 6
0
        public void TryTranslatePathTemplateSegmentTemplate_ReturnsFalse_NoCorrectRouteData(string template)
        {
            // Arrange
            PathTemplateSegment           segment     = new PathTemplateSegment(template);
            PathTemplateSegmentTemplate   pathSegment = new PathTemplateSegmentTemplate(segment);
            ODataTemplateTranslateContext context     = new ODataTemplateTranslateContext
            {
                RouteValues = new RouteValueDictionary()
            };

            context.Segments.Add(new MySegment(_entityType));

            // Act & Assert
            Assert.False(pathSegment.TryTranslate(context));
        }
Exemplo n.º 7
0
        public void TryTranslatePathTemplateSegmentTemplate_ReturnsFalse_DynamicPathSegmentWithKnowProperty()
        {
            // Arrange
            RouteValueDictionary          routeValueDictionary = new RouteValueDictionary(new { dynamicproperty = "Name" });
            ODataTemplateTranslateContext context = new ODataTemplateTranslateContext
            {
                RouteValues = routeValueDictionary
            };

            context.Segments.Add(new MySegment(_entityType));

            PathTemplateSegment         segment     = new PathTemplateSegment("{dynamicproperty}");
            PathTemplateSegmentTemplate pathSegment = new PathTemplateSegmentTemplate(segment);

            // Act & Assert
            Assert.False(pathSegment.TryTranslate(context));
        }