From 58a1c542d22ac3733bb10b3a15bb89ff33b48fc6 Mon Sep 17 00:00:00 2001 From: Congyong Su Date: Thu, 10 Dec 2015 20:47:58 -0800 Subject: [PATCH] QueryEntityInstance etc. test cases work in VS2015 Resolve #409 --- .../ClientTests/ClientQueryTests.cs | 138 ++--- .../PipelineEventsCrossPlatformAsyncTests.cs | 483 ++++++++-------- .../PipelineEventsTests.cs | 535 +++++++++--------- 3 files changed, 589 insertions(+), 567 deletions(-) diff --git a/test/EndToEndTests/Tests/Client/Build.Desktop/ClientTests/ClientQueryTests.cs b/test/EndToEndTests/Tests/Client/Build.Desktop/ClientTests/ClientQueryTests.cs index 80736fc17e..4ec28c5b93 100644 --- a/test/EndToEndTests/Tests/Client/Build.Desktop/ClientTests/ClientQueryTests.cs +++ b/test/EndToEndTests/Tests/Client/Build.Desktop/ClientTests/ClientQueryTests.cs @@ -182,82 +182,94 @@ public void QueryEntityNavigationWithImplicitKeys() [TestMethod] public void MergeProjectionAndQueryOptionTest() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - var query = from p in contextWrapper.Context.Product.AddQueryOption("$select", "ProductId") - where p.ProductId == -10 - select new Product() { Description = p.Description, Photos = p.Photos }; - - Uri uri = ((DataServiceQuery)query).RequestUri; - Assert.AreEqual("?$expand=Photos&$select=Description,ProductId", uri.Query); - Assert.IsTrue(query.ToList().Count == 1); - }); + this.RunOnAtomAndJsonFormats(CreateContext, MergeProjectionAndQueryOptionTest); + } + + private static void MergeProjectionAndQueryOptionTest( + DataServiceContextWrapper contextWrapper) + { + var query = from p in contextWrapper.Context.Product.AddQueryOption("$select", "ProductId") + where p.ProductId == -10 + select new Product() { Description = p.Description, Photos = p.Photos }; + + Uri uri = ((DataServiceQuery)query).RequestUri; + Assert.AreEqual("?$expand=Photos&$select=Description,ProductId", uri.Query); + Assert.IsTrue(query.ToList().Count == 1); } [TestMethod] public void DataServiceCollectionSubQueryTrackingItems() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => + this.RunOnAtomAndJsonFormats(CreateContext, DataServiceCollectionSubQueryTrackingItems); + } + + private static void DataServiceCollectionSubQueryTrackingItems( + DataServiceContextWrapper contextWrapper) + { + var query = from p in contextWrapper.Context.Customer + where p.Name != null + select new Customer() { - var query = from p in contextWrapper.Context.Customer - where p.Name != null - select new Customer() - { - Name = p.Name, - Orders = new DataServiceCollection( - from r in p.Orders - select new Order() - { - OrderId = r.OrderId, - CustomerId = r.CustomerId - }) - }; - var tmpResult0 = query.ToList()[0]; - DataServiceCollection collection = tmpResult0.Orders; // the collection tracking items - int tmpCount = collection.Count; - collection.Load(contextWrapper.Context.Execute(collection.Continuation)); // for testing newly loaded item's tracking - Assert.IsTrue(collection.Count > tmpCount, "Should have loaded another page."); - bool someItemNotTracked = false; - tmpResult0.Orders.ToList().ForEach(s => - { - EntityStates state = contextWrapper.Context.GetEntityDescriptor(s).State; - s.CustomerId = s.CustomerId + 1; - state = contextWrapper.Context.GetEntityDescriptor(s).State; - someItemNotTracked = (state == EntityStates.Unchanged) || someItemNotTracked; - }); - Assert.IsFalse(someItemNotTracked, "All items should have been tracked."); - }); + Name = p.Name, + Orders = new DataServiceCollection( + from r in p.Orders + select new Order() + { + OrderId = r.OrderId, + CustomerId = r.CustomerId + }) + }; + var tmpResult0 = query.ToList()[0]; + DataServiceCollection collection = tmpResult0.Orders; // the collection tracking items + int tmpCount = collection.Count; + collection.Load(contextWrapper.Context.Execute(collection.Continuation)); + + // for testing newly loaded item's tracking + Assert.IsTrue(collection.Count > tmpCount, "Should have loaded another page."); + bool someItemNotTracked = false; + tmpResult0.Orders.ToList().ForEach(s => + { + EntityStates state = contextWrapper.Context.GetEntityDescriptor(s).State; + s.CustomerId = s.CustomerId + 1; + state = contextWrapper.Context.GetEntityDescriptor(s).State; + someItemNotTracked = (state == EntityStates.Unchanged) || someItemNotTracked; + }); + Assert.IsFalse(someItemNotTracked, "All items should have been tracked."); } [TestMethod] public void DataServiceCollectionTrackingItems() { - this.RunOnAtomAndJsonFormats(this.CreateContext, (contextWrapper) => - { - var query = from p in contextWrapper.Context.Customer - where p.CustomerId > -100000 // try to get many for paging - select new Customer() - { - CustomerId = p.CustomerId, - Name = p.Name - }; - DataServiceCollection collection = new DataServiceCollection(query); // the collection to track items - int tmpCount = collection.Count; - collection.Load(contextWrapper.Context.Execute(collection.Continuation)); // for testing newly loaded item's tracking - Assert.IsTrue(collection.Count > tmpCount, "Should have loaded another page."); - bool someItemNotTracked = false; - collection.ToList().ForEach(s => + this.RunOnAtomAndJsonFormats(CreateContext, DataServiceCollectionTrackingItems); + } + + private static void DataServiceCollectionTrackingItems( + DataServiceContextWrapper contextWrapper) + { + var query = from p in contextWrapper.Context.Customer + where p.CustomerId > -100000 + // try to get many for paging + select new Customer() { - s.Name = "value to test tracking"; - EntityStates state = contextWrapper.Context.GetEntityDescriptor(s).State; - someItemNotTracked = (state == EntityStates.Unchanged) || someItemNotTracked; - }); - Assert.IsFalse(someItemNotTracked, "All items should have been tracked."); + CustomerId = p.CustomerId, + Name = p.Name + }; + DataServiceCollection collection = new DataServiceCollection(query); + + // the collection to track items + int tmpCount = collection.Count; + collection.Load(contextWrapper.Context.Execute(collection.Continuation)); + + // for testing newly loaded item's tracking + Assert.IsTrue(collection.Count > tmpCount, "Should have loaded another page."); + bool someItemNotTracked = false; + collection.ToList().ForEach(s => + { + s.Name = "value to test tracking"; + EntityStates state = contextWrapper.Context.GetEntityDescriptor(s).State; + someItemNotTracked = (state == EntityStates.Unchanged) || someItemNotTracked; }); + Assert.IsFalse(someItemNotTracked, "All items should have been tracked."); } [TestMethod] diff --git a/test/EndToEndTests/Tests/Client/Build.Desktop/PipelineEventsTests/PipelineEventsCrossPlatformAsyncTests.cs b/test/EndToEndTests/Tests/Client/Build.Desktop/PipelineEventsTests/PipelineEventsCrossPlatformAsyncTests.cs index 417c4cd1b7..597fa1cd3a 100644 --- a/test/EndToEndTests/Tests/Client/Build.Desktop/PipelineEventsTests/PipelineEventsCrossPlatformAsyncTests.cs +++ b/test/EndToEndTests/Tests/Client/Build.Desktop/PipelineEventsTests/PipelineEventsCrossPlatformAsyncTests.cs @@ -36,85 +36,84 @@ public PipelineEventsCrossPlatformAsyncTests() [TestMethod] public void QueryEntitySetLinqAsync() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.ResponsePipeline - .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading) - .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart) - .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd) - .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading) - .OnNavigationLinkEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink) - .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized); - - // cover this for Json - if (contextWrapper.Format.ODataFormat == ODataFormat.Atom) - { - contextWrapper.Configurations.ResponsePipeline.OnNavigationLinkStarted(PipelineEventsTestsHelper.ModifyLinkName_ReadingNavigationLink); - } - - DataServiceQuery query = contextWrapper.CreateQuery("Customer"); - - IEnumerable customers = null; - IAsyncResult r = query.BeginExecute( - result => - { - customers = query.EndExecute(result); - }, null); - - while (!r.IsCompleted) - { - Thread.Sleep(1000); - } - - foreach (Customer customer in customers) - { - PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); - } - }); + this.RunOnAtomAndJsonFormats(CreateContext, QueryEntitySetLinqAsync); + } + + private static void QueryEntitySetLinqAsync(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.ResponsePipeline + .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading) + .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart) + .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd) + .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading) + .OnNavigationLinkEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink) + .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized); + + // cover this for Json + if (contextWrapper.Format.ODataFormat == ODataFormat.Atom) + { + contextWrapper.Configurations.ResponsePipeline.OnNavigationLinkStarted( + PipelineEventsTestsHelper.ModifyLinkName_ReadingNavigationLink); + } + + var query = contextWrapper.CreateQuery("Customer"); + + var customers = Enumerable.Empty(); + var r = query.BeginExecute( + result => + { + customers = query.EndExecute(result); + }, null); + + while (!r.IsCompleted) + { + Thread.Sleep(1000); + } + + foreach (Customer customer in customers) + { + PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); + } } [TestMethod] public void QueryEntitySetExecuteAsync() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.ResponsePipeline - .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading) - .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart) - .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd) - .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading) - .OnNavigationLinkEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink) - .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized); - - // cover this for Json - if (contextWrapper.Format.ODataFormat == ODataFormat.Atom) - { - contextWrapper.Configurations.ResponsePipeline.OnNavigationLinkStarted(PipelineEventsTestsHelper.ModifyLinkName_ReadingNavigationLink); - } - - IEnumerable customers = null; - IAsyncResult r = contextWrapper.BeginExecute( - new Uri("Customer", UriKind.Relative), - result => - { - customers = contextWrapper.EndExecute(result); - }, - null); - - while (!r.IsCompleted) - { - Thread.Sleep(1000); - } - - foreach (Customer customer in customers) - { - PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); - } - }); + this.RunOnAtomAndJsonFormats(CreateContext, QueryEntitySetExecuteAsync); + } + + private static void QueryEntitySetExecuteAsync(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.ResponsePipeline + .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading) + .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart) + .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd) + .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading) + .OnNavigationLinkEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink) + .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized); + + // cover this for Json + if (contextWrapper.Format.ODataFormat == ODataFormat.Atom) + { + contextWrapper.Configurations.ResponsePipeline.OnNavigationLinkStarted( + PipelineEventsTestsHelper.ModifyLinkName_ReadingNavigationLink); + } + + IEnumerable customers = null; + IAsyncResult r = contextWrapper.BeginExecute( + new Uri("Customer", UriKind.Relative), + result => { customers = contextWrapper.EndExecute(result); }, + null); + + while (!r.IsCompleted) + { + Thread.Sleep(1000); + } + + foreach (Customer customer in customers) + { + PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); + } } /// @@ -123,97 +122,97 @@ public void QueryEntitySetExecuteAsync() [TestMethod] public void QueryEntityInstanceExecuteAsync() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Context.IgnoreMissingProperties = true; - - contextWrapper.Configurations.ResponsePipeline - .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading) - .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized) - .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized); - - IEnumerable specialEmployees = null; - IAsyncResult r = contextWrapper.BeginExecute( - new Uri("Person(-10)", UriKind.Relative), - result => - { - specialEmployees = contextWrapper.EndExecute(result); - }, - null); - - while (!r.IsCompleted) - { - Thread.Sleep(1000); - } - - SpecialEmployee specialEmployee = specialEmployees.Single(); - Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate, "Unexpected CarsLicensePlate"); - Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel"); - }); + this.RunOnAtomAndJsonFormats(CreateContext, QueryEntityInstanceExecuteAsync); + } + + private static void QueryEntityInstanceExecuteAsync(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Context.IgnoreMissingProperties = true; + + contextWrapper.Configurations.ResponsePipeline + .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading) + .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized) + .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized); + + IEnumerable specialEmployees = null; + IAsyncResult r = contextWrapper.BeginExecute( + new Uri("Person(-10)", UriKind.Relative), + result => { specialEmployees = contextWrapper.EndExecute(result); }, + null); + + while (!r.IsCompleted) + { + Thread.Sleep(1000); + } + + SpecialEmployee specialEmployee = specialEmployees.Single(); + Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate, + "Unexpected CarsLicensePlate"); + Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel"); } [TestMethod] public void QueryEntityInstanceBatchAsync() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => + this.RunOnAtomAndJsonFormats(CreateContext, QueryEntityInstanceBatchAsync); + } + + private static void QueryEntityInstanceBatchAsync(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Context.IgnoreMissingProperties = true; + + contextWrapper.Configurations.ResponsePipeline + .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading) + .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized) + .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized); + + DataServiceRequest[] requests = new DataServiceRequest[] + { + contextWrapper.CreateQuery("Person(-10)"), + contextWrapper.CreateQuery("Customer"), + }; + + DataServiceResponse responses = null; + IAsyncResult r = contextWrapper.BeginExecuteBatch( + result => { responses = contextWrapper.EndExecuteBatch(result); }, + null, + requests); + + while (!r.IsCompleted) + { + Thread.Sleep(1000); + } + + bool personVerified = false; + bool customerVerified = false; + foreach (QueryOperationResponse response in responses) + { + foreach (object p in response) { - contextWrapper.Context.IgnoreMissingProperties = true; - - contextWrapper.Configurations.ResponsePipeline - .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading) - .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized) - .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized); - - DataServiceRequest[] requests = new DataServiceRequest[] { - contextWrapper.CreateQuery("Person(-10)"), - contextWrapper.CreateQuery("Customer"), - }; - - DataServiceResponse responses = null; - IAsyncResult r = contextWrapper.BeginExecuteBatch( - result => - { - responses = contextWrapper.EndExecuteBatch(result); - }, - null, - requests); - - while (!r.IsCompleted) + SpecialEmployee se1 = p as SpecialEmployee; + Customer c = p as Customer; + if (se1 != null) { - Thread.Sleep(1000); + Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", se1.CarsLicensePlate, + "Unexpected CarsLicensePlate"); + Assert.AreEqual(1, se1.BonusLevel, "Unexpected BonusLevel"); + personVerified = true; } - bool personVerified = false; - bool customerVerified = false; - foreach (QueryOperationResponse response in responses) + if (c != null) { - foreach (object p in response) - { - SpecialEmployee se1 = p as SpecialEmployee; - Customer c = p as Customer; - if (se1 != null) - { - Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", se1.CarsLicensePlate, "Unexpected CarsLicensePlate"); - Assert.AreEqual(1, se1.BonusLevel, "Unexpected BonusLevel"); - personVerified = true; - } - - if (c != null) - { - Assert.IsTrue(c.Name.EndsWith("ModifyPropertyValueCustomerEntity_Materialized"), "Unexpected primitive property"); - Assert.IsTrue(c.Auditing.ModifiedBy.Equals("ModifyPropertyValueCustomerEntity_Materialized"), "Unexpected complex property"); - Assert.IsTrue(c.PrimaryContactInfo.EmailBag.Contains("ModifyPropertyValueCustomerEntity_Materialized"), "Unexpected collection property"); - customerVerified = true; - } - } + Assert.IsTrue(c.Name.EndsWith("ModifyPropertyValueCustomerEntity_Materialized"), + "Unexpected primitive property"); + Assert.IsTrue(c.Auditing.ModifiedBy.Equals("ModifyPropertyValueCustomerEntity_Materialized"), + "Unexpected complex property"); + Assert.IsTrue(c.PrimaryContactInfo.EmailBag.Contains("ModifyPropertyValueCustomerEntity_Materialized"), + "Unexpected collection property"); + customerVerified = true; } + } + } - Assert.IsTrue(personVerified && customerVerified, "Some inner request does not completed correctly"); - }); + Assert.IsTrue(personVerified && customerVerified, "Some inner request does not completed correctly"); } /// @@ -412,109 +411,97 @@ public void UpdateObjectTestAction(ODataFormat format, MergeOption mergeOption, [TestMethod] public void AddObjectSetLinkTestAsync() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - // These delegates are invoked when the client sends a single request for AddObject+SetLink - contextWrapper.Configurations.RequestPipeline - .OnNavigationLinkStarting(PipelineEventsTestsHelper.ModifyNavigationLink_WritingStart) - .OnNavigationLinkEnding(PipelineEventsTestsHelper.ModifyNavigationLink_WritingEnd) - .OnEntityReferenceLink(PipelineEventsTestsHelper.ModifyReferenceLink); - - Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(1300); - Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(1301); - Customer customer3 = PipelineEventsTestsHelper.CreateNewCustomer(1302); - Customer customer4 = PipelineEventsTestsHelper.CreateNewCustomer(1303); - contextWrapper.AddObject("Customer", customer); - contextWrapper.AddObject("Customer", customer2); - contextWrapper.AddObject("Customer", customer3); - contextWrapper.AddObject("Customer", customer4); - - IAsyncResult r1 = contextWrapper.BeginSaveChanges( - result => - { - contextWrapper.EndSaveChanges(result); - }, - null); - - while (!r1.IsCompleted) - { - Thread.Sleep(1000); - } - - Order order = PipelineEventsTestsHelper.CreateNewOrder(1300); - contextWrapper.AddObject("Order", order); - contextWrapper.SetLink(order, "Customer", customer); - - IAsyncResult r2 = contextWrapper.BeginSaveChanges( - result => - { - contextWrapper.EndSaveChanges(result); - }, - null); - - while (!r2.IsCompleted) - { - Thread.Sleep(1000); - } - - Assert.AreEqual(1300, order.OrderId, "OrderId should not be altered in the pipeline delegates"); - - Customer relatedCustomer = null; - IAsyncResult r3 = contextWrapper.BeginExecute( - new Uri("Order(1300)/Customer", UriKind.Relative), - result => - { - relatedCustomer = contextWrapper.EndExecute(result).Single(); - }, - null); - - while (!r3.IsCompleted) - { - Thread.Sleep(1000); - } - - Assert.AreEqual(1302, relatedCustomer.CustomerId, "Associated CustomerId should be altered in the pipeline delegates"); - - contextWrapper.DeleteObject(customer); - contextWrapper.DeleteObject(customer2); - contextWrapper.DeleteObject(customer3); - contextWrapper.DeleteObject(customer4); - contextWrapper.DeleteObject(order); - IAsyncResult r4 = contextWrapper.BeginSaveChanges( - result => - { - contextWrapper.EndSaveChanges(result); - }, - null); - - while (!r4.IsCompleted) - { - Thread.Sleep(1000); - } - }); + this.RunOnAtomAndJsonFormats(CreateContext, AddObjectSetLinkTestAsync); + } + + private static void AddObjectSetLinkTestAsync(DataServiceContextWrapper contextWrapper) + { + // These delegates are invoked when the client sends a single request for AddObject+SetLink + contextWrapper.Configurations.RequestPipeline + .OnNavigationLinkStarting(PipelineEventsTestsHelper.ModifyNavigationLink_WritingStart) + .OnNavigationLinkEnding(PipelineEventsTestsHelper.ModifyNavigationLink_WritingEnd) + .OnEntityReferenceLink(PipelineEventsTestsHelper.ModifyReferenceLink); + + Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(1300); + Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(1301); + Customer customer3 = PipelineEventsTestsHelper.CreateNewCustomer(1302); + Customer customer4 = PipelineEventsTestsHelper.CreateNewCustomer(1303); + contextWrapper.AddObject("Customer", customer); + contextWrapper.AddObject("Customer", customer2); + contextWrapper.AddObject("Customer", customer3); + contextWrapper.AddObject("Customer", customer4); + + IAsyncResult r1 = contextWrapper.BeginSaveChanges( + result => { contextWrapper.EndSaveChanges(result); }, + null); + + while (!r1.IsCompleted) + { + Thread.Sleep(1000); + } + + Order order = PipelineEventsTestsHelper.CreateNewOrder(1300); + contextWrapper.AddObject("Order", order); + contextWrapper.SetLink(order, "Customer", customer); + + IAsyncResult r2 = contextWrapper.BeginSaveChanges( + result => { contextWrapper.EndSaveChanges(result); }, + null); + + while (!r2.IsCompleted) + { + Thread.Sleep(1000); + } + + Assert.AreEqual(1300, order.OrderId, "OrderId should not be altered in the pipeline delegates"); + + Customer relatedCustomer = null; + IAsyncResult r3 = contextWrapper.BeginExecute( + new Uri("Order(1300)/Customer", UriKind.Relative), + result => { relatedCustomer = contextWrapper.EndExecute(result).Single(); }, + null); + + while (!r3.IsCompleted) + { + Thread.Sleep(1000); + } + + Assert.AreEqual(1302, relatedCustomer.CustomerId, + "Associated CustomerId should be altered in the pipeline delegates"); + + contextWrapper.DeleteObject(customer); + contextWrapper.DeleteObject(customer2); + contextWrapper.DeleteObject(customer3); + contextWrapper.DeleteObject(customer4); + contextWrapper.DeleteObject(order); + IAsyncResult r4 = contextWrapper.BeginSaveChanges( + result => { contextWrapper.EndSaveChanges(result); }, + null); + + while (!r4.IsCompleted) + { + Thread.Sleep(1000); + } } [TestMethod] public void CancelRequestTest() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.RequestPipeline - .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing) - .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing); + this.RunOnAtomAndJsonFormats(CreateContext, CancelRequestTest); + } + private static void CancelRequestTest(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.RequestPipeline + .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing) + .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing); - Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(); - contextWrapper.AddObject("Customer", customer); + Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(); + contextWrapper.AddObject("Customer", customer); - IAsyncResult result = contextWrapper.BeginSaveChanges(null, null); - contextWrapper.CancelRequest(result); + IAsyncResult result = contextWrapper.BeginSaveChanges(null, null); + contextWrapper.CancelRequest(result); - Assert.IsTrue(customer.Name.EndsWith("ModifyPropertyValueCustomerEntity_Writing"), "Unexpected primitive property"); - }); + Assert.IsTrue(customer.Name.EndsWith("ModifyPropertyValueCustomerEntity_Writing"), "Unexpected primitive property"); } private DataServiceContextWrapper CreateContext() diff --git a/test/EndToEndTests/Tests/Client/Build.Desktop/PipelineEventsTests/PipelineEventsTests.cs b/test/EndToEndTests/Tests/Client/Build.Desktop/PipelineEventsTests/PipelineEventsTests.cs index 73e52d33a5..d43dedd9a8 100644 --- a/test/EndToEndTests/Tests/Client/Build.Desktop/PipelineEventsTests/PipelineEventsTests.cs +++ b/test/EndToEndTests/Tests/Client/Build.Desktop/PipelineEventsTests/PipelineEventsTests.cs @@ -34,43 +34,44 @@ public PipelineEventsTests() [TestMethod] public void QueryEntitySet() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.ResponsePipeline - .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading) - .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart) - .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd) - .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading) - .OnNavigationLinkEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink) - .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized); - - // cover this for Json - if (contextWrapper.Format.ODataFormat == ODataFormat.Atom) - { - contextWrapper.Configurations.ResponsePipeline.OnNavigationLinkStarted(PipelineEventsTestsHelper.ModifyLinkName_ReadingNavigationLink); - } - - var entryResultsLinq = contextWrapper.CreateQuery("Customer").ToArray(); - foreach (var customer in entryResultsLinq) - { - PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); - } - - var entryResultsExecute = contextWrapper.Execute(new Uri("Customer", UriKind.Relative)); - foreach (Customer customer in entryResultsExecute) - { - PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); - } - - var customerQuery = contextWrapper.CreateQuery("Customer"); - DataServiceCollection entryResultsCollection = new DataServiceCollection(customerQuery); - foreach (Customer customer in entryResultsCollection) - { - PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); - } - }); + this.RunOnAtomAndJsonFormats(CreateContext, QueryEntitySet); + } + + private static void QueryEntitySet(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.ResponsePipeline + .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryId_Reading) + .OnEntryStarted(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingStart) + .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryEditLink_ReadingEnd) + .OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryAction_Reading) + .OnNavigationLinkEnded(PipelineEventsTestsHelper.ModifyAssociationLinkUrl_ReadingNavigationLink) + .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomer_Materialized); + + // cover this for Json + if (contextWrapper.Format.ODataFormat == ODataFormat.Atom) + { + contextWrapper.Configurations.ResponsePipeline.OnNavigationLinkStarted( + PipelineEventsTestsHelper.ModifyLinkName_ReadingNavigationLink); + } + + var entryResultsLinq = contextWrapper.CreateQuery("Customer").ToArray(); + foreach (var customer in entryResultsLinq) + { + PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); + } + + var entryResultsExecute = contextWrapper.Execute(new Uri("Customer", UriKind.Relative)); + foreach (Customer customer in entryResultsExecute) + { + PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); + } + + var customerQuery = contextWrapper.CreateQuery("Customer"); + DataServiceCollection entryResultsCollection = new DataServiceCollection(customerQuery); + foreach (Customer customer in entryResultsCollection) + { + PipelineEventsTestsHelper.VerifyModfiedCustomerEntry(contextWrapper, customer); + } } /// @@ -79,19 +80,19 @@ public void QueryEntitySet() [TestMethod] public void QueryEntitySetNull() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.ResponsePipeline - .OnEntryEnded(PipelineEventsTestsHelper.ChangeEntryPropertyToNull_Reading); - - var entryResultsExecute = contextWrapper.Execute(new Uri("Customer", UriKind.Relative)); - foreach (Customer customer in entryResultsExecute) - { - Assert.IsNull(customer.Auditing, "Unexpected property value"); - } - }); + this.RunOnAtomAndJsonFormats(CreateContext, QueryEntitySetNull); + } + + private static void QueryEntitySetNull(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.ResponsePipeline + .OnEntryEnded(PipelineEventsTestsHelper.ChangeEntryPropertyToNull_Reading); + + var entryResultsExecute = contextWrapper.Execute(new Uri("Customer", UriKind.Relative)); + foreach (Customer customer in entryResultsExecute) + { + Assert.IsNull(customer.Auditing, "Unexpected property value"); + } } /// @@ -100,59 +101,67 @@ public void QueryEntitySetNull() [TestMethod] public void QueryEntityInstance() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Context.IgnoreMissingProperties = true; - - contextWrapper.Configurations.ResponsePipeline - .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading) - .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized) - .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized); - - var specialEmployee = contextWrapper.CreateQuery("Person").Where(p => p.PersonId == -10).Single() as SpecialEmployee; - EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(specialEmployee); - Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate, "Unexpected CarsLicensePlate"); - Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel"); - - specialEmployee = contextWrapper.Execute(new Uri("Person(-10)", UriKind.Relative)).Single(); - Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate, "Unexpected CarsLicensePlate"); - Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel"); - - DataServiceRequest[] requests = new DataServiceRequest[] { - contextWrapper.CreateQuery("Person"), - contextWrapper.CreateQuery("Customer"), - }; - - DataServiceResponse responses = contextWrapper.ExecuteBatch(requests); - bool personVerified = false; - bool customerVerified = false; - foreach (QueryOperationResponse response in responses) + this.RunOnAtomAndJsonFormats(CreateContext, QueryEntityInstance); + } + + private static void QueryEntityInstance(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Context.IgnoreMissingProperties = true; + + contextWrapper.Configurations.ResponsePipeline + .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading) + .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized) + .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized); + + var specialEmployee = + contextWrapper.CreateQuery("Person").Where(p => p.PersonId == -10).Single() as SpecialEmployee; + EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(specialEmployee); + Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate, + "Unexpected CarsLicensePlate"); + Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel"); + + specialEmployee = contextWrapper.Execute(new Uri("Person(-10)", UriKind.Relative)).Single(); + Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate, + "Unexpected CarsLicensePlate"); + Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel"); + + DataServiceRequest[] requests = new DataServiceRequest[] + { + contextWrapper.CreateQuery("Person"), + contextWrapper.CreateQuery("Customer"), + }; + + DataServiceResponse responses = contextWrapper.ExecuteBatch(requests); + bool personVerified = false; + bool customerVerified = false; + foreach (QueryOperationResponse response in responses) + { + foreach (object p in response) + { + var specialEmployee1 = p as SpecialEmployee; + Customer c = p as Customer; + if (specialEmployee1 != null) { - foreach (object p in response) - { - var specialEmployee1 = p as SpecialEmployee; - Customer c = p as Customer; - if (specialEmployee1 != null) - { - Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee1.CarsLicensePlate, "Unexpected CarsLicensePlate"); - Assert.AreEqual(1, specialEmployee1.BonusLevel, "Unexpected BonusLevel"); - personVerified = true; - } - - if (c != null) - { - Assert.IsTrue(c.Name.EndsWith("ModifyPropertyValueCustomerEntity_Materialized"), "Unexpected primitive property"); - Assert.IsTrue(c.Auditing.ModifiedBy.Equals("ModifyPropertyValueCustomerEntity_Materialized"), "Unexpected complex property"); - Assert.IsTrue(c.PrimaryContactInfo.EmailBag.Contains("ModifyPropertyValueCustomerEntity_Materialized"), "Unexpected collection property"); - customerVerified = true; - } - } + Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee1.CarsLicensePlate, + "Unexpected CarsLicensePlate"); + Assert.AreEqual(1, specialEmployee1.BonusLevel, "Unexpected BonusLevel"); + personVerified = true; } - Assert.IsTrue(personVerified && customerVerified, "Some inner request does not completed correctly"); - }); + if (c != null) + { + Assert.IsTrue(c.Name.EndsWith("ModifyPropertyValueCustomerEntity_Materialized"), + "Unexpected primitive property"); + Assert.IsTrue(c.Auditing.ModifiedBy.Equals("ModifyPropertyValueCustomerEntity_Materialized"), + "Unexpected complex property"); + Assert.IsTrue(c.PrimaryContactInfo.EmailBag.Contains("ModifyPropertyValueCustomerEntity_Materialized"), + "Unexpected collection property"); + customerVerified = true; + } + } + } + + Assert.IsTrue(personVerified && customerVerified, "Some inner request does not completed correctly"); } /// @@ -237,21 +246,23 @@ protected string ResolveTypeNameFromType(Type clientType) [TestMethod] public void LoadPropertyTest() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Context.IgnoreMissingProperties = true; - SpecialEmployee specialEmployee = contextWrapper.Execute(new Uri("Person(-10)", UriKind.Relative)).Single(); - - contextWrapper.Configurations.ResponsePipeline.OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryId_Reading); - QueryOperationResponse cars = contextWrapper.LoadProperty(specialEmployee, "Car") as QueryOperationResponse; - foreach (Car car in cars) - { - EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(car); - Assert.IsTrue(descriptor.Identity.OriginalString.Contains("ModifyEntryId"), "Wrong Id"); - } - }); + this.RunOnAtomAndJsonFormats(CreateContext, LoadPropertyTest); + } + + private static void LoadPropertyTest(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Context.IgnoreMissingProperties = true; + SpecialEmployee specialEmployee = + contextWrapper.Execute(new Uri("Person(-10)", UriKind.Relative)).Single(); + + contextWrapper.Configurations.ResponsePipeline.OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryId_Reading); + QueryOperationResponse cars = + contextWrapper.LoadProperty(specialEmployee, "Car") as QueryOperationResponse; + foreach (Car car in cars) + { + EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(car); + Assert.IsTrue(descriptor.Identity.OriginalString.Contains("ModifyEntryId"), "Wrong Id"); + } } /// @@ -303,18 +314,20 @@ public void ExpandQueryTest() [TestMethod] public void PagingQueryTest() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.ResponsePipeline - .OnFeedStarted(PipelineEventsTestsHelper.ModifyFeedId_ReadingFeed) - .OnFeedEnded(PipelineEventsTestsHelper.ModifyNextlink_ReadingFeed); - - QueryOperationResponse entryResultsLinq = contextWrapper.CreateQuery("Customer").Execute() as QueryOperationResponse; - entryResultsLinq.ToArray(); - Assert.AreEqual("http://modifyfeedidmodifynextlink/", entryResultsLinq.GetContinuation().NextLinkUri.AbsoluteUri, "Unexpected next link"); - }); + this.RunOnAtomAndJsonFormats(CreateContext, PagingQueryTest); + } + + private static void PagingQueryTest(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.ResponsePipeline + .OnFeedStarted(PipelineEventsTestsHelper.ModifyFeedId_ReadingFeed) + .OnFeedEnded(PipelineEventsTestsHelper.ModifyNextlink_ReadingFeed); + + var entryResultsLinq = + contextWrapper.CreateQuery("Customer").Execute() as QueryOperationResponse; + entryResultsLinq.ToArray(); + Assert.AreEqual("http://modifyfeedidmodifynextlink/", + entryResultsLinq.GetContinuation().NextLinkUri.AbsoluteUri, "Unexpected next link"); } /// @@ -323,18 +336,23 @@ public void PagingQueryTest() [TestMethod] public void ProjectionQueryTest() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.ResponsePipeline - .OnEntryEnded(PipelineEventsTestsHelper.ModifyMessageEntry_Reading) - .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyMessageEntry_Materialized); - Message entryResultsExecute = contextWrapper.Execute(new Uri("Message(FromUsername='1',MessageId=-10)?$select=MessageId,ToUsername,Sender", UriKind.Relative)).Single(); - - Assert.IsNull(entryResultsExecute.ToUsername, "Unexpected ToUsername"); - Assert.AreEqual("ModifyMessageEntry_ReadingModifyMessageEntry_Materialized", entryResultsExecute.Body, "Unexpected Body"); - }); + this.RunOnAtomAndJsonFormats(CreateContext, ProjectionQueryTest); + } + + private static void ProjectionQueryTest(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.ResponsePipeline + .OnEntryEnded(PipelineEventsTestsHelper.ModifyMessageEntry_Reading) + .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyMessageEntry_Materialized); + var entryResultsExecute = + contextWrapper.Execute( + new Uri("Message(FromUsername='1',MessageId=-10)?$select=MessageId,ToUsername,Sender", + UriKind.Relative)) + .Single(); + + Assert.IsNull(entryResultsExecute.ToUsername, "Unexpected ToUsername"); + Assert.AreEqual("ModifyMessageEntry_ReadingModifyMessageEntry_Materialized", entryResultsExecute.Body, + "Unexpected Body"); } /// @@ -441,75 +459,80 @@ public void UpdateObjectTestAction(ODataFormat format, MergeOption mergeOption, [TestMethod] public void AddUpdateObjectStreamTest() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.RequestPipeline - .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCarEntity_Writing) - .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCarEntry_Writing); - - Car car = PipelineEventsTestsHelper.CreateNewCar(); - contextWrapper.AddObject("Car", car); - contextWrapper.SetSaveStream(car, new MemoryStream(new byte[] { 66, 67 }), true, "text/plain", "slug"); - contextWrapper.SetSaveStream(car, "Photo", new MemoryStream(new byte[] { 66 }), true, new DataServiceRequestArgs() { ContentType = "text/plain" }); - contextWrapper.SaveChanges(); - - // when DataServiceResponsePreference.IncludeContent is not set, property modified in OnEntryEnding will not be updated in client - Assert.IsTrue(car.Description.EndsWith("ModifyPropertyValueCarEntity_Writing"), "Unexpected primitive property"); - - contextWrapper.SetSaveStream(car, new MemoryStream(new byte[] { 68, 69 }), true, "text/plain", "slug"); - contextWrapper.SetSaveStream(car, "Video", new MemoryStream(new byte[] { 66 }), true, new DataServiceRequestArgs() { ContentType = "text/plain" }); - car.Description = "update"; - contextWrapper.UpdateObject(car); - contextWrapper.SaveChanges(); - - // when DataServiceResponsePreference.IncludeContent is not set, property modified in OnEntryEnding will not be updated in client - Assert.IsTrue(car.Description.EndsWith("ModifyPropertyValueCarEntity_Writing"), "Unexpected primitive property"); - - contextWrapper.DeleteObject(car); - contextWrapper.SaveChanges(); - }); + this.RunOnAtomAndJsonFormats(CreateContext, AddUpdateObjectStreamTest); + } + + private static void AddUpdateObjectStreamTest(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.RequestPipeline + .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCarEntity_Writing) + .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCarEntry_Writing); + + Car car = PipelineEventsTestsHelper.CreateNewCar(); + contextWrapper.AddObject("Car", car); + contextWrapper.SetSaveStream(car, new MemoryStream(new byte[] {66, 67}), true, "text/plain", "slug"); + contextWrapper.SetSaveStream(car, "Photo", new MemoryStream(new byte[] {66}), true, + new DataServiceRequestArgs() {ContentType = "text/plain"}); + contextWrapper.SaveChanges(); + + // when DataServiceResponsePreference.IncludeContent is not set, property modified in OnEntryEnding will not be updated in client + Assert.IsTrue(car.Description.EndsWith("ModifyPropertyValueCarEntity_Writing"), "Unexpected primitive property"); + + contextWrapper.SetSaveStream(car, new MemoryStream(new byte[] {68, 69}), true, "text/plain", "slug"); + contextWrapper.SetSaveStream(car, "Video", new MemoryStream(new byte[] {66}), true, + new DataServiceRequestArgs() {ContentType = "text/plain"}); + car.Description = "update"; + contextWrapper.UpdateObject(car); + contextWrapper.SaveChanges(); + + // when DataServiceResponsePreference.IncludeContent is not set, property modified in OnEntryEnding will not be updated in client + Assert.IsTrue(car.Description.EndsWith("ModifyPropertyValueCarEntity_Writing"), "Unexpected primitive property"); + + contextWrapper.DeleteObject(car); + contextWrapper.SaveChanges(); } [TestMethod] public void AddUpdateBatchTest() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.RequestPipeline - .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing) - .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing); - - Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(300); - contextWrapper.AddObject("Customer", customer); - - Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(301); - contextWrapper.AddObject("Customer", customer2); - - Order order = PipelineEventsTestsHelper.CreateNewOrder(300); - contextWrapper.AddRelatedObject(customer, "Orders", order); - - contextWrapper.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset); - - if (contextWrapper.Format.ODataFormat == ODataFormat.Atom) - { - Assert.IsTrue(customer.Name.EndsWith("UpdatedODataEntryPropertyValueModifyPropertyValueCustomerEntry_Writing"), "Unexpected primitive property"); - Assert.IsTrue(customer2.Name.EndsWith("UpdatedODataEntryPropertyValueModifyPropertyValueCustomerEntry_Writing"), "Unexpected primitive property"); - } - else - { - Assert.IsTrue(customer.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property"); - Assert.IsTrue(customer2.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property"); - } - - contextWrapper.DeleteObject(customer); - contextWrapper.DeleteObject(customer2); - contextWrapper.DeleteObject(order); - contextWrapper.SaveChanges(); - }); + this.RunOnAtomAndJsonFormats(CreateContext, AddUpdateBatchTest); + } + + private static void AddUpdateBatchTest(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.RequestPipeline + .OnEntryStarting(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Writing) + .OnEntryEnding(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntry_Writing); + + Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(300); + contextWrapper.AddObject("Customer", customer); + + Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(301); + contextWrapper.AddObject("Customer", customer2); + + Order order = PipelineEventsTestsHelper.CreateNewOrder(300); + contextWrapper.AddRelatedObject(customer, "Orders", order); + + contextWrapper.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset); + + if (contextWrapper.Format.ODataFormat == ODataFormat.Atom) + { + Assert.IsTrue(customer.Name.EndsWith("UpdatedODataEntryPropertyValueModifyPropertyValueCustomerEntry_Writing"), + "Unexpected primitive property"); + Assert.IsTrue( + customer2.Name.EndsWith("UpdatedODataEntryPropertyValueModifyPropertyValueCustomerEntry_Writing"), + "Unexpected primitive property"); + } + else + { + Assert.IsTrue(customer.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property"); + Assert.IsTrue(customer2.Name.EndsWith("UpdatedODataEntryPropertyValue"), "Unexpected primitive property"); + } + + contextWrapper.DeleteObject(customer); + contextWrapper.DeleteObject(customer2); + contextWrapper.DeleteObject(order); + contextWrapper.SaveChanges(); } /// @@ -518,42 +541,42 @@ public void AddUpdateBatchTest() [TestMethod] public void AddObjectSetLinkTest() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - // These delegates are invoked when the client sends a single request for AddObject+SetLink - contextWrapper.Configurations.RequestPipeline - .OnNavigationLinkStarting(PipelineEventsTestsHelper.ModifyNavigationLink_WritingStart) - .OnNavigationLinkEnding(PipelineEventsTestsHelper.ModifyNavigationLink_WritingEnd) - .OnEntityReferenceLink(PipelineEventsTestsHelper.ModifyReferenceLink); - - Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(400); - Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(401); - Customer customer3 = PipelineEventsTestsHelper.CreateNewCustomer(402); - Customer customer4 = PipelineEventsTestsHelper.CreateNewCustomer(403); - contextWrapper.AddObject("Customer", customer); - contextWrapper.AddObject("Customer", customer2); - contextWrapper.AddObject("Customer", customer3); - contextWrapper.AddObject("Customer", customer4); - contextWrapper.SaveChanges(); - - Order order = PipelineEventsTestsHelper.CreateNewOrder(400); - contextWrapper.AddObject("Order", order); - contextWrapper.SetLink(order, "Customer", customer); - contextWrapper.SaveChanges(); - - Assert.AreEqual(400, order.OrderId, "OrderId should not be altered in the pipeline delegates"); - Customer relatedCustomer = contextWrapper.Execute(new Uri("Order(400)/Customer", UriKind.Relative)).Single(); - Assert.AreEqual(402, relatedCustomer.CustomerId, "Associated CustomerId should be altered in the pipeline delegates"); - - contextWrapper.DeleteObject(customer); - contextWrapper.DeleteObject(customer2); - contextWrapper.DeleteObject(customer3); - contextWrapper.DeleteObject(customer4); - contextWrapper.DeleteObject(order); - contextWrapper.SaveChanges(); - }); + this.RunOnAtomAndJsonFormats(CreateContext, AddObjectSetLinkTest); + } + + private static void AddObjectSetLinkTest(DataServiceContextWrapper contextWrapper) + { + // These delegates are invoked when the client sends a single request for AddObject+SetLink + contextWrapper.Configurations.RequestPipeline + .OnNavigationLinkStarting(PipelineEventsTestsHelper.ModifyNavigationLink_WritingStart) + .OnNavigationLinkEnding(PipelineEventsTestsHelper.ModifyNavigationLink_WritingEnd) + .OnEntityReferenceLink(PipelineEventsTestsHelper.ModifyReferenceLink); + + Customer customer = PipelineEventsTestsHelper.CreateNewCustomer(400); + Customer customer2 = PipelineEventsTestsHelper.CreateNewCustomer(401); + Customer customer3 = PipelineEventsTestsHelper.CreateNewCustomer(402); + Customer customer4 = PipelineEventsTestsHelper.CreateNewCustomer(403); + contextWrapper.AddObject("Customer", customer); + contextWrapper.AddObject("Customer", customer2); + contextWrapper.AddObject("Customer", customer3); + contextWrapper.AddObject("Customer", customer4); + contextWrapper.SaveChanges(); + + Order order = PipelineEventsTestsHelper.CreateNewOrder(400); + contextWrapper.AddObject("Order", order); + contextWrapper.SetLink(order, "Customer", customer); + contextWrapper.SaveChanges(); + + Assert.AreEqual(400, order.OrderId, "OrderId should not be altered in the pipeline delegates"); + Customer relatedCustomer = contextWrapper.Execute(new Uri("Order(400)/Customer", UriKind.Relative)).Single(); + Assert.AreEqual(402, relatedCustomer.CustomerId, "Associated CustomerId should be altered in the pipeline delegates"); + + contextWrapper.DeleteObject(customer); + contextWrapper.DeleteObject(customer2); + contextWrapper.DeleteObject(customer3); + contextWrapper.DeleteObject(customer4); + contextWrapper.DeleteObject(order); + contextWrapper.SaveChanges(); } [TestMethod] @@ -627,23 +650,23 @@ public void ErrorResponseTest() [TestMethod] public void ExpandNullEntry() { - this.RunOnAtomAndJsonFormats( - this.CreateContext, - (contextWrapper) => - { - contextWrapper.Configurations.ResponsePipeline - .OnEntryStarted(PipelineEventsTestsHelper.ModifyNullableEntryId_Reading) - .OnEntryEnded(PipelineEventsTestsHelper.ModifyNullalbeEntryEditLink_ReadingEnd); - - var entries = contextWrapper.CreateQuery("License").Expand("Driver").Where(c => c.Name == "3").ToArray(); - Assert.IsTrue(entries.Count() == 1, "Wrong count"); - var license = entries[0]; - Assert.IsNull(license.Driver, "Driver is not null"); - - EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(license); - Assert.IsTrue(descriptor.Identity.OriginalString.Contains("ModifyEntryId"), "Wrong Id"); - Assert.IsTrue(descriptor.EditLink.AbsoluteUri.Contains("ModifyEntryEditLink"), "Wrong EditLink"); - }); + this.RunOnAtomAndJsonFormats(CreateContext, ExpandNullEntry); + } + + private static void ExpandNullEntry(DataServiceContextWrapper contextWrapper) + { + contextWrapper.Configurations.ResponsePipeline + .OnEntryStarted(PipelineEventsTestsHelper.ModifyNullableEntryId_Reading) + .OnEntryEnded(PipelineEventsTestsHelper.ModifyNullalbeEntryEditLink_ReadingEnd); + + var entries = contextWrapper.CreateQuery("License").Expand("Driver").Where(c => c.Name == "3").ToArray(); + Assert.IsTrue(entries.Count() == 1, "Wrong count"); + var license = entries[0]; + Assert.IsNull(license.Driver, "Driver is not null"); + + EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(license); + Assert.IsTrue(descriptor.Identity.OriginalString.Contains("ModifyEntryId"), "Wrong Id"); + Assert.IsTrue(descriptor.EditLink.AbsoluteUri.Contains("ModifyEntryEditLink"), "Wrong EditLink"); } private bool OnCustomerFeedStartedCalled = false;