public override async Task <PageNavigationResult> OnPageLeavingAsync(WizardLeavingArgs args)
        {
            UserSettings.AddToTopOfMruList(((Wizard)this.Wizard).UserSettings.MruEndpoints, this.Endpoint);
            try
            {
                if (!UserSettings.GenerateCSharpClient && !UserSettings.GenerateCSharpController && !UserSettings.GenerateTypeScriptClient)
                {
                    throw new Exception("Should check one of the checkboxes for generating!");
                }

                this.SpecificationTempPath = await GetSpecificationAsync();

                // convert from OData specification
                if (this.UserSettings.ConvertFromOdata)
                {
                    var csdl  = File.ReadAllText(this.SpecificationTempPath);
                    var model = CsdlReader.Parse(XElement.Parse(csdl).CreateReader());
                    if ((this.UserSettings.OpenApiConvertSettings.ServiceRoot == null || this.UserSettings.OpenApiConvertSettings.ServiceRoot.Host.Contains("localhost")) &&
                        this.UserSettings.Endpoint.StartsWith("http", StringComparison.Ordinal))
                    {
                        this.UserSettings.OpenApiConvertSettings.ServiceRoot = new Uri(this.UserSettings.Endpoint.TrimEnd("$metadata".ToCharArray()));
                    }
                    var document   = model.ConvertToOpenApi(this.UserSettings.OpenApiConvertSettings);
                    var outputJson = document.SerializeAsJson(this.UserSettings.OpenApiSpecVersion);
                    File.WriteAllText(this.SpecificationTempPath, outputJson);
                }

                return(await base.OnPageLeavingAsync(args));
            }
            catch (Exception e)
            {
                return(await Task.FromResult <PageNavigationResult>(
                           new PageNavigationResult
                {
                    ErrorMessage = e.Message,
                    IsSuccess = false,
                    ShowMessageBoxOnFailure = true
                }));
            }
        }
Exemplo n.º 2
0
        public void ReadNavigationPropertyPartnerTypeHierarchyTest()
        {
            var csdl =
                "<?xml version=\"1.0\" encoding=\"utf-16\"?>" +
                "<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" +
                "<edmx:DataServices>" +
                "<Schema Namespace=\"NS\" xmlns=\"http://docs.oasis-open.org/odata/ns/edm\">" +
                "<EntityType Name=\"EntityTypeA1\">" +
                "<Key><PropertyRef Name=\"ID\" /></Key>" +
                "<Property Name=\"ID\" Type=\"Edm.Int32\" />" +
                "<NavigationProperty Name=\"A1Nav\" Type=\"NS.EntityTypeB\" Nullable=\"false\" Partner=\"BNav1\" />" +
                "</EntityType>" +
                "<EntityType Name=\"EntityTypeA2\" BaseType=\"NS.EntityTypeA1\" />" +
                "<EntityType Name=\"EntityTypeA3\" BaseType=\"NS.EntityTypeA2\">" +
                "<NavigationProperty Name=\"A3Nav\" Type=\"NS.EntityTypeB\" Nullable=\"false\" Partner=\"BNav2\" />" +
                "</EntityType>" +
                "<EntityType Name=\"EntityTypeB\">" +
                "<Key><PropertyRef Name=\"ID\" /></Key>" +
                "<Property Name=\"ID\" Type=\"Edm.Int32\" />" +
                "<NavigationProperty Name=\"BNav1\" Type=\"NS.EntityTypeA2\" Nullable=\"false\" Partner=\"A1Nav\" />" +
                "<NavigationProperty Name=\"BNav2\" Type=\"NS.EntityTypeA3\" Nullable=\"false\" Partner=\"NS.EntityTypeA3/A3Nav\" />" +
                "</EntityType>" +
                "</Schema>" +
                "</edmx:DataServices>" +
                "</edmx:Edmx>";
            var model        = CsdlReader.Parse(XElement.Parse(csdl).CreateReader());
            var entityTypeA1 = (IEdmEntityType)model.FindDeclaredType("NS.EntityTypeA1");
            var entityTypeA2 = (IEdmEntityType)model.FindDeclaredType("NS.EntityTypeA2");
            var entityTypeA3 = (IEdmEntityType)model.FindDeclaredType("NS.EntityTypeA3");
            var entityTypeB  = (IEdmEntityType)model.FindDeclaredType("NS.EntityTypeB");

            Assert.Equal("BNav1", ((IEdmNavigationProperty)entityTypeA2.FindProperty("A1Nav")).GetPartnerPath().Path);
            Assert.Equal(entityTypeB.FindProperty("BNav1"), ((IEdmNavigationProperty)entityTypeA2.FindProperty("A1Nav")).Partner);
            Assert.Equal("BNav2", ((IEdmNavigationProperty)entityTypeA3.FindProperty("A3Nav")).GetPartnerPath().Path);
            Assert.Equal(entityTypeB.FindProperty("BNav2"), ((IEdmNavigationProperty)entityTypeA3.FindProperty("A3Nav")).Partner);
            Assert.Equal("A1Nav", ((IEdmNavigationProperty)entityTypeB.FindProperty("BNav1")).GetPartnerPath().Path);
            Assert.Equal(entityTypeA2.FindProperty("A1Nav"), ((IEdmNavigationProperty)entityTypeB.FindProperty("BNav1")).Partner);
            Assert.Equal("NS.EntityTypeA3/A3Nav", ((IEdmNavigationProperty)entityTypeB.FindProperty("BNav2")).GetPartnerPath().Path);
            Assert.Equal(entityTypeA3.FindProperty("A3Nav"), ((IEdmNavigationProperty)entityTypeB.FindProperty("BNav2")).Partner);
        }
