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); }); }
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); }); }
public void TryTranslatePathTemplateSegmentTemplate_ThrowsArgumentNull_Context() { // Arrange PathTemplateSegment segment = new PathTemplateSegment("{any}"); PathTemplateSegmentTemplate pathSegment = new PathTemplateSegmentTemplate(segment); // Act & Assert ExceptionAssert.ThrowsArgumentNull(() => pathSegment.TryTranslate(null), "context"); }
[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)); }
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)); }
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)); }
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)); }