示例#1
0
        public void EFFK_1To1_BasicInsertAndBind_Batch()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office()
            {
                ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173
            };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker e = new EFFKClient.Worker()
            {
                ID = 1, FirstName = "Pratik", LastName = "Patel"
            };
            ctx.AddObject("CustomObjectContext.Workers", e);

            // Establish relationship between employee and office
            ctx.SetLink(o, "Worker", e);
            ctx.SetLink(e, "Office", o);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            // clean the context
            ctx.DeleteObject(e);
            ctx.DeleteObject(o);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);
        }
示例#2
0
        public void EFFK_1To1_BasicInsertAndBind_Batch_ChangedUriCompositionRulesOnServer()
        {
            // Fix URI composition in Astoria for V3 payloads
            ctx            = new DataServiceContext(web.ServiceRoot, Microsoft.OData.Client.ODataProtocolVersion.V4);
            ctx.EnableAtom = true;
            ctx.Format.UseAtom();
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office()
            {
                ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173
            };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker e = new EFFKClient.Worker()
            {
                ID = 1, FirstName = "Pratik", LastName = "Patel"
            };
            ctx.AddObject("CustomObjectContext.Workers", e);

            // Establish relationship between employee and office
            ctx.SetLink(o, "Worker", e);
            ctx.SetLink(e, "Office", o);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            // clean the context
            ctx.DeleteObject(e);
            ctx.DeleteObject(o);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);
        }
示例#3
0
        public void EFFK_1To1_CascadeDelete_DependentToPrincipal()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office()
            {
                ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173
            };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker w = new EFFKClient.Worker()
            {
                ID = 1, FirstName = "Pratik", LastName = "Patel"
            };
            ctx.AddObject("CustomObjectContext.Workers", w);
            ctx.SaveChanges();

            // setting the link from dependent to principal should delete the dependent
            ctx.SetLink(w, "Office", null);
            ctx.SaveChanges();
            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");

            ctx.DeleteObject(o);
            ctx.SaveChanges();

            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Office>("CustomObjectContext.Offices").Count(), 0, "There should be no offices left");
            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");
        }
示例#4
0
        public void EFFK_1To1_DeleteDependent()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office()
            {
                ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173
            };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker w = new EFFKClient.Worker()
            {
                ID = 1, FirstName = "Pratik", LastName = "Patel"
            };
            ctx.AddObject("CustomObjectContext.Workers", w);
            ctx.SaveChanges();

            // Deleting the dependent should work
            ctx.DeleteObject(w);
            ctx.SaveChanges();

            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Office>("CustomObjectContext.Offices").Count(), 1, "There should be exactly one office instance");
            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");

            // clean the context
            ctx.DeleteObject(o);
            ctx.SaveChanges();

            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Office>("CustomObjectContext.Offices").Count(), 0, "There should be no offices left");
            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");
        }
示例#5
0
        public void EFFK_1To1_BasicInsert_Bind_Delete()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office()
            {
                ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173
            };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker e = new EFFKClient.Worker()
            {
                ID = 1, FirstName = "Pratik", LastName = "Patel"
            };
            ctx.AddObject("CustomObjectContext.Workers", e);
            ctx.SaveChanges();

            // Establish relationship between employee and office again. This operation should be no-op
            ctx.SetLink(o, "Worker", e);
            ctx.SaveChanges();

            ctx.SetLink(e, "Office", o);
            ctx.SaveChanges();

            // clean the tests by deleting the office instance created by this test
            ctx.DeleteObject(e);
            ctx.DeleteObject(o);
            ctx.SaveChanges();

            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");
            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Office>("CustomObjectContext.Offices").Count(), 0, "There should be no offices left");
        }
