public void Delete_Schedule_By_Schedule() { Pier pier = new Pier { Name = "Pier Test" }; Route route = new Route { Name = "Route Test", TimeTable = new TimeTable { Name = "TimeTable" } }; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { ScheduleRepository scheduleRepository = new ScheduleRepository(ctx); scheduleRepository.Add(new Schedule { Pier = pier, Route = route, Time = new TimeSpan(1, 0, 0) }); scheduleRepository.SaveChanges(); } // Find and delete it using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Schedule> schedules = ctx.Schedules.Where(schedule => schedule.Pier.Id == pier.Id && schedule.Route.Id == route.Id).ToList(); Assert.AreEqual(1, schedules.Count()); ScheduleRepository scheduleRepository = new ScheduleRepository(ctx); scheduleRepository.Delete(schedules[0]); scheduleRepository.SaveChanges(); } // Check that nothing is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Schedule> schedules = ctx.Schedules.Where(schedule => schedule.Pier.Id == pier.Id && schedule.Route.Id == route.Id).ToList(); Assert.AreEqual(0, schedules.Count()); } }
public void Delete_TimeTable_By_TimeTableId() { int pierId = 1000; string timeTableName = "Test TimeTable to Delete"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { TimeTableRepository timeTableRepository = new TimeTableRepository(ctx); timeTableRepository.Add(new TimeTable { Id = pierId, Name = timeTableName }); timeTableRepository.SaveChanges(); } // Find and delete it using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<TimeTable> timeTables = ctx.TimeTables.Where(pier => pier.Name == timeTableName).ToList(); Assert.AreEqual(1, timeTables.Count()); } using (ThamesClipperContext ctx = new ThamesClipperContext()) { TimeTableRepository timeTableRepository = new TimeTableRepository(ctx); timeTableRepository.Delete(pierId); timeTableRepository.SaveChanges(); } // Check that nothing is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<TimeTable> timeTables = ctx.TimeTables.Where(pier => pier.Id == pierId).ToList(); Assert.AreEqual(0, timeTables.Count()); } }
public void Delete_Pier_By_Pier() { string pierName = "Test Pier to Delete"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { PierRepository pierRepository = new PierRepository(ctx); pierRepository.Add(new Pier { Name = pierName }); pierRepository.SaveChanges(); } // Find and delete it using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierName).ToList(); Assert.AreEqual(1, piers.Count()); PierRepository pierRepository = new PierRepository(ctx); pierRepository.Delete(piers[0]); pierRepository.SaveChanges(); } // Check that nothing is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierName).ToList(); Assert.AreEqual(0, piers.Count()); } }
public void Setup() { AppDomain.CurrentDomain.SetData("DataDirectory", AppDomain.CurrentDomain.BaseDirectory); using (ThamesClipperContext ctx = new ThamesClipperContext()) { if (ctx.Database.Exists()) { ctx.Database.Delete(); } } }
public void Add_Route() { string routeName = "Test Route to Add"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { RouteRepository routeRepository = new RouteRepository(ctx); routeRepository.Add(new Route { Name = routeName, TimeTable = new TimeTable { Name = "TimeTable to add" } }); routeRepository.SaveChanges(); } // Check that it is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Route> routes = ctx.Routes.Where(route => route.Name == routeName).ToList(); Assert.AreEqual(1, routes.Count()); } }
public void Add_TimeTable() { string timeTableName = "Test TimeTable to Add"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { TimeTableRepository timeTableRepository = new TimeTableRepository(ctx); timeTableRepository.Add(new TimeTable { Name = timeTableName }); timeTableRepository.SaveChanges(); } // Check that it is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<TimeTable> timeTables = ctx.TimeTables.Where(pier => pier.Name == timeTableName).ToList(); Assert.AreEqual(1, timeTables.Count()); } }
public void Add_Pier() { string pierName = "Test Pier to Add"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { PierRepository pierRepository = new PierRepository(ctx); pierRepository.Add(new Pier { Name = pierName }); pierRepository.SaveChanges(); } // Check that it is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierName).ToList(); Assert.AreEqual(1, piers.Count()); } }
public void Delete_Route_By_Route() { string routeName = "Test Route to Delete"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { RouteRepository routeRepository = new RouteRepository(ctx); Route route = new Route { Name = routeName, TimeTable = new TimeTable { Name = "TimeTable" } }; route.Schedules = new List<Schedule>() { new Schedule { Route = route, Pier = new Pier { Name = "Pier" }, Time = new TimeSpan(1, 0, 0) } }; routeRepository.Add(route); routeRepository.SaveChanges(); } // Find and delete it using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Route> routes = ctx.Routes.Where(route => route.Name == routeName).ToList(); Assert.AreEqual(1, routes.Count()); RouteRepository routeRepository = new RouteRepository(ctx); routeRepository.Delete(routes[0]); routeRepository.SaveChanges(); } // Check that nothing is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Route> routes = ctx.Routes.Where(route => route.Name == routeName).ToList(); Assert.AreEqual(0, routes.Count()); } }
public void Add_Or_Update_Schedule() { Pier pier = new Pier { Name = "Pier" }; TimeTable timeTable = new TimeTable { Name = "TimeTable" }; Route routeExisting = new Route { Name = "Route1", TimeTable = timeTable }; Route routeAdd = new Route { Name = "Route2", TimeTable = timeTable }; TimeSpan timeExisting = new TimeSpan(13, 0, 0); TimeSpan timeAdd = new TimeSpan(14, 0, 0); TimeSpan timeUpdated = new TimeSpan(15, 0, 0); Schedule existing = new Schedule { Pier = pier, Route = routeExisting, Time = timeExisting }; Schedule add = new Schedule { Pier = pier, Route = routeAdd, Time = timeAdd }; // Add the existing one to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { ScheduleRepository scheduleRepository = new ScheduleRepository(ctx); scheduleRepository.Add(existing); scheduleRepository.SaveChanges(); } // Find and update it using (ThamesClipperContext ctx = new ThamesClipperContext()) { ScheduleRepository scheduleRepository = new ScheduleRepository(ctx); existing.Time = timeUpdated; scheduleRepository.AddOrUpate(existing); scheduleRepository.AddOrUpate(add); scheduleRepository.SaveChanges(); } // Check that the new name is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { var schedulesExisting = ctx.Schedules.Where(schedule => schedule.Pier.Id == pier.Id && schedule.Route.Id == routeExisting.Id).ToList(); Assert.AreEqual(1, schedulesExisting.Count()); Assert.AreEqual(timeUpdated, schedulesExisting[0].Time); var schedulesAdd = ctx.Schedules.Where(schedule => schedule.Pier.Id == pier.Id && schedule.Route.Id == routeAdd.Id).ToList(); Assert.AreEqual(1, schedulesAdd.Count()); } }
public void Update_Route() { string routeName = "Test Route to Update"; string routeNameUpdated = "Test Route Updated"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { RouteRepository routeRepository = new RouteRepository(ctx); routeRepository.Add(new Route { Name = routeName, TimeTable = new TimeTable { Name = "TimeTable" } }); routeRepository.SaveChanges(); } // Find and update it using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Route> routes = ctx.Routes.Where(route => route.Name == routeName).ToList(); Assert.AreEqual(1, routes.Count()); RouteRepository routeRepository = new RouteRepository(ctx); routes[0].Name = routeNameUpdated; routeRepository.Update(routes[0]); routeRepository.SaveChanges(); } // Check that the new name is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Route> routes = ctx.Routes.Where(route => route.Name == routeNameUpdated).ToList(); Assert.AreEqual(1, routes.Count()); } }
public void Update_TimeTable() { string timeTableName = "Test TimeTable to Update"; string timeTableNameUpdated = "Test TimeTable Updated"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { TimeTableRepository timeTableRepository = new TimeTableRepository(ctx); timeTableRepository.Add(new TimeTable { Name = timeTableName }); timeTableRepository.SaveChanges(); } // Find and update it using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<TimeTable> timeTables = ctx.TimeTables.Where(pier => pier.Name == timeTableName).ToList(); Assert.AreEqual(1, timeTables.Count()); TimeTableRepository timeTableRepository = new TimeTableRepository(ctx); timeTables[0].Name = timeTableNameUpdated; timeTableRepository.Update(timeTables[0]); timeTableRepository.SaveChanges(); } // Check that the new name is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<TimeTable> timeTables = ctx.TimeTables.Where(pier => pier.Name == timeTableNameUpdated).ToList(); Assert.AreEqual(1, timeTables.Count()); } }
public void Update_Pier() { string pierName = "Test Pier to Update"; string pierNameUpdated = "Test Pier Updated"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { PierRepository pierRepository = new PierRepository(ctx); pierRepository.Add(new Pier { Name = pierName }); pierRepository.SaveChanges(); } // Find and update it using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierName).ToList(); Assert.AreEqual(1, piers.Count()); PierRepository pierRepository = new PierRepository(ctx); piers[0].Name = pierNameUpdated; pierRepository.Update(piers[0]); pierRepository.SaveChanges(); } // Check that the new name is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierNameUpdated).ToList(); Assert.AreEqual(1, piers.Count()); } }