Exemplo n.º 3
0
        public void AmbiguousOperationImportTest()
        {
            string csdl = @"
<Schema Namespace=""DefaultNamespace"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <Annotations Target=""DefaultNamespace.Container/FunctionImport"">
        <Annotation Term=""AnnotationNamespace.Annotation"">
          <Int>42</Int>
        </Annotation>
      </Annotations>
      <Action Name=""Operation"">
        <Parameter Name=""Parameter"" Type=""Edm.String"" />
        <ReturnType Type=""Edm.Int32"" />
      </Action>

     <EntityContainer Name=""Container"">
        <ActionImport Name=""FunctionImport"" Action=""DefaultNamespace.Operation"" />
        <ActionImport Name=""FunctionImport"" Action=""DefaultNamespace.Operation"" />
      </EntityContainer>
    </Schema>";

            IEdmModel model;
            IEnumerable <EdmError> errors;
            bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(csdl)) }, out model, out errors);

            Assert.IsTrue(parsed, "parsed");
            Assert.IsTrue(errors.Count() == 0, "No errors");

            IEdmVocabularyAnnotation annotation               = model.VocabularyAnnotations.First();
            IEdmEntityContainer      container                = model.EntityContainer;
            IEdmOperationImport      firstOperationImport     = container.FindOperationImports("FunctionImport").First();
            IEdmOperationImport      ambiguousOperationImport = annotation.Target as IEdmOperationImport;

            Assert.IsNotNull(ambiguousOperationImport, "Function not null");
            Assert.AreEqual(EdmContainerElementKind.ActionImport, ambiguousOperationImport.ContainerElementKind, "Correct schema element kind");
            Assert.AreEqual(firstOperationImport.Operation.ReturnType, ambiguousOperationImport.Operation.ReturnType, "Function gets return type from first function");
            Assert.AreEqual(firstOperationImport.Operation.Parameters.First(), ambiguousOperationImport.Operation.Parameters.First(), "Function gets parameters from first function");
            Assert.AreEqual(firstOperationImport.Operation.FindParameter("Parameter"), ambiguousOperationImport.Operation.FindParameter("Parameter"), "Find parameter defers to first function");
            Assert.AreEqual(container, ambiguousOperationImport.Container, "Correct container");
            Assert.AreEqual(null, ambiguousOperationImport.EntitySet, "Correct container");
        }
Exemplo n.º 4
0
        private void ValidateNavigationWithExpectedErrors(string navigationText, EdmErrorCode[] errorCodes, string[] messages)
        {
            const string template  = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""Test"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityType Name=""EntityType"">
        <Key>
          <PropertyRef Name=""ID"" />
        </Key>
        <Property Name=""ID"" Type=""Edm.Int32"" Nullable=""false"" />
        {0}
      </EntityType>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            string       modelText = string.Format(template, navigationText);

            IEdmModel model;
            IEnumerable <EdmError> errors;

            CsdlReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out errors).Should().BeTrue();

            bool result = model.Validate(out errors);

            if (errorCodes.Length > 0)
            {
                result.Should().BeFalse();

                errors.Should().HaveCount(messages.Length);
                for (int i = 0; i < messages.Length; i++)
                {
                    errors.Should().Contain(e => e.ErrorCode == errorCodes[i] && e.ErrorMessage == messages[i]);
                }
            }
            else
            {
                result.Should().BeTrue();
                errors.Should().BeEmpty();
            }
        }
Exemplo n.º 5
0
        public void ValidateNavigationPropertyBindingPathTraversesContainmentNavigationProperties()
        {
            var csdl
                = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" +
                  "<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" +
                  "<edmx:DataServices>" +
                  "<Schema Namespace=\"NS\" xmlns=\"http://docs.oasis-open.org/odata/ns/edm\">" +
                  "<EntityType Name=\"RootEntity\">" +
                  "<NavigationProperty Name=\"SetA\" Type=\"Collection(NS.EntityA)\" ContainsTarget=\"true\" />" +
                  "<NavigationProperty Name=\"SetB\" Type=\"Collection(NS.EntityB)\" ContainsTarget=\"true\" />" +
                  "</EntityType>" +
                  "<EntityType Name=\"EntityA\">" +
                  "<NavigationProperty Name=\"EntityAToB\" Type=\"Collection(NS.EntityB)\" />" +
                  "</EntityType>" +
                  "<EntityType Name=\"EntityB\"/>" +
                  "<EntityContainer Name=\"Container\">" +
                  "<Singleton Name=\"Root\" Type=\"NS.RootEntity\">" +
                  "<NavigationPropertyBinding Path=\"EntityA/EntityAToB\" Target=\"Root/SetB\" />" +
                  "</Singleton>" +
                  "</EntityContainer>" +
                  "</Schema>" +
                  "</edmx:DataServices>" +
                  "</edmx:Edmx>";
            var model  = CsdlReader.Parse(XElement.Parse(csdl).CreateReader());
            var setA   = model.FindDeclaredNavigationSource("Root");
            var target = setA.NavigationPropertyBindings.First().Target;

            Assert.True(target is IEdmContainedEntitySet);
            target.Name.Should().Be("SetB");
            var targetSegments = target.Path.PathSegments.ToList();

            targetSegments.Count().Should().Be(2);
            targetSegments[0].Should().Be("Root");
            targetSegments[1].Should().Be("SetB");
            var pathSegments = setA.NavigationPropertyBindings.First().Path.PathSegments.ToList();

            pathSegments.Count().Should().Be(2);
            pathSegments[0].Should().Be("EntityA");
            pathSegments[1].Should().Be("EntityAToB");
        }