示例#6
0
        public void EFFK_1To1_UpdateRelationship()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office()
            {
                ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173
            };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker w = new EFFKClient.Worker()
            {
                ID = 1, FirstName = "Pratik", LastName = "Patel"
            };
            ctx.AddObject("CustomObjectContext.Workers", w);
            ctx.SaveChanges();

            EFFKClient.Office o1 = new EFFKClient.Office()
            {
                ID = 2, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2174
            };
            ctx.AddObject("CustomObjectContext.Offices", o1);
            ctx.SaveChanges();

            try
            {
                ctx.SetLink(o1, "Worker", w);
                ctx.SaveChanges();
            }
            catch (DataServiceRequestException ex)
            {
                Assert.AreEqual(ex.Response.First().StatusCode, 400, "Expecting bad request");
                Assert.IsTrue(ex.Response.First().Error.Message.Contains("A referential integrity constraint violation occurred"), "Making sure appropriate EF exception is thrown");
                ctx.DetachLink(o1, "Worker", w); // To clear this operation from the context so that next test doesn't hit the same issue
            }

            try
            {
                ctx.SetLink(w, "Office", o1);
                ctx.SaveChanges();
            }
            catch (DataServiceRequestException ex1)
            {
                Assert.AreEqual(ex1.Response.First().StatusCode, 400, "Expecting bad request");
                Assert.IsTrue(ex1.Response.First().Error.Message.Contains("The principal object must be tracked and not marked for deletion."), "Making sure appropriate EF exception is thrown");
                ctx.DetachLink(w, "Office", o1); // To clear this operation from the context so that next test doesn't hit the same issue
            }

            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Office>("CustomObjectContext.Offices").Count(), 2, "Unexpected number of office instances encountered");
            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 1, "Unexpected number of worker instances encountered");

            ctx.DeleteObject(o);
            ctx.DeleteObject(o1);
            ctx.DeleteObject(w);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);
            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Office>("CustomObjectContext.Offices").Count(), 0, "There should be no offices left");
            Assert.AreEqual(ctx.CreateQuery <EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");
        }
示例#7
0
        public void EFFK_1To1_UpdateRelationship()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office() { ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173 };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker w = new EFFKClient.Worker() { ID = 1, FirstName = "Pratik", LastName = "Patel" };
            ctx.AddObject("CustomObjectContext.Workers", w);
            ctx.SaveChanges();

            EFFKClient.Office o1 = new EFFKClient.Office() { ID = 2, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2174 };
            ctx.AddObject("CustomObjectContext.Offices", o1);
            ctx.SaveChanges();

            try
            {
                ctx.SetLink(o1, "Worker", w);
                ctx.SaveChanges();
            }
            catch (DataServiceRequestException ex)
            {
                Assert.AreEqual(ex.Response.First().StatusCode, 400, "Expecting bad request");
                Assert.IsTrue(ex.Response.First().Error.Message.Contains("A referential integrity constraint violation occurred"), "Making sure appropriate EF exception is thrown");
                ctx.DetachLink(o1, "Worker", w); // To clear this operation from the context so that next test doesn't hit the same issue
            }

            try
            {
                ctx.SetLink(w, "Office", o1);
                ctx.SaveChanges();
            }
            catch (DataServiceRequestException ex1)
            {
                Assert.AreEqual(ex1.Response.First().StatusCode, 400, "Expecting bad request");
                Assert.IsTrue(ex1.Response.First().Error.Message.Contains("The principal object must be tracked and not marked for deletion."), "Making sure appropriate EF exception is thrown");
                ctx.DetachLink(w, "Office", o1); // To clear this operation from the context so that next test doesn't hit the same issue
            }

            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Office>("CustomObjectContext.Offices").Count(), 2, "Unexpected number of office instances encountered");
            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 1, "Unexpected number of worker instances encountered");

            ctx.DeleteObject(o);
            ctx.DeleteObject(o1);
            ctx.DeleteObject(w);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);
            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Office>("CustomObjectContext.Offices").Count(), 0, "There should be no offices left");
            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");
        }
