Esempio n. 1
0
        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'"));
            }
        }
Esempio n. 2
0
        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"));
            }
        }
Esempio n. 3
0
        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."));
            }
        }