public void AddDepartmentAlreadyInUnitOfWork() { using (FakeEmployeeContext ctx = new FakeEmployeeContext()) { UnitOfWork unit = new UnitOfWork(ctx); Department dep = new Department(); unit.AddDepartment(dep); try { unit.AddDepartment(dep); Assert.Fail("Adding an Department that was already added did not throw."); } catch (InvalidOperationException ex) { Assert.AreEqual("The supplied Department is already part of this Unit of Work.", ex.Message); } } }
public void AddDepartment() { using (FakeEmployeeContext ctx = new FakeEmployeeContext()) { UnitOfWork unit = new UnitOfWork(ctx); Department dep = new Department(); unit.AddDepartment(dep); Assert.IsTrue(ctx.Departments.Contains(dep), "Department was not added to underlying context."); } }
public void RemoveDepartment() { using (FakeEmployeeContext ctx = new FakeEmployeeContext()) { UnitOfWork unit = new UnitOfWork(ctx); Department dep = new Department(); unit.AddDepartment(dep); unit.RemoveDepartment(dep); Assert.IsFalse(ctx.Departments.Contains(dep), "Department was not removed from underlying context."); } }
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"); } }