public void AddAStatus() { int beforeCount = _db.Statuses.Count(); var status = new Status { StatusName = "Waiting for Supervisor Approval" }; _db.Statuses.Add(status); _db.SaveChanges(); Assert.Equal(beforeCount + 1, _db.Statuses.Count()); }
public void AddDepartment() { var department = new Department { DepartmentName = "Wood Chucks", Active = true, DivisionId = _db.Divisions.First().Id }; _db.Departments.Add(department); _db.SaveChanges(); Assert.Equal(9, _db.Departments.Count()); }
public void AddEmployee() { var count = _db.Employees.Count(); _db.Employees.Add(new Employee { FirstName = "Bob", LastName = "Bobnby", Active = true }); _db.SaveChanges(); Assert.Equal(count + 1, _db.Employees.Count()); }
public void Case01() { Campus MainCampus = new Campus { CampusName = "WVUP Main Campus", Address = new Address { StreetAddress = "300 Campus Dr.", City = "Parkersburg", State = "WV", Zip = "25550" } }; _db.Campuses.Add(MainCampus); _db.SaveChanges(); int id = _db.Campuses.Where(x => x.CampusName == "Main Campus").ToList().First().Id; Assert.Equal("Main Campus", _db.Campuses.Find(id).CampusName); }
public void AddDivision() { var division = new Division { DivisionName = "Basket Weaving", SupervisorId = _db.Employees.Last().Id }; _db.Divisions.Add(division); _db.SaveChanges(); Assert.Equal(6, _db.Divisions.Count()); }
public int SaveChanges() { try { return(Db.SaveChanges()); } catch (DbUpdateConcurrencyException ex) { //A concurrency error occurred Console.WriteLine(ex); throw; } catch (RetryLimitExceededException ex) { //DbResiliency retry limit exceeded Console.WriteLine(ex); throw; } catch (Exception ex) { Console.WriteLine(ex); throw; } }
public static void SeedData(PurchaseReqContext context) { context.Database.EnsureCreated(); if (!context.Campuses.Any()) { context.Campuses.AddRange(SampleData.GetCampuses); context.SaveChanges(); } if (!context.Rooms.Any()) { context.Rooms.AddRange(SampleData.GetRooms); context.SaveChanges(); } if (!context.Employees.Any()) { context.Employees.AddRange(SampleData.GetEmployees(context.Rooms.ToList())); context.SaveChanges(); } if (!context.Divisions.Any()) { context.Divisions.AddRange(SampleData.GetDivisions(context.Employees.ToList())); context.SaveChanges(); } if (!context.Departments.Any()) { context.Departments.AddRange(SampleData.GetDepartments(context.Divisions.ToList())); context.SaveChanges(); context.Employees.UpdateRange(SampleData.SetEmployeesDepartment(context.Employees.OrderBy(x => x.FirstName).ToList())); context.SaveChanges(); } if (!context.BudgetCodes.Any()) { context.BudgetCodes.AddRange(SampleData.GetBudgetCodes); context.SaveChanges(); } if (!context.EmployeesBudgetCodes.Any()) { context.EmployeesBudgetCodes.AddRange(SampleData.GetEmployeeBudgetCodes(context.Employees.ToList(), context.BudgetCodes.ToList())); context.Employees.UpdateRange(SampleData.SetPasswords(context.Employees.ToList())); context.SaveChanges(); } if (!context.Vendors.Any()) { context.Vendors.AddRange(SampleData.GetVendors); context.SaveChanges(); } if (!context.Statuses.Any()) { context.Statuses.AddRange(SampleData.GetStatuses); context.SaveChanges(); } if (!context.Categories.Any()) { context.Categories.AddRange(SampleData.GetCategories); context.SaveChanges(); } if (!context.Orders.Any()) { context.Orders.AddRange(SampleData.GetOrders(context.Employees.ToList())); context.SaveChanges(); } if (!context.Items.Any()) { context.Items.AddRange(SampleData.GetItems); context.SaveChanges(); } if (!context.Requests.Any()) { context.Requests.AddRange(SampleData.GetRequests); context.SaveChanges(); } if (!context.Approval.Any()) { context.Approval.AddRange(SampleData.GetApprovals); context.SaveChanges(); } if (!context.Roles.Any()) { context.Roles.AddRange(SampleData.GetRoles); context.SaveChanges(); } if (!context.UserRoles.Any()) { context.UserRoles.AddRange(SampleData.GetUserWithRole(context.Employees.ToList(), context.Roles.ToList())); context.SaveChanges(); } if (!context.SupervisorApprovals.Any()) { context.SupervisorApprovals.AddRange(SampleData.GetSupervisorApprovals(context.Employees.ToList(), context.Roles.ToList())); context.SaveChanges(); } context.SaveChanges(); }