Exemplo n.º 6
0
        private void InitializeEdmModel()
        {
            this.clientModel        = new ClientEdmModel(ODataProtocolVersion.V4);
            this.dataServiceContext = new DataServiceContext(new Uri(ServiceUri), ODataProtocolVersion.V4, this.clientModel);
            this.dataServiceContext.UndeclaredPropertyBehavior = UndeclaredPropertyBehavior.Support;
            this.dataServiceContext.ResolveType = (typeName) =>
            {
                return(this.dataServiceContext.DefaultResolveType(typeName, "NS.Models", "NS.Models"));
            };

            this.dataServiceContext.ResolveName = (clientType) =>
            {
                var originalNameAttribute = (OriginalNameAttribute)Enumerable.SingleOrDefault(Utility.GetCustomAttributes(clientType, typeof(OriginalNameAttribute), true));
                if (clientType.Namespace.Equals("NS.Models", global::System.StringComparison.Ordinal))
                {
                    if (originalNameAttribute != null)
                    {
                        return(string.Concat("NS.Models.", originalNameAttribute.OriginalName));
                    }

                    return(string.Concat("NS.Models.", clientType.Name));
                }

                if (originalNameAttribute != null)
                {
                    return(clientType.Namespace + "." + originalNameAttribute.OriginalName);
                }

                return(clientType.FullName);
            };

            using (var reader = XmlReader.Create(new StringReader(CamelCasedEdmx)))
            {
                if (CsdlReader.TryParse(reader, out IEdmModel serviceModel, out _))
                {
                    this.dataServiceContext.Format.UseJson(serviceModel);
                }
            }
        }
Exemplo n.º 7
0
        private IEdmModel GetEdmModel(string annotation)
        {
            const string template = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""NS"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <Function Name=""delta"" IsBound=""true"" >
         <Parameter Name=""bindingParameter"" Type=""Edm.String"" />
         <ReturnType Type=""Edm.String"" />
         {0}
      </Function>
    <Term Name=""MyOperationRestriction"" Type=""Org.OData.Capabilities.V1.OperationRestriction"" />
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";

            string    modelText = string.Format(template, annotation);
            IEdmModel model;
            bool      result = CsdlReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out _);

            Assert.True(result);
            return(model);
        }
        public static IEdmModel GetEdmModel(string annotation)
        {
            const string template  = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""microsoft.graph"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityType Name=""Todo"" HasStream=""true"">
        <Key>
          <PropertyRef Name=""Id"" />
        </Key>
        <Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"" />
        <Property Name=""Logo"" Type=""Edm.Stream""/>
        <Property Name = ""Description"" Type = ""Edm.String"" />
      </EntityType>
      <EntityType Name=""user"" OpenType=""true"">
        <NavigationProperty Name = ""photo"" Type = ""microsoft.graph.profilePhoto"" >
            <Annotation Term=""Org.OData.Core.V1.Description"" String=""The user's profile photo."" />
        </NavigationProperty>
      </EntityType>
      <EntityType Name=""profilePhoto"" HasStream=""true"">
        <Property Name = ""height"" Type = ""Edm.Int32"" />
        <Property Name = ""width"" Type = ""Edm.Int32"" />
      </EntityType >
      <EntityContainer Name =""GraphService"">
        <EntitySet Name=""Todos"" EntityType=""microsoft.graph.Todo"" />
        <Singleton Name=""me"" Type=""microsoft.graph.user"" />
      </EntityContainer>
      <Annotations Target=""microsoft.graph.Todo/Logo"">
        {0}
      </Annotations>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            string       modelText = string.Format(template, annotation);

            bool result = CsdlReader.TryParse(XElement.Parse(modelText).CreateReader(), out IEdmModel model, out _);

            Assert.True(result);
            return(model);
        }
