public void entities_should_not_be_deleted_from_storage()
        {
            // using Service API, call Delete on the record
            using (var work = Ignorance.Create.Work())
            {
                var s = new DepartmentService(work);
                var d = s.GetByID(this.TestDepartmentID);
                s.Delete(d);

                // but do NOT call Save on Work.
            }

            // test (using straight EF) that the record still exists.
            using (var db = new AdventureWorksEntities())
            {
                var d = db.Departments.Find(this.TestDepartmentID);
                Assert.IsNotNull(d, "Changes were persisted without Work.Save().");
            }
        }
        public void changes_to_entities_should_not_persist()
        {
            // using Service API, call Update on the record
            using (var work = Ignorance.Create.Work())
            {
                var s = new DepartmentService(work);
                var d = s.GetByID(this.TestDepartmentID);
                d.Name = "Updated";
                s.Update(d);

                // but do NOT call Save on Work.
            }

            // test (using straight EF) that the record still exists.
            using (var db = new AdventureWorksEntities())
            {
                var d = db.Departments.Find(this.TestDepartmentID);
                Assert.AreEqual("Ignorance", d.Name, "Update was persisted without Work.Save().");
            }
        }
        public void added_entities_should_not_persist()
        {
            var guidName = Guid.NewGuid().ToString();
            // using Service API, Add a record
            using (var work = Ignorance.Create.Work())
            {
                var s = new DepartmentService(work);
                var d = s.Create();
                d.Name = guidName;
                s.Add(d);

                // but do NOT call Save on Work.
            }

            // test (using straight EF) that the record still exists.
            using (var db = new AdventureWorksEntities())
            {
                var d = db.Departments.FirstOrDefault(p => p.Name == guidName);
                Assert.IsNull(d, "Add was persisted without Work.Save().");
            }
        }
        public void Service_Update_should_apply_the_changes()
        {
            // change the entity outside a working context
            this.Dept.Name = new_department_name;

            // use Update to re-attach and save the changes
            using (var work = Ignorance.Create.Work())
            {
                var s = new DepartmentService(work);
                s.Update(this.Dept);

                work.Save();
            }

            // verify the changes using EF
            using (var db = new AdventureWorksEntities())
            {
                var d = db.Departments.Find(this.Dept.DepartmentID);
                Assert.AreEqual(new_department_name, d.Name, "Changes from outside of Work were not applied.");
            }
        }
        public void SetUp()
        {
            // create a record using straight EF
            using (var db = new AdventureWorksEntities())
            {
                var d = new Department() {
                     Name = "Ignorance",
                     GroupName = "Information Technology",
                     ModifiedDate = DateTime.Today
                };
                db.Departments.Add(d);
                db.SaveChanges();

                this.TestDepartmentID = d.DepartmentID;
            }
        }
 public void TearDown()
 {
     // delete the test record using straight EF
     using (var db = new AdventureWorksEntities())
     {
         var d = db.Departments.Find(this.TestDepartmentID);
         db.Departments.Remove(d);
         db.SaveChanges();
     }
 }