public void GetFuel_ById() { //ARRANGE var options = new DbContextOptionsBuilder <FleetManagmentContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FleetManagmentContext(options); IFuelRepository fuelRepository = new FuelRepository(context); FuelTO fuel = new FuelTO { Name = "diesel", }; FuelTO fuel2 = new FuelTO { Name = "essence", }; //ACT var addedFuel = fuelRepository.Insert(fuel); var addedFuel2 = fuelRepository.Insert(fuel2); context.SaveChanges(); //ASSERT Assert.IsNotNull(addedFuel); Assert.AreNotEqual(0, addedFuel.Id); Assert.AreEqual("diesel", addedFuel.Name); Assert.AreEqual(1, fuelRepository.GetByID(1).Id); }
public void AddFuel_ThrowsException_WhenNullIsProvided() { var options = new DbContextOptionsBuilder <FleetManagmentContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FleetManagmentContext(options); IFuelRepository fuelRepository = new FuelRepository(context); FuelTO fuel = new FuelTO { Name = "diesel", }; FuelTO fuel2 = new FuelTO { Name = "essence", }; //ACT var addedFuel = fuelRepository.Insert(fuel); context.SaveChanges(); //ASSERT Assert.ThrowsException <ArgumentNullException>(() => fuelRepository.Insert(null)); }
public void UpdapteFuel_With_Correct_Parameter() { //ARRANGE var options = new DbContextOptionsBuilder <FleetManagmentContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FleetManagmentContext(options); IFuelRepository fuelRepository = new FuelRepository(context); FuelTO fuel = new FuelTO { Name = "diesel" }; //ACT var addedFuel = fuelRepository.Insert(fuel); context.SaveChanges(); addedFuel.Name = "essence"; fuelRepository.Update(addedFuel); context.SaveChanges(); //ASSERT Assert.IsNotNull(addedFuel); Assert.AreNotEqual(0, addedFuel.Id); Assert.AreEqual("essence", addedFuel.Name); }
public int Save(BE.Fuel fuel) { FuelRepository repository = new FuelRepository(); if(fuel.ID > 0) return repository.Update(fuel); else return repository.Insert(fuel); }
public void DeleteFuel_With_FuelTO_Parameter() { //ARRANGE var options = new DbContextOptionsBuilder <FleetManagmentContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FleetManagmentContext(options); IFuelRepository fuelRepository = new FuelRepository(context); FuelTO fuel = new FuelTO { Name = "diesel", }; FuelTO fuel2 = new FuelTO { Name = "essence", }; var addedFuel = fuelRepository.Insert(fuel); var addedFuel2 = fuelRepository.Insert(fuel2); context.SaveChanges(); //List<FuelTO> fuels = new List<FuelTO>(); var fuels = fuelRepository.GetAll().ToList(); //ACT fuelRepository.Remove(addedFuel); context.SaveChanges(); fuels = fuelRepository.GetAll().ToList(); //ASSERT Assert.IsNotNull(addedFuel); Assert.IsNotNull(addedFuel2); Assert.AreNotEqual(0, addedFuel.Id); Assert.AreNotEqual(0, addedFuel2.Id); Assert.AreEqual("diesel", addedFuel.Name); Assert.AreEqual("essence", addedFuel2.Name); Assert.AreEqual(1, fuels.Count); }