Exemplo n.º 9
0
        // Metadata serialization: add tests for reading/writing in-stream errors

        /// <summary>
        /// Creates a test model in the specified EDM(X) version for manual testing.
        /// </summary>
        /// <param name="edmxVersion">The EDM(X) version to use.</param>
        /// <returns>The created <see cref="IEdmModel"/>.</returns>
        private IEdmModel CreateTestModel(Version edmxVersion)
        {
            string ns = edmxVersion == MetadataUtils.EdmxVersion4
                          ? Microsoft.Test.Taupo.Contracts.EntityModel.Edm.EdmConstants.CsdlOasisNamespace.NamespaceName
                          : null;

            this.Assert.IsNotNull(ns, "Could not determine EDMX namespace for version " + edmxVersion + ".");

            string csdl = @"
<Schema Namespace='TestModel' p1:UseStrongSpatialTypes='false' xmlns:p1='http://schemas.microsoft.com/ado/2009/02/edm/annotation' xmlns='" + ns + @"'>
  <EntityContainer Name='DefaultContainer'>
    <EntitySet Name='EPMEntityType' EntityType='TestModel.EPMEntityType' />
  </EntityContainer>
  <EntityType Name='EPMEntityType'>
    <Key>
      <PropertyRef Name='ID' />
    </Key>
    <Property Name='ID' Type='Int32' Nullable='false' />
  </EntityType>
  <ComplexType Name='EPMComplexType'>
    <Property Name='Name' Type='String' />
  </ComplexType>
</Schema>";

            IEdmModel model;
            IEnumerable <EdmError> errors;

            using (XmlReader reader = XmlReader.Create(new StringReader(csdl)))
            {
                if (!CsdlReader.TryParse(new[] { reader }, out model, out errors))
                {
                    string errorStrings = string.Join(", ", errors.Select(e => e.ToString()).ToArray());
                    this.Assert.Fail("Could not parse CSDL: " + System.Environment.NewLine + errorStrings);
                }
            }

            model.SetEdmxVersion(edmxVersion);
            return(model);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Parse Capabilities Vocabulary Model from CapabilitiesVocabularies.xml
        /// </summary>
        static CapabilitiesVocabularyModel()
        {
            Assembly assembly = typeof(CapabilitiesVocabularyModel).GetAssembly();

            // Resource name has leading namespace and folder in .NetStandard dll.
            string[] allResources             = assembly.GetManifestResourceNames();
            string   capabilitiesVocabularies = allResources.FirstOrDefault(x => x.Contains("CapabilitiesVocabularies.xml"));

            Debug.Assert(capabilitiesVocabularies != null, "CapabilitiesVocabularies.xml: not found.");

            using (Stream stream = assembly.GetManifestResourceStream(capabilitiesVocabularies))
            {
                IEnumerable <EdmError> errors;
                Debug.Assert(stream != null, "CapabilitiesVocabularies.xml: stream!=null");
                CsdlReader.TryParse(XmlReader.Create(stream), out Instance, out errors);
            }

            ChangeTrackingTerm = Instance.FindDeclaredTerm(CapabilitiesVocabularyConstants.ChangeTracking);

            // It needn't to list all other terms like CoreVocabularyModel.cs, because Capabilities model class is
            // an internal class. Customers can call FindTerm(qualifiedName) method to get the corresponding term.
        }
Exemplo n.º 11
0
        public void CheckNewModelHasNoVersion()
        {
            EdmModel               model = new EdmModel();
            EdmEntityType          t1    = new EdmEntityType("Bunk", "T1");
            EdmStructuralProperty  p1    = t1.AddStructuralProperty("P1", EdmCoreModel.Instance.GetBoolean(false));
            EdmStructuralProperty  p2    = t1.AddStructuralProperty("P2", EdmCoreModel.Instance.GetDecimal(1, 1, false));
            EdmStructuralProperty  p3    = t1.AddStructuralProperty("P3", EdmCoreModel.Instance.GetTemporal(EdmPrimitiveTypeKind.Duration, 1, false));
            EdmStructuralProperty  p4    = t1.AddStructuralProperty("P4", EdmCoreModel.Instance.GetBinary(false, 4, false));
            EdmStructuralProperty  p5    = t1.AddStructuralProperty("P5", EdmCoreModel.Instance.GetBinary(false));
            IEdmStructuralProperty q1    = (IEdmStructuralProperty)t1.FindProperty("P1");
            IEdmStructuralProperty q2    = (IEdmStructuralProperty)t1.FindProperty("P2");
            IEdmStructuralProperty q3    = (IEdmStructuralProperty)t1.FindProperty("P3");
            IEdmStructuralProperty q4    = (IEdmStructuralProperty)t1.FindProperty("P4");
            IEdmStructuralProperty q5    = (IEdmStructuralProperty)t1.FindProperty("P5");

            model.AddElement(t1);

            Assert.IsNull(model.GetEdmVersion(), "Version is null");

            StringWriter      sw       = new StringWriter();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent   = true;
            settings.Encoding = System.Text.Encoding.UTF8;
            XmlWriter xw = XmlWriter.Create(sw, settings);
            IEnumerable <EdmError> errors;

            model.TryWriteCsdl(xw, out errors);
            xw.Flush();
            xw.Close();
            string outputText = sw.ToString();

            IEdmModel iEdmModel;
            bool      parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(outputText)) }, out iEdmModel, out errors);

            Assert.IsTrue(parsed, "Model Parsed");
            Assert.IsTrue(errors.Count() == 0, "No errors");
            Assert.AreEqual(EdmConstants.EdmVersionLatest, iEdmModel.GetEdmVersion(), "Version check");
        }
Exemplo n.º 12
0
        /// <summary>
        /// Converts CSDL to OpenAPI
        /// </summary>
        /// <param name="csdl">The CSDL stream.</param>
        /// <returns>An OpenAPI document.</returns>
        public static OpenApiDocument ConvertCsdlToOpenApi(Stream csdl)
        {
            var edmModel = CsdlReader.Parse(XElement.Load(csdl).CreateReader());

            var settings = new OpenApiConvertSettings()
            {
                EnableKeyAsSegment            = true,
                EnableOperationId             = true,
                PrefixEntityTypeNameBeforeKey = true,
                TagDepth                 = 2,
                EnablePagination         = true,
                EnableDiscriminatorValue = false,
                EnableDerivedTypesReferencesForRequestBody = false,
                EnableDerivedTypesReferencesForResponses   = false,
                ShowRootPath = true,
                ShowLinks    = true
            };
            OpenApiDocument document = edmModel.ConvertToOpenApi(settings);

            document = FixReferences(document);
            return(document);
        }
        public void ValidateActionImportReferencingNonExistingActionShouldReturnError()
        {
            const string errorDocument = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""Test"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityContainer Name=""Container"">
        <ActionImport Name=""Add"" Action=""Test.Add""/>
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";

            var model = CsdlReader.Parse(XElement.Parse(errorDocument).CreateReader());
            IEnumerable <EdmError> errors = null;

            model.Validate(out errors);

            var errorsList = errors.ToList();
            var error      = Assert.Single(errorsList);

            Assert.Equal(EdmErrorCode.BadUnresolvedOperation, error.ErrorCode);
        }
