public void RemoveEmployeeWithReports()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                Employee   emp  = new Employee();
                Employee   man  = new Employee();
                unit.AddEmployee(emp);
                unit.AddEmployee(man);
                emp.Manager = man;

                unit.RemoveEmployee(man);
                Assert.IsFalse(ctx.Employees.Contains(man), "Employee was not removed from underlying context.");
                Assert.AreEqual(0, man.Reports.Count, "Employee was not removed from managers reports.");
                Assert.IsNull(emp.Manager, "Manager property on Employee was not cleared.");
            }
        }
        public void AddEmployeeAlreadyInUnitOfWork()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);

                Employee emp = new Employee();
                unit.AddEmployee(emp);

                try
                {
                    unit.AddEmployee(emp);
                    Assert.Fail("Adding an Employee that was already added did not throw.");
                }
                catch (InvalidOperationException ex)
                {
                    Assert.AreEqual("The supplied Employee is already part of this Unit of Work.", ex.Message);
                }
            }
        }
        public void AddEmployee()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);

                Employee emp = new Employee();
                unit.AddEmployee(emp);
                Assert.IsTrue(ctx.Employees.Contains(emp), "Employee was not added to underlying context.");
            }
        }
        public void RemoveEmployee()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                Employee   emp  = new Employee();
                unit.AddEmployee(emp);

                unit.RemoveEmployee(emp);
                Assert.IsFalse(ctx.Employees.Contains(emp), "Employee was not removed from underlying context.");
            }
        }
Exemple #5
0
        public void AddContactDetailFromDefaultConstructor()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                Employee emp = new Employee();
                unit.AddEmployee(emp);

                ContactDetail cd = new Address();
                unit.AddContactDetail(emp, cd);
                Assert.IsTrue(ctx.ContactDetails.Contains(cd), "ContactDetail was not added to underlying context.");
            }
        }
        public void AddContactDetailFromDefaultConstructor()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                Employee   emp  = new Employee();
                unit.AddEmployee(emp);

                ContactDetail cd = new Address();
                unit.AddContactDetail(emp, cd);
                Assert.IsTrue(ctx.ContactDetails.Contains(cd), "ContactDetail was not added to underlying context.");
            }
        }
        public void RemoveContactDetail()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);

                Employee      emp    = new Employee();
                ContactDetail detail = new Phone();
                unit.AddEmployee(emp);
                unit.AddContactDetail(emp, detail);

                unit.RemoveContactDetail(emp, detail);
                Assert.IsFalse(ctx.ContactDetails.Contains(detail), "ContactDetail was not removed from underlying context.");
                Assert.IsFalse(
                    emp.ContactDetails.Contains(detail),
                    "ContactDetail is still in collection on Employee after being removed via Unit of Work.");
            }
        }
        public void RemoveDepartmentWithEmployees()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                Department dep  = new Department();
                Employee   emp  = new Employee();
                unit.AddDepartment(dep);
                unit.AddEmployee(emp);
                emp.Department = dep;

                unit.RemoveDepartment(dep);
                Assert.IsFalse(ctx.Departments.Contains(dep), "Department was not removed from underlying context.");
                Assert.IsNull(emp.Department, "Employee.Department property has not been nulled when deleting department.");
                Assert.IsNull(emp.DepartmentId, "Employee.DepartmentId property has not been nulled when deleting department.");
                Assert.AreEqual(0, dep.Employees.Count, "Department.Employees collection was not cleared when deleting department.");
            }
        }
        public void NullArgumentChecks()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);

                Utilities.CheckNullArgumentException(() => { new UnitOfWork(null); }, "context", "ctor");

                Utilities.CheckNullArgumentException(() => { unit.AddEmployee(null); }, "employee", "AddEmployee");
                Utilities.CheckNullArgumentException(() => { unit.AddDepartment(null); }, "department", "AddDepartment");
                Utilities.CheckNullArgumentException(() => { unit.AddContactDetail(new Employee(), null); }, "detail", "AddContactDetail");
                Utilities.CheckNullArgumentException(() => { unit.AddContactDetail(null, new Phone()); }, "employee", "AddContactDetail");

                Utilities.CheckNullArgumentException(() => { unit.RemoveEmployee(null); }, "employee", "RemoveEmployee");
                Utilities.CheckNullArgumentException(() => { unit.RemoveDepartment(null); }, "department", "RemoveDepartment");
                Utilities.CheckNullArgumentException(() => { unit.RemoveContactDetail(null, new Phone()); }, "employee", "RemoveContactDetail");
                Utilities.CheckNullArgumentException(() => { unit.RemoveContactDetail(new Employee(), null); }, "detail", "RemoveContactDetail");
            }
        }
