public void Put_CarClass_IsTrue() { var carclass = new CarClass() { Class = "ichwerde", CostsPerDay = 1000m }; DbContextOptionsBuilder <CarRentDBContext> builder = new DbContextOptionsBuilder <CarRentDBContext>(); builder.UseInMemoryDatabase("CarRent"); DbContextOptions <CarRentDBContext> options = builder.Options; CarRentDBContext carrent = new CarRentDBContext(options); ExampleData.ExampleData.InitTestData(carrent); var carclasscontroller = new CarClassesController(carrent); carclasscontroller.PostCarClass(carclass); int id = 0; foreach (var cclass in carclasscontroller.GetCarClasses()) { if (cclass.Class.Equals("ichwerde")) { id = cclass.Id; break; } } var carclass2 = carclasscontroller.GetCarClass(id); carclasscontroller.PutCarClass(id, carclass2); var carclass3 = carclasscontroller.GetCarClass(id); Assert.IsTrue(carclass3.Class.Equals(carclass2.Class)); }
public void Post_CarClass_IsTrue() { var carclass = new CarClass() { Class = "Ichwerdegeloescht", CostsPerDay = 1000m }; DbContextOptionsBuilder <CarRentDBContext> builder = new DbContextOptionsBuilder <CarRentDBContext>(); builder.UseInMemoryDatabase("CarRent"); DbContextOptions <CarRentDBContext> options = builder.Options; CarRentDBContext carrent = new CarRentDBContext(options); ExampleData.ExampleData.InitTestData(carrent); var carclasscontroller = new CarClassesController(carrent); if (carrent.CarClasses.Any(e => e.Class == carclass.Class)) { int index = 0; var carclasslist = carclasscontroller.GetCarClasses(); foreach (var cclass in carclasslist) { if (!cclass.Class.Equals(carclass.Class)) { continue; } index = cclass.Id; } carclasscontroller.DeleteCarClass(index); } carclasscontroller.PostCarClass(carclass); var bOk = false; var ind = 0; foreach (var carsclasses in carclasscontroller.GetCarClasses()) { if (carsclasses.Class.Equals(carclass.Class) && carsclasses.CostsPerDay == carclass.CostsPerDay) { bOk = true; ind = carsclasses.Id; break; } } carclasscontroller.DeleteCarClass(ind); Assert.IsTrue(bOk); }