public void TryTranslateSingletonSegmentTemplate_ThrowsArgumentNull_Context() { // Arrange EdmEntityType entityType = new EdmEntityType("NS", "entity"); IEdmEntityContainer container = new EdmEntityContainer("NS", "default"); IEdmSingleton singleton = new EdmSingleton(container, "singleton", entityType); SingletonSegmentTemplate singletonSegment = new SingletonSegmentTemplate(singleton); // Act & Assert ExceptionAssert.ThrowsArgumentNull(() => singletonSegment.TryTranslate(null), "context"); }
public void CtorSingletonSegmentTemplate_SetsProperties() { // Arrange & Act EdmEntityType entityType = new EdmEntityType("NS", "entity"); IEdmEntityContainer container = new EdmEntityContainer("NS", "default"); IEdmSingleton singleton = new EdmSingleton(container, "singleton", entityType); SingletonSegmentTemplate singletonSegment = new SingletonSegmentTemplate(singleton); // Assert Assert.NotNull(singletonSegment.Segment); Assert.Same(singleton, singletonSegment.Singleton); }
public void GetTemplatesSingletonSegmentTemplate_ReturnsTemplates() { // Assert EdmEntityType entityType = new EdmEntityType("NS", "entity"); IEdmEntityContainer container = new EdmEntityContainer("NS", "default"); IEdmSingleton singleton = new EdmSingleton(container, "singleton", entityType); SingletonSegmentTemplate singletonSegment = new SingletonSegmentTemplate(singleton); // Act & Assert IEnumerable <string> templates = singletonSegment.GetTemplates(); string template = Assert.Single(templates); Assert.Equal("/singleton", template); }
public void ParseODataUriTemplate_ForSingleton() { // Arrange IODataPathTemplateParser parser = new DefaultODataPathTemplateParser(); // Act ODataPathTemplate path = parser.Parse(_edmModel, "VipCustomer", null); // Assert Assert.NotNull(path); ODataSegmentTemplate pathSegment = Assert.Single(path); SingletonSegmentTemplate singletonSegment = Assert.IsType <SingletonSegmentTemplate>(pathSegment); Assert.Equal("VipCustomer", singletonSegment.Singleton.Name); }
public void CommonSingletonSegmentTemplateProperties_ReturnsAsExpected() { // Assert EdmEntityType entityType = new EdmEntityType("NS", "entity"); IEdmEntityContainer container = new EdmEntityContainer("NS", "default"); IEdmSingleton singleton = new EdmSingleton(container, "singleton", entityType); SingletonSegmentTemplate singletonSegment = new SingletonSegmentTemplate(singleton); // Act & Assert Assert.Equal("singleton", singletonSegment.Literal); Assert.Equal(ODataSegmentKind.Singleton, singletonSegment.Kind); Assert.True(singletonSegment.IsSingle); Assert.Same(entityType, singletonSegment.EdmType); Assert.Same(singleton, singletonSegment.NavigationSource); }
public void TryMatch_ReturnsFalse() { // Arrange EdmEntityType entityType = new EdmEntityType("NS", "entity"); IEdmEntityContainer container = new EdmEntityContainer("NS", "default"); IEdmSingleton singleton1 = new EdmSingleton(container, "singleton1", entityType); IEdmSingleton singleton2 = new EdmSingleton(container, "singleton2", entityType); SingletonSegmentTemplate template = new SingletonSegmentTemplate(new SingletonSegment(singleton1)); SingletonSegment segment = new SingletonSegment(singleton2); // Act Dictionary <string, object> values = new Dictionary <string, object>(); bool result = template.TryMatch(segment, values); // Assert Assert.False(result); }
public void TryTranslateSingletonSegmentTemplate_ReturnsSingletonSegment() { // Arrange EdmEntityType entityType = new EdmEntityType("NS", "entity"); IEdmEntityContainer container = new EdmEntityContainer("NS", "default"); IEdmSingleton singleton = new EdmSingleton(container, "singleton", entityType); ODataTemplateTranslateContext context = new ODataTemplateTranslateContext(); SingletonSegmentTemplate template = new SingletonSegmentTemplate(new SingletonSegment(singleton)); // Act Assert.True(template.TryTranslate(context)); // Assert ODataPathSegment segment = Assert.Single(context.Segments); SingletonSegment singletonTemplate = Assert.IsType <SingletonSegment>(segment); Assert.Same(singleton, singletonTemplate.Singleton); }
public void TranslateValueTemplateReturnsAsExpected() { // Arrange EdmEntityType entityType = new EdmEntityType("NS", "entity"); IEdmEntityContainer container = new EdmEntityContainer("NS", "default"); IEdmSingleton singleton = new EdmSingleton(container, "singleton", entityType); ODataTemplateTranslateContext context = new ODataTemplateTranslateContext(); SingletonSegmentTemplate template = new SingletonSegmentTemplate(new SingletonSegment(singleton)); // Act ODataPathSegment segment = template.Translate(context); // Assert Assert.NotNull(segment); SingletonSegment singletonTemplate = Assert.IsType <SingletonSegment>(segment); Assert.Same(singleton, singletonTemplate.Singleton); }
public static ODataPath Translate(this ODataPathTemplate pathTemplate) { if (pathTemplate.Count == 0) { // It's service root, so far, let's skip it. return(null); } IList <ODataSegment> newSegments = new List <ODataSegment>(); foreach (var segment in pathTemplate) { switch (segment.Kind) { case ODataSegmentKind.Metadata: newSegments.Add(new ODataMetadataSegment()); break; case ODataSegmentKind.EntitySet: EntitySetSegmentTemplate entitySet = (EntitySetSegmentTemplate)segment; newSegments.Add(entitySet.ConvertTo()); break; case ODataSegmentKind.Singleton: SingletonSegmentTemplate singleton = (SingletonSegmentTemplate)segment; newSegments.Add(singleton.ConvertTo()); break; case ODataSegmentKind.Key: KeySegmentTemplate key = (KeySegmentTemplate)segment; newSegments.Add(key.ConvertTo()); break; case ODataSegmentKind.Cast: CastSegmentTemplate cast = (CastSegmentTemplate)segment; newSegments.Add(cast.ConvertTo()); break; case ODataSegmentKind.Property: // TODO: return(null); //PropertySegmentTemplate property = (PropertySegmentTemplate)segment; //newSegments.Add(property.ConvertTo()); //break; case ODataSegmentKind.Navigation: NavigationSegmentTemplate navigation = (NavigationSegmentTemplate)segment; newSegments.Add(navigation.ConvertTo()); break; case ODataSegmentKind.Function: FunctionSegmentTemplate function = (FunctionSegmentTemplate)segment; newSegments.Add(function.ConvertTo()); break; case ODataSegmentKind.Action: ActionSegmentTemplate action = (ActionSegmentTemplate)segment; newSegments.Add(action.ConvertTo()); break; case ODataSegmentKind.FunctionImport: FunctionImportSegmentTemplate functionImport = (FunctionImportSegmentTemplate)segment; newSegments.Add(functionImport.ConvertTo()); break; case ODataSegmentKind.ActionImport: ActionImportSegmentTemplate actionImport = (ActionImportSegmentTemplate)segment; newSegments.Add(actionImport.ConvertTo()); break; case ODataSegmentKind.Value: return(null); //ValueSegmentTemplate value = (ValueSegmentTemplate)segment; //newSegments.Add(value.ConvertTo()); //break; case ODataSegmentKind.Ref: return(null); //KeySegmentTemplate key = (KeySegmentTemplate)segment; //newSegments.Add(key.ConvertTo()); //break; case ODataSegmentKind.NavigationLink: return(null); //NavigationLinkSegmentTemplate navigationLink = (NavigationLinkSegmentTemplate)segment; //newSegments.Add(navigationLink.ConvertTo()); //break; case ODataSegmentKind.Count: CountSegmentTemplate count = (CountSegmentTemplate)segment; newSegments.Add(count.ConvertTo()); break; case ODataSegmentKind.PathTemplate: return(null); //KeySegmentTemplate key = (KeySegmentTemplate)segment; //newSegments.Add(key.ConvertTo()); //break; case ODataSegmentKind.Dynamic: return(null); //KeySegmentTemplate key = (KeySegmentTemplate)segment; //newSegments.Add(key.ConvertTo()); //break; default: throw new NotSupportedException(); } } return(new ODataPath(newSegments)); }
public static ODataNavigationSourceSegment ConvertTo(this SingletonSegmentTemplate singleton) { return(new ODataNavigationSourceSegment(singleton.Singleton)); }