public CsdlSemanticsEntitySetTests() { var referentialConstraints = new List <CsdlReferentialConstraint>(); var csdlNavigation = new CsdlNavigationProperty("Navigation", null, null, null, false, null, referentialConstraints, null, null); this.csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, Enumerable.Empty <CsdlProperty>(), new[] { csdlNavigation }, null, null); var goodBinding = new CsdlNavigationPropertyBinding("Navigation", "EntitySet", null, new CsdlLocation(1, 1)); this.csdlEntitySet = new CsdlEntitySet("EntitySet", "FQ.NS.EntityType", new[] { goodBinding }, null, null); this.csdlContainer = new CsdlEntityContainer("Container", null, new[] { this.csdlEntitySet }, Enumerable.Empty <CsdlSingleton>(), Enumerable.Empty <CsdlOperationImport>(), null, null); var derivedCsdlNavigation = new CsdlNavigationProperty("DerivedNavigation", null, null, null, false, null, referentialConstraints, null, null); var derivedCsdlEntityType = new CsdlEntityType("DerivedEntityType", "FQ.NS.EntityType", false, false, false, null, Enumerable.Empty <CsdlProperty>(), new[] { derivedCsdlNavigation }, null, null); var unrelatedCsdlEntityType = new CsdlEntityType("UnrelatedEntityType", null, false, false, false, null, Enumerable.Empty <CsdlProperty>(), Enumerable.Empty <CsdlNavigationProperty>(), null, null); var csdlSchema = new CsdlSchema("FQ.NS", null, null, new[] { this.csdlEntityType, derivedCsdlEntityType, unrelatedCsdlEntityType }, Enumerable.Empty <CsdlEnumType>(), Enumerable.Empty <CsdlOperation>(), Enumerable.Empty <CsdlTerm>(), Enumerable.Empty <CsdlEntityContainer>(), Enumerable.Empty <CsdlAnnotations>(), Enumerable.Empty <CsdlTypeDefinition>(), null, null); var csdlModel = new CsdlModel(); csdlModel.AddSchema(csdlSchema); var semanticModel = new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty <IEdmModel>()); this.semanticSchema = new CsdlSemanticsSchema(semanticModel, csdlSchema); this.semanticContainer = new CsdlSemanticsEntityContainer(this.semanticSchema, this.csdlContainer); this.semanticEntityType = semanticModel.FindType("FQ.NS.EntityType") as CsdlSemanticsEntityTypeDefinition; this.semanticEntityType.Should().NotBeNull(); this.navigationProperty = this.semanticEntityType.FindProperty("Navigation") as CsdlSemanticsNavigationProperty; this.navigationProperty.Should().NotBeNull(); }
private IEdmNavigationProperty ResolveNavigationPropertyPathForBinding(CsdlNavigationPropertyBinding binding) { Debug.Assert(binding != null, "binding != null"); string bindingPath = binding.Path; Debug.Assert(bindingPath != null, "bindingPath != null"); IEdmEntityType definingType = this.typeCache.GetValue(this, ComputeElementTypeFunc, null); const char Slash = '/'; if (bindingPath.Length == 0 || bindingPath[bindingPath.Length - 1] == Slash) { // if the path did not actually contain a navigation property, then treat it as an unresolved path. // TODO: improve the error given in this case? return(new UnresolvedNavigationPropertyPath(definingType, bindingPath, binding.Location)); } IEdmNavigationProperty navigationProperty; string[] pathSegements = bindingPath.Split(Slash); for (int index = 0; index < pathSegements.Length - 1; index++) { string pathSegement = pathSegements[index]; if (pathSegement.Length == 0) { // TODO: improve the error given in this case? return(new UnresolvedNavigationPropertyPath(definingType, bindingPath, binding.Location)); } IEdmEntityType derivedType = this.container.Context.FindType(pathSegement) as IEdmEntityType; if (derivedType == null) { IEdmProperty property = definingType.FindProperty(pathSegement); navigationProperty = property as IEdmNavigationProperty; if (navigationProperty == null) { return(new UnresolvedNavigationPropertyPath(definingType, bindingPath, binding.Location)); } definingType = navigationProperty.ToEntityType(); } else { definingType = derivedType; } } navigationProperty = definingType.FindProperty(pathSegements.Last()) as IEdmNavigationProperty; if (navigationProperty == null) { // TODO: improve the error given in this case? navigationProperty = new UnresolvedNavigationPropertyPath(definingType, bindingPath, binding.Location); } return(navigationProperty); }
private IEdmNavigationPropertyBinding ParseSingleBinding(string path, string target, CsdlLocation location = null) { var binding = new CsdlNavigationPropertyBinding(path, target, location); var testSubject = new CsdlSemanticsEntitySet(this.semanticContainer, new CsdlEntitySet("Fake", "FQ.NS.EntityType", new[] { binding }, null)); var result = Assert.Single(testSubject.NavigationPropertyBindings); return(result); }
public void FindNavigationTargetShouldReturnUnresolvedEntitySetIfEntitySetIsNotFound() { var nonExistentBinding = new CsdlNavigationPropertyBinding("Navigation", "NonExistent", null, new CsdlLocation(1, 1)); var testSubject = new CsdlSemanticsEntitySet(this.semanticContainer, new CsdlEntitySet("Fake", "FQ.NS.EntityType", new[] { nonExistentBinding }, null, null)); var result = testSubject.FindNavigationTarget(this.navigationProperty); result.Should().BeAssignableTo <UnresolvedEntitySet>(); result.As <UnresolvedEntitySet>().Name.Should().Be("NonExistent"); result.Errors().Should().Contain(e => e.ErrorLocation == nonExistentBinding.Location && e.ErrorCode == EdmErrorCode.BadUnresolvedEntitySet); }
public void FindNavigationTargetShouldReturnUnresolvedEntitySetIfEntitySetIsNotFound() { var nonExistentBinding = new CsdlNavigationPropertyBinding("Navigation", "NonExistent", new CsdlLocation(1, 1)); var testSubject = new CsdlSemanticsEntitySet(this.semanticContainer, new CsdlEntitySet("Fake", "FQ.NS.EntityType", new[] { nonExistentBinding }, null)); var result = testSubject.FindNavigationTarget(this.navigationProperty); var entitySet = Assert.IsType <UnresolvedEntitySet>(result); Assert.Equal("NonExistent", entitySet.Name); Assert.Contains(result.Errors(), e => e.ErrorLocation == nonExistentBinding.Location && e.ErrorCode == EdmErrorCode.BadUnresolvedEntitySet); }
private IEdmNavigationProperty ResolveNavigationPropertyPathForBinding(CsdlNavigationPropertyBinding binding) { Debug.Assert(binding != null); Debug.Assert(binding.Path != null); var pathSegments = binding.Path.Split('/'); IEdmStructuredType definingType = this.typeCache.GetValue(this, ComputeElementTypeFunc, null); for (int index = 0; index < pathSegments.Length - 1; index++) { string segment = pathSegments[index]; if (segment.IndexOf('.') < 0) { var property = definingType.FindProperty(segment); if (property == null) { return(new UnresolvedNavigationPropertyPath(definingType, binding.Path, binding.Location)); } var navProperty = property as IEdmNavigationProperty; if (navProperty != null && !navProperty.ContainsTarget) { // TODO: Improve error message #644. return(new UnresolvedNavigationPropertyPath(definingType, binding.Path, binding.Location)); } definingType = property.Type.Definition.AsElementType() as IEdmStructuredType; if (definingType == null) { // TODO: Improve error message #644. return(new UnresolvedNavigationPropertyPath(definingType, binding.Path, binding.Location)); } } else { var derivedType = container.Context.FindType(segment) as IEdmStructuredType; if (derivedType == null || !derivedType.IsOrInheritsFrom(definingType)) { // TODO: Improve error message #644. return(new UnresolvedNavigationPropertyPath(definingType, binding.Path, binding.Location)); } definingType = derivedType; } } return(definingType.FindProperty(pathSegments.Last()) as IEdmNavigationProperty ?? new UnresolvedNavigationPropertyPath(definingType, binding.Path, binding.Location)); }
private IEdmNavigationPropertyBinding CreateSemanticMappingForBinding(CsdlNavigationPropertyBinding binding) { IEdmNavigationProperty navigationProperty = this.ResolveNavigationPropertyPathForBinding(binding); IEdmNavigationSource targetNavigationSource = this.Container.FindEntitySetExtended(binding.Target); if (targetNavigationSource == null) { targetNavigationSource = this.Container.FindSingletonExtended(binding.Target); if (targetNavigationSource == null) { targetNavigationSource = new UnresolvedEntitySet(binding.Target, this.Container, binding.Location); } } return(new EdmNavigationPropertyBinding(navigationProperty, targetNavigationSource, new EdmPathExpression(binding.Path))); }