Exemple #10
0
        public void AddContactDetailAlreadyInUnitOfWork()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);

                Employee emp = new Employee();
                ContactDetail detail = new Phone();
                unit.AddEmployee(emp);
                unit.AddContactDetail(emp, detail);

                try
                {
                    unit.AddContactDetail(emp, detail);
                    Assert.Fail("Adding an ContactDetail that was already added did not throw.");
                }
                catch (InvalidOperationException ex)
                {
                    Assert.AreEqual("The supplied Phone is already part of this Unit of Work.", ex.Message);
                }
            }
        }
Exemple #11
0
        public void RemoveEmployeeWithReports()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                Employee emp = new Employee();
                Employee man = new Employee();
                unit.AddEmployee(emp);
                unit.AddEmployee(man);
                emp.Manager = man;

                unit.RemoveEmployee(man);
                Assert.IsFalse(ctx.Employees.Contains(man), "Employee was not removed from underlying context.");
                Assert.AreEqual(0, man.Reports.Count, "Employee was not removed from managers reports.");
                Assert.IsNull(emp.Manager, "Manager property on Employee was not cleared.");
            }
        }
Exemple #12
0
        public void RemoveEmployee()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                Employee emp = new Employee();
                unit.AddEmployee(emp);

                unit.RemoveEmployee(emp);
                Assert.IsFalse(ctx.Employees.Contains(emp), "Employee was not removed from underlying context.");
            }
        }
Exemple #13
0
        public void RemoveDepartmentWithEmployees()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                Department dep = new Department();
                Employee emp = new Employee();
                unit.AddDepartment(dep);
                unit.AddEmployee(emp);
                emp.Department = dep;

                unit.RemoveDepartment(dep);
                Assert.IsFalse(ctx.Departments.Contains(dep), "Department was not removed from underlying context.");
                Assert.IsNull(emp.Department, "Employee.Department property has not been nulled when deleting department.");
                Assert.IsNull(emp.DepartmentId, "Employee.DepartmentId property has not been nulled when deleting department.");
                Assert.AreEqual(0, dep.Employees.Count, "Department.Employees collection was not cleared when deleting department.");
            }
        }
Exemple #14
0
        public void RemoveContactDetail()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);

                Employee emp = new Employee();
                ContactDetail detail = new Phone();
                unit.AddEmployee(emp);
                unit.AddContactDetail(emp, detail);

                unit.RemoveContactDetail(emp, detail);
                Assert.IsFalse(ctx.ContactDetails.Contains(detail), "ContactDetail was not removed from underlying context.");
                Assert.IsFalse(
                    emp.ContactDetails.Contains(detail),
                    "ContactDetail is still in collection on Employee after being removed via Unit of Work.");
            }
        }
Exemple #15
0
        public void NullArgumentChecks()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);

                Utilities.CheckNullArgumentException(() => { new UnitOfWork(null); }, "context", "ctor");

                Utilities.CheckNullArgumentException(() => { unit.AddEmployee(null); }, "employee", "AddEmployee");
                Utilities.CheckNullArgumentException(() => { unit.AddDepartment(null); }, "department", "AddDepartment");
                Utilities.CheckNullArgumentException(() => { unit.AddContactDetail(new Employee(), null); }, "detail", "AddContactDetail");
                Utilities.CheckNullArgumentException(() => { unit.AddContactDetail(null, new Phone()); }, "employee", "AddContactDetail");

                Utilities.CheckNullArgumentException(() => { unit.RemoveEmployee(null); }, "employee", "RemoveEmployee");
                Utilities.CheckNullArgumentException(() => { unit.RemoveDepartment(null); }, "department", "RemoveDepartment");
                Utilities.CheckNullArgumentException(() => { unit.RemoveContactDetail(null, new Phone()); }, "employee", "RemoveContactDetail");
                Utilities.CheckNullArgumentException(() => { unit.RemoveContactDetail(new Employee(), null); }, "detail", "RemoveContactDetail");
            }
        }
Exemple #16
0
        public void AddEmployee()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);

                Employee emp = new Employee();
                unit.AddEmployee(emp);
                Assert.IsTrue(ctx.Employees.Contains(emp), "Employee was not added to underlying context.");
            }
        }