public void UpdateEntityTest_ETag() { IQDSP.Customer c = this.CreateCustomer(); context.MergeOption = MergeOption.OverwriteChanges; context.AddObject("Customers", c); context.SaveChanges(); var outdatedContext = new DataServiceContext(context.BaseUri); IQDSP.Customer outdatedSupplier = outdatedContext.CreateQuery <IQDSP.Customer>("Customers").Where(_c => _c.CustomerID == c.CustomerID).FirstOrDefault(); c.CompanyName = "something else"; context.UpdateObject(c); context.SaveChanges(); context.UpdateObject(c); context.SaveChanges(); c = context.CreateQuery <IQDSP.Customer>("Customers").Where(_c => _c.CustomerID == c.CustomerID).FirstOrDefault(); Assert.AreEqual("something else", c.CompanyName); outdatedContext.UpdateObject(outdatedSupplier); try { outdatedContext.SaveChanges(); Assert.Fail("Concurrency failed to throw"); } catch (DataServiceRequestException ex) { Assert.IsTrue(ex.InnerException.Message.Contains("Concurrency: precondition failed for property 'CompanyName'")); } }
public void UpdateEntity_Validate_StringLength() { context.MergeOption = MergeOption.OverwriteChanges; IQDSP.Customer cust = context.CreateQuery <IQDSP.Customer>("Customers").FirstOrDefault(); cust.City = "Alfreds Futterkiste Town"; context.UpdateObject(cust); try { context.SaveChanges(); Assert.Fail("ValidationContext StringLength 'City' failed to throw"); } catch (DataServiceRequestException ex) { Assert.IsTrue(ex.InnerException.Message.Contains("maximum length exceed")); } }
public void UpdateEntity_Validate() { context.MergeOption = MergeOption.OverwriteChanges; IQDSP.Customer cust = context.CreateQuery <IQDSP.Customer>("Customers").FirstOrDefault(); cust.CompanyName = string.Empty; context.UpdateObject(cust); try { context.SaveChanges(); Assert.Fail("ValidationContext RequiredAttribute 'CompanyName' failed to throw"); } catch (DataServiceRequestException ex) { Assert.IsTrue(ex.InnerException.Message.Contains("CompanyName is a required field.")); } }
public void DeleteConditional_EntityTest() { IQDSP.Customer c = this.CreateCustomer(); context.MergeOption = MergeOption.OverwriteChanges; context.AddObject("Customers", c); context.SaveChanges(); int precount = context.CreateQuery <IQDSP.Customer>("Customers").ToList().Count(); IQDSP.Customer customer = RunQuery <IQDSP.Customer>("/Customers()?$filter=(CompanyName eq 'Alfreds Futterkiste US') and (City eq 'New York')").FirstOrDefault(); Assert.AreEqual("ALFUS", customer.CustomerID); context.DeleteObject(customer); context.SaveChanges(); int postcount = context.CreateQuery <IQDSP.Customer>("Customers").ToList().Count(); Assert.AreEqual(precount, postcount, "Product count pre: " + precount.ToString() + " post: " + postcount.ToString() + " did not match."); }