public static void Main() { // item 233 Bar db = new Bar(); // item 160 Bar.ICompany yellow = db.InsertCompany(0); Bar.ICompany grey = db.InsertCompany(0); // item 161 Bar.IDepartment yellow_m = db.InsertDepartment(0, "Yellow marketing"); Bar.IDepartment grey_m = db.InsertDepartment(0, "Grey marketing"); // item 162 Bar.IEmployee grey_e = db.InsertEmployee(0, "Mark", grey_m); Bar.IEmployee grey_e2 = db.InsertEmployee(0, "John", null); // item 178 ExpectException(() => db.InsertEmployee(0, "Mark", grey_m)); // item 163 var fake = new FakeDepartment { Id = 1000, Title = "Fake" }; ExpectException(() => db.InsertEmployee(0, "Jack", fake)); // item 164 db.SetCompanyMarketing(yellow, yellow_m); db.SetCompanyMarketing(grey, grey_m); // item 165 db.SetEmployeeDepartment(grey_e2, grey_m); // item 169 Equal(yellow_m, db.GetDepartment(yellow_m.Id)); // item 166 ExpectException(() => db.DeleteDepartment(yellow_m)); // item 167 db.DeleteCompany(yellow); // item 168 Equal(null, db.GetDepartment(yellow_m.Id)); Equal(null, db.GetCompany(yellow.Id)); // item 170 ExpectException(() => db.DeleteCompany(grey)); // item 171 db.SetEmployeeDepartment(grey_e, null); // item 172 db.DeleteEmployee(grey_e2); // item 173 db.DeleteCompany(grey); // item 174 Equal(null, db.GetCompany(grey.Id)); Equal(null, db.GetDepartment(grey_m.Id)); }
public static void Main() { // item 159 Bar db = new Bar(); // item 76 Bar.IEmployee john = db.InsertEmployee(0, "John", new DateTime(1978, 1, 1)); Bar.IEmployee mark = db.InsertEmployee(0, "Mark", new DateTime(1978, 1, 1)); Bar.IEmployee john2 = db.InsertEmployee(0, "John", new DateTime(1985, 1, 1)); // item 75 db.InsertDepartment(0, "Marketing"); db.InsertDepartment(0, "Sales"); db.InsertDepartment(0, "Logistics"); Bar.IDepartment marketing = db.FindDepartmentByTitle("Marketing"); Bar.IDepartment sales = db.FindDepartmentByTitle("Sales"); Bar.IDepartment logistics = db.FindDepartmentByTitle("Logistics"); // item 205 Equal(null, john.Department); Equal(null, john2.Department); Equal(null, mark.Department); // item 137 db.SetEmployeeDepartment(john, null); db.SetEmployeeDepartment(john2, null); db.SetEmployeeDepartment(mark, null); // item 136 Equal(null, john.Department); Equal(null, john2.Department); Equal(null, mark.Department); // item 114 var fakeDepartment = new FakeDepartment { Id = 1000, Title = "Fake" }; ExpectException(() => db.SetEmployeeDepartment(john, fakeDepartment) ); // item 138 db.SetEmployeeDepartment(john, marketing); db.SetEmployeeDepartment(john2, sales); db.SetEmployeeDepartment(mark, marketing); // item 139 Equal(marketing, john.Department); Equal(sales, john2.Department); Equal(marketing, mark.Department); // item 141 db.SetEmployeeDepartment(john, marketing); db.SetEmployeeDepartment(john2, logistics); db.SetEmployeeDepartment(mark, null); // item 142 Equal(marketing, john.Department); Equal(logistics, john2.Department); Equal(null, mark.Department); // item 143 db.DeleteDepartment(sales); Equal(null, db.FindDepartmentByTitle("Sales")); // item 144 ExpectException(() => db.DeleteDepartment(marketing)); ExpectException(() => db.DeleteDepartment(logistics)); // item 100 db.DeleteEmployee(john); db.DeleteDepartment(marketing); // item 101 db.SetEmployeeDepartment(john2, null); db.DeleteDepartment(logistics); // item 145 Equal(2, db.EmployeeCount()); Equal(0, db.DepartmentCount()); }