Exemplo n.º 14
0
        public void CheckDefaultVersionSerialization()
        {
            const string inputText =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""Grumble"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
  <ComplexType Name=""Smod"">
    <Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"" />
  </ComplexType>
</Schema>";

            IEdmModel model;
            IEnumerable <EdmError> errors;
            bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(inputText)) }, out model, out errors);

            Assert.IsTrue(parsed, "Model Parsed");
            Assert.IsTrue(errors.Count() == 0, "No errors");
            Assert.AreEqual(EdmConstants.EdmVersion4, model.GetEdmVersion(), "Version check");

            StringWriter      sw       = new StringWriter();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent   = true;
            settings.Encoding = System.Text.Encoding.UTF8;
            XmlWriter xw = XmlWriter.Create(sw, settings);

            // Make sure it is possible to remove version from the model.
            model.SetEdmVersion(null);
            Assert.IsNull(model.GetEdmVersion(), "Version is null");

            model.TryWriteCsdl(xw, out errors);
            xw.Flush();
            xw.Close();
            string outputText = sw.ToString();

            parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(outputText)) }, out model, out errors);
            Assert.IsTrue(parsed, "Model Parsed 2");
            Assert.IsTrue(errors.Count() == 0, "No errors 2");
            Assert.AreEqual(EdmConstants.EdmVersionLatest, model.GetEdmVersion(), "Version check 2");
        }
        /// <summary>
        /// This methods reads the metadata from the input and returns an <see cref="IEdmModel"/>
        /// representing the read metadata information.
        /// </summary>
        /// <param name="getReferencedModelReaderFunc">The function to load referenced model xml. If null, will stop loading the referenced models. Normally it should throw no exception.</param>
        /// <returns>An <see cref="IEdmModel"/> instance representing the read metadata.</returns>
        private IEdmModel ReadMetadataDocumentImplementation(Func <Uri, XmlReader> getReferencedModelReaderFunc)
        {
            IEdmModel model;
            IEnumerable <EdmError> errors;

            if (!CsdlReader.TryParse(this.xmlReader, getReferencedModelReaderFunc, out model, out errors))
            {
                Debug.Assert(errors != null, "errors != null");

                StringBuilder builder = new StringBuilder();
                foreach (EdmError error in errors)
                {
                    builder.AppendLine(error.ToString());
                }

                throw new ODataException(Strings.ODataMetadataInputContext_ErrorReadingMetadata(builder.ToString()));
            }

            Debug.Assert(model != null, "model != null");

            return(model);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Process the arguments.
        /// </summary>
        protected override IEdmModel GetEdmModel()
        {
            try
            {
                string csdl      = File.ReadAllText(Input);
                var    directory = Path.GetDirectoryName(Input);
                var    parsed    = XElement.Parse(csdl);
                using (XmlReader mainReader = parsed.CreateReader())
                {
                    return(CsdlReader.Parse(mainReader, u =>
                    {
                        // Currently only support relative paths
                        if (u.IsAbsoluteUri)
                        {
                            Console.WriteLine($"Referenced model must use relative paths to the main model.");
                            return null;
                        }

                        var file = Path.Combine(directory, u.OriginalString);
                        string referenceText = File.ReadAllText(file);
                        var referenceParsed = XElement.Parse(referenceText);
                        XmlReader referenceReader = referenceParsed.CreateReader();
                        return referenceReader;
                    }));
                }
            }
            catch (EdmParseException parseException)
            {
                Console.WriteLine("Failed to parse the CSDL file.");
                Console.WriteLine(string.Join(Environment.NewLine, parseException.Errors.Select(e => e.ToString())));
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Gets all the operation imports in the model
        /// </summary>
        /// <param name="path">Edmx file path.</param>
        /// <param name="context">ConnectedServiceContext object.</param>
        /// <returns>Edm model</returns>
        public static IEdmModel GetEdmModelFromFile(string path, ConnectedServiceContext context = null)
        {
            var xmlSettings = new XmlReaderSettings
            {
                DtdProcessing = DtdProcessing.Parse
            };

            using (var reader = XmlReader.Create(path, xmlSettings))
            {
                try
                {
                    var result = CsdlReader.TryParse(reader, true /* ignoreUnexpectedAttributes */, out var model, out var errors);
                    if (result)
                    {
                        return(model);
                    }

                    if (context != null)
                    {
                        foreach (var error in errors)
                        {
                            var task = context.Logger?.WriteMessageAsync(LoggerMessageCategory.Warning,
                                                                         error.ErrorMessage);
                            task?.RunSynchronously();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (context != null)
                    {
                        var task = context.Logger?.WriteMessageAsync(LoggerMessageCategory.Warning, ex.Message);
                        task?.RunSynchronously();
                    }
                }
            }
            return(null);
        }
Exemplo n.º 18
0
        private static IEdmModel GetEdmModel()
        {
            IEdmModel edmModel = null;

            try
            {
                //Hard coded for demo purpose

                //Edmx version 4.01 not working - Edm error is generated saying invalid version
                //As per OData - both version 4.0 and 4.01 are accepted - Refer http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/cs01/schemas/edmx.xsd
                string xml = "<edmx:Edmx xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\" Version=\"4.01\">\r\n  <edmx:DataServices>\r\n    <Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" Namespace=\"OdataTest\">\r\n      <EntityType Name=\"Dataset1\">\r\n        <Key>\r\n          <PropertyRef Name=\"ID\" />\r\n        </Key>\r\n        <Property Name=\"ID\" Type=\"Edm.Int32\" Nullable=\"false\" />\r\n        <Property Name=\"Number\" Type=\"Edm.Int32\" Nullable=\"false\" />\r\n        <Property Name=\"String\" Type=\"Edm.String\" MaxLength=\"30\" />\r\n      </EntityType>\r\n      <EntityContainer Name=\"Dataset1Entities\">\r\n        <EntitySet Name=\"Dataset1\" EntityType=\"OdataTest.Dataset1\" />\r\n      </EntityContainer>\r\n    </Schema>\r\n  </edmx:DataServices>\r\n</edmx:Edmx>";

                //Edmx version 4.0 is working
                //string xml = "<edmx:Edmx xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\" Version=\"4.0\">\r\n  <edmx:DataServices>\r\n    <Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" Namespace=\"OdataTest\">\r\n      <EntityType Name=\"Dataset1\">\r\n        <Key>\r\n          <PropertyRef Name=\"ID\" />\r\n        </Key>\r\n        <Property Name=\"ID\" Type=\"Edm.Int32\" Nullable=\"false\" />\r\n        <Property Name=\"Number\" Type=\"Edm.Int32\" Nullable=\"false\" />\r\n        <Property Name=\"String\" Type=\"Edm.String\" MaxLength=\"30\" />\r\n      </EntityType>\r\n      <EntityContainer Name=\"Dataset1Entities\">\r\n        <EntitySet Name=\"Dataset1\" EntityType=\"OdataTest.Dataset1\" />\r\n      </EntityContainer>\r\n    </Schema>\r\n  </edmx:DataServices>\r\n</edmx:Edmx>";


                var stringReader = new StringReader(xml);
                var xmlReader    = XmlReader.Create(stringReader);

                IEnumerable <EdmError> edmErrors;
                CsdlReader.TryParse(xmlReader, out edmModel, out edmErrors);


                if (edmErrors != null && edmErrors.Count() > 0)
                {
                    edmModel = null;
                }
                if (edmModel != null && edmModel.EntityContainer == null)
                {
                    edmModel = null;
                }
                return(edmModel);
            }
            catch (Exception ex)
            {
                return(edmModel);
            }
        }
Exemplo n.º 19
0
        void VerifyResult(string inputText, string expectedResult, EdmxTarget target)
        {
            IEdmModel model;
            IEnumerable <EdmError> errors;
            bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(inputText)) }, out model, out errors);

            Assert.IsTrue(parsed, "Model Parsed");
            Assert.IsTrue(errors.Count() == 0, "No Errors");

            StringWriter      sw       = new StringWriter();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent   = true;
            settings.Encoding = System.Text.Encoding.UTF8;
            XmlWriter xw = XmlWriter.Create(sw, settings);

            EdmxWriter.TryWriteEdmx(model, xw, target, out errors);
            xw.Flush();
            xw.Close();
            string outputText = sw.ToString();

            Assert.AreEqual(expectedResult, outputText, "Expected Result = Output");
        }
Exemplo n.º 20
0
        public void AllElementsWithCircleRefTest()
        {
            string mainModelxml = @"<?xml version=""1.0"" encoding=""utf-16""?>
<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx""> 
  <edmx:DataServices>
    <Schema Namespace=""Namespace0"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">  
        <EntityContainer Name=""Container"" Extends=""Namespace0.Container"" />
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";

            IEdmModel mainModel;
            IEnumerable <EdmError> errors;

            bool parsed = CsdlReader.TryParse(XmlReader.Create(new StringReader(mainModelxml)), out mainModel, out errors);

            Assert.IsTrue(parsed);

            var    container = mainModel.EntityContainer;
            Action action    = () => container.AllElements();

            action.ShouldThrow <InvalidOperationException>().WithMessage(Strings.Bad_CyclicEntityContainer("Namespace0.Container"));
        }
Exemplo n.º 21
0
        static CapabilitiesHelpers()
        {
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ODataSamples.Services.Core.Vocabularies.CapabilitiesVocabularies.xml"))
            {
                IEnumerable <EdmError> errors;
                CsdlReader.TryParse(new[] { XmlReader.Create(stream) }, out Instance, out errors);
            }

            ConformanceLevelTerm = Instance.FindDeclaredValueTerm(CapabilitiesConformanceLevel);
            SupportedFormatsTerm = Instance.FindDeclaredValueTerm(CapabilitiesSupportedFormats);
            AsynchronousRequestsSupportedTerm = Instance.FindDeclaredValueTerm(CapabilitiesAsynchronousRequestsSupported);
            BatchContinueOnErrorSupportedTerm = Instance.FindDeclaredValueTerm(CapabilitiesBatchContinueOnErrorSupported);
            ChangeTrackingTerm         = Instance.FindDeclaredValueTerm(CapabilitiesChangeTracking);
            NavigationRestrictionsTerm = Instance.FindDeclaredValueTerm(CapabilitiesNavigationRestrictions);
            FilterFunctionsTerm        = Instance.FindDeclaredValueTerm(CapabilitiesFilterFunctions);
            SearchRestrictionsTerm     = Instance.FindDeclaredValueTerm(CapabilitiesSearchRestrictions);
            InsertRestrictionsTerm     = Instance.FindDeclaredValueTerm(CapabilitiesInsertRestrictions);
            UpdateRestrictionsTerm     = Instance.FindDeclaredValueTerm(CapabilitiesUpdateRestrictions);
            DeleteRestrictionsTerm     = Instance.FindDeclaredValueTerm(CapabilitiesDeleteRestrictions);
            ConformanceLevelTypeType   = (IEdmEnumType)Instance.FindDeclaredType(CapabilitiesConformanceLevelType);
            NavigationTypeType         = (IEdmEnumType)Instance.FindDeclaredType(CapabilitiesNavigationType);
            SearchExpressionsType      = (IEdmEnumType)Instance.FindDeclaredType(CapabilitiesSearchExpressions);
        }
Exemplo n.º 22
0
        public void NoSourceOfErrorLocation()
        {
            const string csdl =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""MyNS"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
  <EntityType Name1=""Person"">
    <Key>
      <PropertyRef Name=""Id"" />
    </Key>
    <Property Name=""Id"" Type=""Int32"" Nullable=""false"" />
    <Property Name=""Name"" Type=""String"" />
  </EntityType>
</Schema>";
            IEdmModel model;
            IEnumerable <EdmError> error;
            bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(csdl)) }, out model, out error);

            Assert.IsFalse(parsed, "parsed");

            var location = (CsdlLocation)error.First().ErrorLocation;

            Assert.AreEqual(string.Empty, location.Source);
        }
        public void ValidateEntitySetPathExpressionCannotHaveValueWhenActionNonBound()
        {
            const string           errorDocument = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""Test"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <Action Name=""Add"" EntitySetPath=""Param/Thing"">
        <Parameter Name=""Param"" Type=""Edm.String"" />
        <ReturnType Type=""Test.Person"" />
      </Action>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            IEdmModel              model         = null;
            IEnumerable <EdmError> errors        = null;
            var errorParsing = CsdlReader.TryParse(XElement.Parse(errorDocument).CreateReader(), out model, out errors);

            Assert.False(errorParsing);
            var errorsList = errors.ToList();
            var error      = Assert.Single(errorsList);

            Assert.Equal(EdmErrorCode.InvalidEntitySetPath, error.ErrorCode);
            Assert.Equal(Strings.CsdlParser_InvalidEntitySetPathWithUnboundAction(CsdlConstants.Element_Action, "Add"), error.ErrorMessage);
        }