示例#8
0
        public void EFFK_1To1_BasicInsertAndBind_Batch_ChangedUriCompositionRulesOnServer()
        {
            // Fix URI composition in Astoria for V3 payloads
            ctx = new DataServiceContext(web.ServiceRoot, Microsoft.OData.Client.ODataProtocolVersion.V4);
            ctx.EnableAtom = true;
            ctx.Format.UseAtom();
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office() { ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173 };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker e = new EFFKClient.Worker() { ID = 1, FirstName = "Pratik", LastName = "Patel" };
            ctx.AddObject("CustomObjectContext.Workers", e);

            // Establish relationship between employee and office
            ctx.SetLink(o, "Worker", e);
            ctx.SetLink(e, "Office", o);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            // clean the context
            ctx.DeleteObject(e);
            ctx.DeleteObject(o);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);
        }
示例#9
0
        public void EFFK_1To1_BasicInsertAndBind_Batch()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office() { ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173 };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker e = new EFFKClient.Worker() { ID = 1, FirstName = "Pratik", LastName = "Patel" };
            ctx.AddObject("CustomObjectContext.Workers", e);

            // Establish relationship between employee and office
            ctx.SetLink(o, "Worker", e);
            ctx.SetLink(e, "Office", o);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            // clean the context
            ctx.DeleteObject(e);
            ctx.DeleteObject(o);
            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);
        }
示例#10
0
        public void EFFK_1To1_DeleteDependent()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office() { ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173 };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker w = new EFFKClient.Worker() { ID = 1, FirstName = "Pratik", LastName = "Patel" };
            ctx.AddObject("CustomObjectContext.Workers", w);
            ctx.SaveChanges();

            // Deleting the dependent should work
            ctx.DeleteObject(w);
            ctx.SaveChanges();

            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Office>("CustomObjectContext.Offices").Count(), 1, "There should be exactly one office instance");
            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");

            // clean the context
            ctx.DeleteObject(o);
            ctx.SaveChanges();

            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Office>("CustomObjectContext.Offices").Count(), 0, "There should be no offices left");
            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");
        }
示例#11
0
        public void EFFK_1To1_CascadeDelete_DependentToPrincipal()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office() { ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173 };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker w = new EFFKClient.Worker() { ID = 1, FirstName = "Pratik", LastName = "Patel" };
            ctx.AddObject("CustomObjectContext.Workers", w);
            ctx.SaveChanges();

            // setting the link from dependent to principal should delete the dependent
            ctx.SetLink(w, "Office", null);
            ctx.SaveChanges();
            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");

            ctx.DeleteObject(o);
            ctx.SaveChanges();

            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Office>("CustomObjectContext.Offices").Count(), 0, "There should be no offices left");
            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");
        }
示例#12
0
        public void EFFK_1To1_BasicInsert_Bind_Delete()
        {
            // Create new office type
            EFFKClient.Office o = new EFFKClient.Office() { ID = 1, BuildingName = "Building 35", FloorNumber = 2, OfficeNumber = 2173 };
            ctx.AddObject("CustomObjectContext.Offices", o);

            // create new employee type
            EFFKClient.Worker e = new EFFKClient.Worker() { ID = 1, FirstName = "Pratik", LastName = "Patel" };
            ctx.AddObject("CustomObjectContext.Workers", e);
            ctx.SaveChanges();

            // Establish relationship between employee and office again. This operation should be no-op
            ctx.SetLink(o, "Worker", e);
            ctx.SaveChanges();

            ctx.SetLink(e, "Office", o);
            ctx.SaveChanges();

            // clean the tests by deleting the office instance created by this test
            ctx.DeleteObject(e);
            ctx.DeleteObject(o);
            ctx.SaveChanges();

            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Worker>("CustomObjectContext.Workers").Count(), 0, "There should be no workers left");
            Assert.AreEqual(ctx.CreateQuery<EFFKClient.Office>("CustomObjectContext.Offices").Count(), 0, "There should be no offices left");
        }