private string WriteAndVerifyEmployeeEntry(StreamResponseMessage responseMessage, ODataWriter odataWriter, bool hasExpectedType, string mimeType) { ODataEntry employeeEntry = WritePayloadHelper.CreateEmployeeEntry(false); ODataFeedAndEntrySerializationInfo serializationInfo = new ODataFeedAndEntrySerializationInfo() { NavigationSourceName = "Person", NavigationSourceEntityTypeName = NameSpace + "Person", }; if (hasExpectedType) { serializationInfo.ExpectedTypeName = NameSpace + "Employee"; } employeeEntry.SetSerializationInfo(serializationInfo); odataWriter.WriteStart(employeeEntry); var employeeNavigation1 = new ODataNavigationLink() { Name = "PersonMetadata", IsCollection = true, Url = new Uri("Person(-3)/" + NameSpace + "Employee" + "/PersonMetadata", UriKind.Relative) }; odataWriter.WriteStart(employeeNavigation1); odataWriter.WriteEnd(); var employeeNavigation2 = new ODataNavigationLink() { Name = "Manager", IsCollection = false, Url = new Uri("Person(-3)/" + NameSpace + "Employee" + "/Manager", UriKind.Relative) }; odataWriter.WriteStart(employeeNavigation2); odataWriter.WriteEnd(); // Finish writing employeeEntry. odataWriter.WriteEnd(); // Some very basic verification for the payload. bool verifyEntryCalled = false; bool verifyNavigationCalled = false; Action <ODataEntry> verifyEntry = (entry) => { Assert.IsTrue(entry.EditLink.AbsoluteUri.Contains("Person"), "entry.EditLink"); verifyEntryCalled = true; }; Action <ODataNavigationLink> verifyNavigation = (navigation) => { Assert.IsTrue(navigation.Name == "PersonMetadata" || navigation.Name == "Manager", "navigation.Name"); verifyNavigationCalled = true; }; Stream stream = responseMessage.GetStream(); if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) { stream.Seek(0, SeekOrigin.Begin); WritePayloadHelper.ReadAndVerifyFeedEntryMessage(false, responseMessage, WritePayloadHelper.PersonSet, WritePayloadHelper.PersonType, null, verifyEntry, verifyNavigation); Assert.IsTrue(verifyEntryCalled && verifyNavigationCalled, "Verification action not called."); } return(WritePayloadHelper.ReadStreamContent(stream)); }
private string WriteAndVerifyPersonFeed(StreamResponseMessage responseMessage, ODataWriter odataWriter, bool hasModel, string mimeType) { var personFeed = new ODataFeed() { Id = new Uri(this.ServiceUri + "Person"), DeltaLink = new Uri(this.ServiceUri + "Person") }; if (!hasModel) { personFeed.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo() { NavigationSourceName = "Person", NavigationSourceEntityTypeName = NameSpace + "Person" }); } odataWriter.WriteStart(personFeed); ODataEntry personEntry = WritePayloadHelper.CreatePersonEntry(hasModel); odataWriter.WriteStart(personEntry); var personNavigation = new ODataNavigationLink() { Name = "PersonMetadata", IsCollection = true, Url = new Uri("Person(-5)/PersonMetadata", UriKind.Relative) }; odataWriter.WriteStart(personNavigation); odataWriter.WriteEnd(); // Finish writing personEntry. odataWriter.WriteEnd(); ODataEntry employeeEntry = WritePayloadHelper.CreateEmployeeEntry(hasModel); odataWriter.WriteStart(employeeEntry); var employeeNavigation1 = new ODataNavigationLink() { Name = "PersonMetadata", IsCollection = true, Url = new Uri("Person(-3)/" + NameSpace + "Employee" + "/PersonMetadata", UriKind.Relative) }; odataWriter.WriteStart(employeeNavigation1); odataWriter.WriteEnd(); var employeeNavigation2 = new ODataNavigationLink() { Name = "Manager", IsCollection = false, Url = new Uri("Person(-3)/" + NameSpace + "Employee" + "/Manager", UriKind.Relative) }; odataWriter.WriteStart(employeeNavigation2); odataWriter.WriteEnd(); // Finish writing employeeEntry. odataWriter.WriteEnd(); ODataEntry specialEmployeeEntry = WritePayloadHelper.CreateSpecialEmployeeEntry(hasModel); odataWriter.WriteStart(specialEmployeeEntry); var specialEmployeeNavigation1 = new ODataNavigationLink() { Name = "PersonMetadata", IsCollection = true, Url = new Uri("Person(-10)/" + NameSpace + "SpecialEmployee" + "/PersonMetadata", UriKind.Relative) }; odataWriter.WriteStart(specialEmployeeNavigation1); odataWriter.WriteEnd(); var specialEmployeeNavigation2 = new ODataNavigationLink() { Name = "Manager", IsCollection = false, Url = new Uri("Person(-10)/" + NameSpace + "SpecialEmployee" + "/Manager", UriKind.Relative) }; odataWriter.WriteStart(specialEmployeeNavigation2); odataWriter.WriteEnd(); var specialEmployeeNavigation3 = new ODataNavigationLink() { Name = "Car", IsCollection = false, Url = new Uri("Person(-10)/" + NameSpace + "SpecialEmployee" + "/Manager", UriKind.Relative) }; odataWriter.WriteStart(specialEmployeeNavigation3); odataWriter.WriteEnd(); // Finish writing specialEmployeeEntry. odataWriter.WriteEnd(); // Finish writing the feed. odataWriter.WriteEnd(); // Some very basic verification for the payload. bool verifyFeedCalled = false; bool verifyEntryCalled = false; bool verifyNavigationCalled = false; Action <ODataFeed> verifyFeed = (feed) => { if (mimeType != MimeTypes.ApplicationAtomXml) { Assert.IsTrue(feed.DeltaLink.AbsoluteUri.Contains("Person")); } verifyFeedCalled = true; }; Action <ODataEntry> verifyEntry = (entry) => { Assert.IsTrue(entry.EditLink.AbsoluteUri.EndsWith("Person(-5)") || entry.EditLink.AbsoluteUri.EndsWith("Person(-3)/" + NameSpace + "Employee") || entry.EditLink.AbsoluteUri.EndsWith("Person(-10)/" + NameSpace + "SpecialEmployee")); verifyEntryCalled = true; }; Action <ODataNavigationLink> verifyNavigation = (navigation) => { Assert.IsTrue(navigation.Name == "PersonMetadata" || navigation.Name == "Manager" || navigation.Name == "Car"); verifyNavigationCalled = true; }; Stream stream = responseMessage.GetStream(); if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) { stream.Seek(0, SeekOrigin.Begin); WritePayloadHelper.ReadAndVerifyFeedEntryMessage(true, responseMessage, WritePayloadHelper.PersonSet, WritePayloadHelper.PersonType, verifyFeed, verifyEntry, verifyNavigation); Assert.IsTrue(verifyFeedCalled && verifyEntryCalled && verifyNavigationCalled, "Verification action not called."); } return(WritePayloadHelper.ReadStreamContent(stream)); }