Exemplo n.º 24
0
        private void ParseReferentialConstraint(string referentialConstraintText, EdmErrorCode?errorCode = null, params string[] messages)
        {
            const string template  = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""Test"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityType Name=""EntityType"">
        <Key>
          <PropertyRef Name=""ID1"" />
          <PropertyRef Name=""ID2"" />
        </Key>
        <Property Name=""ID1"" Type=""Edm.Int32"" Nullable=""false"" />
        <Property Name=""ID2"" Type=""Edm.Int32"" Nullable=""false"" />
        <Property Name=""ForeignKeyId1"" Type=""Edm.Int32"" />
        <Property Name=""ForeignKeyId2"" Type=""Edm.Int32"" />
        <NavigationProperty Name=""Navigation"" Type=""Test.EntityType"" Nullable=""true"">
          {0}
        </NavigationProperty>
      </EntityType>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            string       modelText = string.Format(template, referentialConstraintText);

            IEdmModel model;
            IEnumerable <EdmError> errors;
            bool result = CsdlReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out errors);

            if (errorCode != null)
            {
                result.Should().BeFalse();
                errors.Should().HaveCount(messages.Length);
                foreach (var message in messages)
                {
                    errors.Should().Contain(e => e.ErrorCode == errorCode && e.ErrorMessage == message);
                }
            }
        }
