public void WritingExpandedValue() { using (OpenWebDataServiceHelper.CreateODataWriterDelegate.Restore()) using (MyODataWriter.WriteEntryStart.Restore()) using (MyODataWriter.WriteLinkStart.Restore()) using (var request = TestWebRequest.CreateForInProcess()) { MyODataWriter testODataWriter = null; request.HttpMethod = "GET"; request.DataServiceType = typeof(CustomDataContext); OpenWebDataServiceHelper.CreateODataWriterDelegate.Value = (odataWriter) => { testODataWriter = new MyODataWriter(odataWriter); return(testODataWriter); }; object mostRecentEntry = null; MyODataWriter.WriteEntryStart.Value = (args) => { mostRecentEntry = args.Instance; return(false); }; MyODataWriter.WriteLinkStart.Value = (args) => { if (args.NavigationLink.Name == "BestFriend") { testODataWriter.CallBaseWriteStart(args.NavigationLink); var entry = CreateEntry(((Customer)mostRecentEntry).BestFriend, args.OperationContext); testODataWriter.CallBaseWriteStart(entry); testODataWriter.WriteEnd(); return(true); } return(false); }; request.RequestUriString = "/Customers?$format=atom"; request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPathResultCount(response, 2, new string[] { "/atom:feed/atom:entry/atom:link[@title='BestFriend']/adsm:inline/atom:entry" }); } }
[Ignore] // Remove Atom // [TestMethod] public void DataServiceOdataWriterWriteEndForLinksTest() { using (OpenWebDataServiceHelper.CreateODataWriterDelegate.Restore()) using (MyODataWriter.WriteLinkStart.Restore()) using (MyODataWriter.WriteLinkEnd.Restore()) using (var request = TestWebRequest.CreateForInProcess()) { MyODataWriter testODataWriter = null; request.HttpMethod = "GET"; request.DataServiceType = typeof(CustomDataContext); Stack <ODataItem> items = new Stack <ODataItem>(); int linksCount = 0; int linksStartedAndNotEnded = 0; OpenWebDataServiceHelper.CreateODataWriterDelegate.Value = (odataWriter) => { testODataWriter = new MyODataWriter(odataWriter); return(testODataWriter); }; MyODataWriter.WriteLinkStart.Value = (args) => { items.Push(args.NavigationLink); linksCount++; linksStartedAndNotEnded++; return(false); }; MyODataWriter.WriteLinkEnd.Value = (args) => { linksStartedAndNotEnded--; Assert.AreSame(args.NavigationLink, items.Pop()); return(false); }; request.RequestUriString = "/Customers(1)/Orders/$ref?$format=atom"; request.SendRequest(); Assert.AreEqual(linksStartedAndNotEnded, 0); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPathResultCount(response, linksCount, "/atom:links/atom:uri"); } }
[Ignore] // Remove Atom // [TestMethod] public void DataServiceOdataWriterWriteEndForFeedTest() { using (OpenWebDataServiceHelper.CreateODataWriterDelegate.Restore()) using (MyODataWriter.WriteFeedStart.Restore()) using (MyODataWriter.WriteEntryStart.Restore()) using (MyODataWriter.WriteLinkStart.Restore()) using (MyODataWriter.WriteFeedEnd.Restore()) using (MyODataWriter.WriteEntryEnd.Restore()) using (MyODataWriter.WriteLinkEnd.Restore()) using (var request = TestWebRequest.CreateForInProcess()) { MyODataWriter testODataWriter = null; request.HttpMethod = "GET"; request.DataServiceType = typeof(CustomDataContext); Stack <ODataItem> items = new Stack <ODataItem>(); int customersCount = 0; int customersStartedAndNotEnded = 0; int linksCount = 0; int linksStartedAndNotEnded = 0; bool feedStarted = false, feedEnded = false; OpenWebDataServiceHelper.CreateODataWriterDelegate.Value = (odataWriter) => { testODataWriter = new MyODataWriter(odataWriter); return(testODataWriter); }; MyODataWriter.WriteFeedStart.Value = (args) => { items.Push(args.Feed); feedStarted = true; return(false); }; MyODataWriter.WriteEntryStart.Value = (args) => { items.Push(args.Entry); customersCount++; customersStartedAndNotEnded++; return(false); }; MyODataWriter.WriteLinkStart.Value = (args) => { items.Push(args.NavigationLink); linksCount++; linksStartedAndNotEnded++; return(false); }; MyODataWriter.WriteFeedEnd.Value = (args) => { feedEnded = true; Assert.AreSame(args.Feed, items.Pop()); return(false); }; MyODataWriter.WriteEntryEnd.Value = (args) => { customersStartedAndNotEnded--; Assert.AreSame(args.Entry, items.Pop()); return(false); }; MyODataWriter.WriteLinkEnd.Value = (args) => { linksStartedAndNotEnded--; Assert.AreSame(args.NavigationLink, items.Pop()); return(false); }; request.RequestUriString = "/Customers?$format=atom"; request.SendRequest(); Assert.IsTrue(feedStarted); Assert.IsTrue(feedEnded); Assert.AreEqual(customersStartedAndNotEnded, 0); Assert.AreEqual(linksStartedAndNotEnded, 0); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPathResultCount(response, customersCount, "/atom:feed/atom:entry"); UnitTestsUtil.VerifyXPathResultCount(response, linksCount, "/atom:feed/atom:entry/atom:link[@title='BestFriend' or @title='Orders']"); } }
[Ignore] // Remove Atom // [TestMethod] public void ChangingFeedCollectionValueForTopLevel() { using (OpenWebDataServiceHelper.CreateODataWriterDelegate.Restore()) using (MyODataWriter.WriteEntryStart.Restore()) using (MyODataWriter.WriteFeedStart.Restore()) using (MyODataWriter.WriteLinkStart.Restore()) using (MyODataWriter.WriteEndDelegate.Restore()) using (var request = TestWebRequest.CreateForInProcess()) { MyODataWriter testODataWriter = null; request.HttpMethod = "GET"; request.DataServiceType = typeof(CustomDataContext); OpenWebDataServiceHelper.CreateODataWriterDelegate.Value = (odataWriter) => { testODataWriter = new MyODataWriter(odataWriter); return(testODataWriter); }; int CustomerCount = 0; int insideIgnoreCustomer = 0; MyODataWriter.WriteEntryStart.Value = (args) => { if (args.Entry.TypeName.Contains("Customer")) { // Only write the first instance of the customer on the wire CustomerCount++; if (CustomerCount != 1) { insideIgnoreCustomer = 1; return(true); } } return(false); }; MyODataWriter.WriteFeedStart.Value = (args) => { if (args.Feed.Id.OriginalString.Contains("Customers")) { testODataWriter.CallBaseWriteStart(new ODataResourceSet() { Id = args.Feed.Id, Count = 88 }); return(true); } return(false); }; MyODataWriter.WriteLinkStart.Value = (args) => { if (insideIgnoreCustomer > 0) { insideIgnoreCustomer++; return(true); } return(false); }; MyODataWriter.WriteEndDelegate.Value = () => { if (insideIgnoreCustomer > 0) { insideIgnoreCustomer--; return(true); } return(false); }; request.RequestUriString = "/Customers?$format=atom&$inlineCount=allpages"; request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); // verify that the count is 100 // verify that there is one customer written on the wire UnitTestsUtil.VerifyXPaths(response, new string[] { "/atom:feed[adsm:count=88]" }); UnitTestsUtil.VerifyXPathResultCount(response, 1, "/atom:feed/atom:entry"); } }
public void DataServiceOdataWriterWriteEndForFeedTest() { using (OpenWebDataServiceHelper.CreateODataWriterDelegate.Restore()) using (MyODataWriter.WriteFeedStart.Restore()) using (MyODataWriter.WriteEntryStart.Restore()) using (MyODataWriter.WriteLinkStart.Restore()) using (MyODataWriter.WriteFeedEnd.Restore()) using (MyODataWriter.WriteEntryEnd.Restore()) using (MyODataWriter.WriteLinkEnd.Restore()) using (var request = TestWebRequest.CreateForInProcess()) { MyODataWriter testODataWriter = null; request.HttpMethod = "GET"; request.DataServiceType = typeof(CustomDataContext); Stack<ODataItem> items = new Stack<ODataItem>(); int customersCount = 0; int customersStartedAndNotEnded = 0; int linksCount = 0; int linksStartedAndNotEnded = 0; bool feedStarted = false, feedEnded = false; OpenWebDataServiceHelper.CreateODataWriterDelegate.Value = (odataWriter) => { testODataWriter = new MyODataWriter(odataWriter); return testODataWriter; }; MyODataWriter.WriteFeedStart.Value = (args) => { items.Push(args.Feed); feedStarted = true; return false; }; MyODataWriter.WriteEntryStart.Value = (args) => { items.Push(args.Entry); customersCount++; customersStartedAndNotEnded++; return false; }; MyODataWriter.WriteLinkStart.Value = (args) => { items.Push(args.NavigationLink); linksCount++; linksStartedAndNotEnded++; return false; }; MyODataWriter.WriteFeedEnd.Value = (args) => { feedEnded = true; Assert.AreSame(args.Feed, items.Pop()); return false; }; MyODataWriter.WriteEntryEnd.Value = (args) => { customersStartedAndNotEnded--; Assert.AreSame(args.Entry, items.Pop()); return false; }; MyODataWriter.WriteLinkEnd.Value = (args) => { linksStartedAndNotEnded--; Assert.AreSame(args.NavigationLink, items.Pop()); return false; }; request.RequestUriString = "/Customers?$format=atom"; request.SendRequest(); Assert.IsTrue(feedStarted); Assert.IsTrue(feedEnded); Assert.AreEqual(customersStartedAndNotEnded, 0); Assert.AreEqual(linksStartedAndNotEnded, 0); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPathResultCount(response, customersCount, "/atom:feed/atom:entry"); UnitTestsUtil.VerifyXPathResultCount(response, linksCount, "/atom:feed/atom:entry/atom:link[@title='BestFriend' or @title='Orders']"); } }
public void DataServiceOdataWriterWriteEndForLinksTest() { using (OpenWebDataServiceHelper.CreateODataWriterDelegate.Restore()) using (MyODataWriter.WriteLinkStart.Restore()) using (MyODataWriter.WriteLinkEnd.Restore()) using (var request = TestWebRequest.CreateForInProcess()) { MyODataWriter testODataWriter = null; request.HttpMethod = "GET"; request.DataServiceType = typeof(CustomDataContext); Stack<ODataItem> items = new Stack<ODataItem>(); int linksCount = 0; int linksStartedAndNotEnded = 0; OpenWebDataServiceHelper.CreateODataWriterDelegate.Value = (odataWriter) => { testODataWriter = new MyODataWriter(odataWriter); return testODataWriter; }; MyODataWriter.WriteLinkStart.Value = (args) => { items.Push(args.NavigationLink); linksCount++; linksStartedAndNotEnded++; return false; }; MyODataWriter.WriteLinkEnd.Value = (args) => { linksStartedAndNotEnded--; Assert.AreSame(args.NavigationLink, items.Pop()); return false; }; request.RequestUriString = "/Customers(1)/Orders/$ref?$format=atom"; request.SendRequest(); Assert.AreEqual(linksStartedAndNotEnded, 0); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPathResultCount(response, linksCount, "/atom:links/atom:uri"); } }
public void WritingExpandedValue() { using (OpenWebDataServiceHelper.CreateODataWriterDelegate.Restore()) using (MyODataWriter.WriteEntryStart.Restore()) using (MyODataWriter.WriteLinkStart.Restore()) using (var request = TestWebRequest.CreateForInProcess()) { MyODataWriter testODataWriter = null; request.HttpMethod = "GET"; request.DataServiceType = typeof(CustomDataContext); OpenWebDataServiceHelper.CreateODataWriterDelegate.Value = (odataWriter) => { testODataWriter = new MyODataWriter(odataWriter); return testODataWriter; }; object mostRecentEntry = null; MyODataWriter.WriteEntryStart.Value = (args) => { mostRecentEntry = args.Instance; return false; }; MyODataWriter.WriteLinkStart.Value = (args) => { if (args.NavigationLink.Name == "BestFriend") { testODataWriter.CallBaseWriteStart(args.NavigationLink); var entry = CreateEntry(((Customer)mostRecentEntry).BestFriend, args.OperationContext); testODataWriter.CallBaseWriteStart(entry); testODataWriter.WriteEnd(); return true; } return false; }; request.RequestUriString = "/Customers?$format=atom"; request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPathResultCount(response, 2, new string[] { "/atom:feed/atom:entry/atom:link[@title='BestFriend']/adsm:inline/atom:entry" }); } }
public void ChangingFeedCollectionValueForTopLevel() { using (OpenWebDataServiceHelper.CreateODataWriterDelegate.Restore()) using (MyODataWriter.WriteEntryStart.Restore()) using (MyODataWriter.WriteFeedStart.Restore()) using (MyODataWriter.WriteLinkStart.Restore()) using (MyODataWriter.WriteEndDelegate.Restore()) using (var request = TestWebRequest.CreateForInProcess()) { MyODataWriter testODataWriter = null; request.HttpMethod = "GET"; request.DataServiceType = typeof(CustomDataContext); OpenWebDataServiceHelper.CreateODataWriterDelegate.Value = (odataWriter) => { testODataWriter = new MyODataWriter(odataWriter); return testODataWriter; }; int CustomerCount = 0; int insideIgnoreCustomer = 0; MyODataWriter.WriteEntryStart.Value = (args) => { if (args.Entry.TypeName.Contains("Customer")) { // Only write the first instance of the customer on the wire CustomerCount++; if (CustomerCount != 1) { insideIgnoreCustomer = 1; return true; } } return false; }; MyODataWriter.WriteFeedStart.Value = (args) => { if (args.Feed.Id.OriginalString.Contains("Customers")) { testODataWriter.CallBaseWriteStart(new ODataFeed() { Id = args.Feed.Id, Count = 88 }); return true; } return false; }; MyODataWriter.WriteLinkStart.Value = (args) => { if (insideIgnoreCustomer > 0) { insideIgnoreCustomer++; return true; } return false; }; MyODataWriter.WriteEndDelegate.Value = () => { if (insideIgnoreCustomer > 0) { insideIgnoreCustomer--; return true; } return false; }; request.RequestUriString = "/Customers?$format=atom&$inlineCount=allpages"; request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); // verify that the count is 100 // verify that there is one customer written on the wire UnitTestsUtil.VerifyXPaths(response, new string[] { "/atom:feed[adsm:count=88]" }); UnitTestsUtil.VerifyXPathResultCount(response, 1, "/atom:feed/atom:entry"); } }