public void UpdapteTechnicalControl_With_Correct_Parameter() { //ARRANGE var options = new DbContextOptionsBuilder <FleetManagmentContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FleetManagmentContext(options); ITechnicalControlRepository technicalControlRepository = new TechnicalControlRepository(context); TechnicalControlTO technicalControl = new TechnicalControlTO { Comment = "Nothing" }; //ACT var addedTechnicalControl = technicalControlRepository.Insert(technicalControl); context.SaveChanges(); addedTechnicalControl.Comment = "Refused"; technicalControlRepository.Update(addedTechnicalControl); context.SaveChanges(); //ASSERT Assert.IsNotNull(addedTechnicalControl); Assert.AreNotEqual(0, addedTechnicalControl.Id); Assert.AreEqual("Refused", addedTechnicalControl.Comment); }
public void GetTechnicalControl_ById() { //ARRANGE var options = new DbContextOptionsBuilder <FleetManagmentContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FleetManagmentContext(options); ITechnicalControlRepository technicalControlRepository = new TechnicalControlRepository(context); TechnicalControlTO technicalControl = new TechnicalControlTO { Comment = "nothing", }; TechnicalControlTO technicalControl2 = new TechnicalControlTO { Comment = "change tyre", }; //ACT var addedTechnicalControl = technicalControlRepository.Insert(technicalControl); var addedTechnicalControl2 = technicalControlRepository.Insert(technicalControl2); context.SaveChanges(); //ASSERT Assert.IsNotNull(addedTechnicalControl); Assert.AreNotEqual(0, addedTechnicalControl.Id); Assert.AreEqual("nothing", addedTechnicalControl.Comment); Assert.AreEqual(1, technicalControlRepository.GetByID(1).Id); }
public TechnicalControlTO Insert(TechnicalControlTO entity) { if (entity is null) { throw new ArgumentNullException(nameof(entity)); } return(context.TechnicalControls.Add(entity.ToEntity()).Entity.ToTransfertObject()); }
public TechnicalControlTO Update(TechnicalControlTO entity) { if (entity is null) { throw new ArgumentNullException(nameof(entity)); } var updated = context.TechnicalControls.FirstOrDefault(x => x.Id == entity.Id); updated.Car = entity.Car?.ToEntity(); updated.Comment = entity.Comment; updated.EndDate = entity.EndDate; updated.StartDate = entity.StartDate; return(updated.ToTransfertObject()); }
public static TechnicalControl ToDomain(this TechnicalControlTO technicalControl) { if (technicalControl is null) { throw new ArgumentNullException(nameof(technicalControl)); } return(new TechnicalControl { Id = technicalControl.Id, Comment = technicalControl.Comment, StartDate = technicalControl.StartDate, EndDate = technicalControl.EndDate, Car = technicalControl.Car?.ToDomain(), }); }
public void DeleteTechnicalControl_With_TechnicalControlTO_Parameter() { //ARRANGE var options = new DbContextOptionsBuilder <FleetManagmentContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FleetManagmentContext(options); ITechnicalControlRepository technicalControlRepository = new TechnicalControlRepository(context); TechnicalControlTO technicalControl = new TechnicalControlTO { Comment = "nothing", }; TechnicalControlTO technicalControl2 = new TechnicalControlTO { Comment = "change tyre", }; var addedTechnicalControl = technicalControlRepository.Insert(technicalControl); var addedTechnicalControl2 = technicalControlRepository.Insert(technicalControl2); context.SaveChanges(); //List<TechnicalControlTO> technicalControls = new List<TechnicalControlTO>(); var technicalControls = technicalControlRepository.GetAll().ToList(); //ACT technicalControlRepository.Remove(addedTechnicalControl); context.SaveChanges(); technicalControls = technicalControlRepository.GetAll().ToList(); //ASSERT Assert.IsNotNull(addedTechnicalControl); Assert.IsNotNull(addedTechnicalControl2); Assert.AreNotEqual(0, addedTechnicalControl.Id); Assert.AreNotEqual(0, addedTechnicalControl2.Id); Assert.AreEqual("nothing", addedTechnicalControl.Comment); Assert.AreEqual("change tyre", addedTechnicalControl2.Comment); Assert.AreEqual(1, technicalControls.Count); }
public void AddTechnicalControl_ThrowsException_WhenNullIsProvided() { var options = new DbContextOptionsBuilder <FleetManagmentContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FleetManagmentContext(options); ITechnicalControlRepository technicalControlRepository = new TechnicalControlRepository(context); TechnicalControlTO technicalControl = new TechnicalControlTO { Comment = "nothing", }; //ACT var addedTechnicalControl = technicalControlRepository.Insert(technicalControl); context.SaveChanges(); //ASSERT Assert.ThrowsException <ArgumentNullException>(() => technicalControlRepository.Insert(null)); }
public bool Remove(TechnicalControlTO entity) { return(RemoveById(entity.Id)); }