Exemplo n.º 25
0
        public async Task CanRenamePropertiesInRegularModelBuilder()
        {
            HttpRequestMessage  request  = new HttpRequestMessage(HttpMethod.Get, BaseAddress + "/explicit/$metadata");
            HttpResponseMessage response = await Client.SendAsync(request);

            IEdmModel model = CsdlReader.Parse(XmlReader.Create(await response.Content.ReadAsStreamAsync()));
            // Can change the name of regular, complex and navigation properties.
            IEdmEntityType customer = model.FindDeclaredType("ModelAliasing.Customer") as IEdmEntityType;

            Assert.NotNull(customer);
            Assert.NotNull(customer.FindProperty("FinancialAddress"));
            Assert.NotNull(customer.FindProperty("ClientName"));
            Assert.NotNull(customer.FindProperty("Purchases"));
            // Can change the name of properties on complex objects
            IEdmComplexType address = model.FindDeclaredType("Location.Direction") as IEdmComplexType;

            Assert.NotNull(address);
            Assert.NotNull(address.FindProperty("Reign"));
            //Can change the name of properties on derived entities.
            IEdmEntityType expressOrder = model.FindDeclaredType("Purchasing.ExpressOrder") as IEdmEntityType;

            Assert.NotNull(expressOrder);
            //Can change the name of properties on derived entities when added explicitly.
            Assert.NotNull(expressOrder.FindProperty("Fee"));
            //Data contract attribute doesn't change the name of the property.
            Assert.Null(expressOrder.FindProperty("DeliveryDate"));
            Assert.Null(expressOrder.FindProperty("GuanteedDeliveryDate"));
            // Data contract attribute doesn't change the names of the properties
            IEdmEntityType ordersLines = model.FindDeclaredType("Microsoft.Test.E2E.AspNet.OData.ModelAliasing.ModelAliasingMetadataOrderLine") as IEdmEntityType;

            Assert.NotNull(ordersLines);
            Assert.Null(ordersLines.FindProperty("Product"));
            Assert.NotNull(ordersLines.FindProperty("Item"));
            // Data contract attribute doesn't override any explicit configuration on the model builder
            Assert.NotNull(ordersLines.FindProperty("Cost"));
        }
Exemplo n.º 26
0
        public static IEdmModel GetEdmModel(string inline, string outline)
        {
            const string template  = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""NS"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityType Name=""Calendar"">
        <Key>
          <PropertyRef Name=""Id"" />
        </Key>
        <Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"" />
        <NavigationProperty Name=""RelatedEvents"" Type=""Collection(NS.Event)"" />
      </EntityType>
      <EntityType Name=""Event"">
        <Key>
          <PropertyRef Name=""Id"" />
        </Key>
        <Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"" />
        <NavigationProperty Name=""RelatedCalendar"" Type=""NS.Calendar"" />
      </EntityType>
      <EntityContainer Name=""Default"">
        <EntitySet Name=""Calendars"" EntityType=""NS.Calendar"" >
          <NavigationPropertyBinding Path=""RelatedEvents"" Target=""Events"" />
          {0}
        </EntitySet>
        <EntitySet Name=""Events"" EntityType=""NS.Event"" >
          <NavigationPropertyBinding Path=""RelatedCalendar"" Target=""Calendars"" />
        </EntitySet>
      </EntityContainer>
      {1}
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            string       modelText = string.Format(template, inline, outline);

            return(CsdlReader.Parse(XElement.Parse(modelText).CreateReader()));
        }
Exemplo n.º 27
0
        void VerifyRoundTrip(string inputText, Version expectedEdmVersion)
        {
            IEdmModel model;
            IEnumerable <EdmError> errors;
            bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(inputText)) }, out model, out errors);

            Assert.IsTrue(parsed, "Model Parsed");
            Assert.IsTrue(errors.Count() == 0, "No errors");
            Assert.AreEqual(expectedEdmVersion, model.GetEdmVersion(), "Version check");

            StringWriter      sw       = new StringWriter();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent   = true;
            settings.Encoding = System.Text.Encoding.UTF8;
            XmlWriter xw = XmlWriter.Create(sw, settings);

            model.TryWriteCsdl(xw, out errors);
            xw.Flush();
            xw.Close();
            string outputText = sw.ToString();

            Assert.AreEqual(inputText, outputText, "Input = Output");
        }
Exemplo n.º 28
0
        /// <summary>
        /// Easily wrap existing models as referenced models, and return a main model.
        /// </summary>
        /// <param name="referencedModels">NONE of them should have the container to extend.</param>
        /// <returns>The main model.</returns>
        public static IEdmModel WrapReferencedModelsToMainModel(params IEdmModel[] referencedModels)
        {
            Assert.True(referencedModels[0] != null, "referencedModels[0] != null");
            string    mainModelxml = @"<?xml version=""1.0"" encoding=""utf-16""?>
<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:Reference Uri=""http://host/schema/Location.xml"">
    <edmx:Include Namespace=""Test.Chh"" Alias=""NO_Alias"" />
  </edmx:Reference>
  <edmx:DataServices>
    <Schema Namespace=""MainModel_NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            IEdmModel ret;
            IEnumerable <EdmError> errors;

            if (CsdlReader.TryParse(XmlReader.Create(new StringReader(mainModelxml)), new List <IEdmModel>(referencedModels), out ret, out errors))
            {
                return(ret);
            }

            Assert.False(errors.Any(), "should be zero error.");
            return(null);
        }
Exemplo n.º 29
0
        private static IEdmModel ReadModel(string fileName, Func <Uri, XmlReader> getReferencedSchemaFunc = null)
        {
            IEdmModel model;

            using (Stream csdlStream = ReadResourceFromAssembly(fileName))
            {
                bool parseResult;
                IEnumerable <EdmError> errors;
                if (getReferencedSchemaFunc == null)
                {
                    parseResult = CsdlReader.TryParse(XmlReader.Create(csdlStream), out model, out errors);
                }
                else
                {
                    parseResult = CsdlReader.TryParse(XmlReader.Create(csdlStream), getReferencedSchemaFunc, out model, out errors);
                }

                if (!parseResult)
                {
                    throw new InvalidOperationException("Failed to load model : " + string.Join(Environment.NewLine, errors.Select(e => e.ErrorMessage)));
                }
            }
            return(model);
        }
Exemplo n.º 30
0
        public void ParsingXmlWithCollectionOfNavOnComplex()
        {
            string complexWithNav = "<?xml version=\"1.0\" encoding=\"utf-16\"?><edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" +
                                    "<edmx:DataServices><Schema Namespace=\"DefaultNs\" xmlns=\"http://docs.oasis-open.org/odata/ns/edm\">" +
                                    "<EntityType Name=\"EntityType\">" +
                                    "<Key><PropertyRef Name=\"ID\" /></Key>" +
                                    "<Property Name=\"ID\" Type=\"Edm.String\" Nullable=\"false\" />" +
                                    "<Property Name=\"Complex\" Type=\"DefaultNs.ComplexType\" Nullable=\"false\" />" +
                                    "</EntityType>" +
                                    "<EntityType Name=\"NavEntityType\">" +
                                    "<Key><PropertyRef Name=\"ID\" /></Key>" +
                                    "<Property Name=\"ID\" Type=\"Edm.String\" Nullable=\"false\" />" +
                                    "</EntityType>" +
                                    "<ComplexType Name=\"ComplexType\">" +
                                    "<Property Name=\"Prop1\" Type=\"Edm.Int32\" Nullable=\"false\" />" +
                                    "<NavigationProperty Name=\"CollectionOfNav\" Type=\"Collection(DefaultNs.NavEntityType)\" />" +
                                    "</ComplexType>" +
                                    "<EntityContainer Name=\"Container\">" +
                                    "<EntitySet Name=\"Entities\" EntityType=\"DefaultNs.EntityType\">" +
                                    "<NavigationPropertyBinding Path=\"Complex/CollectionOfNav\" Target=\"NavEntities\" />" +
                                    "</EntitySet>" +
                                    "<EntitySet Name=\"NavEntities\" EntityType=\"DefaultNs.NavEntityType\" />" +
                                    "</EntityContainer>" +
                                    "</Schema>" +
                                    "</edmx:DataServices>" +
                                    "</edmx:Edmx>";

            var model            = CsdlReader.Parse(XElement.Parse(complexWithNav).CreateReader());
            var people           = model.EntityContainer.FindEntitySet("Entities");
            var address          = model.FindType("DefaultNs.ComplexType") as IEdmStructuredType;
            var city             = address.FindProperty("CollectionOfNav") as IEdmNavigationProperty;
            var cities           = model.EntityContainer.FindEntitySet("NavEntities");
            var navigationTarget = people.FindNavigationTarget(city, new EdmPathExpression("Complex/CollectionOfNav"));

            Assert.Equal(navigationTarget, cities);
        }