public void Test_ManufacturerDescriptionIsNotEmptyOrNullAndContainsOnlyLettersOrNumbersAndDoesNotExistAlreadyInDB_ManufacturerAdded() { //Arrange IRepository <TruckManufacturer> _truckManufacturerContext = new MockTruckCheckUpContext <TruckManufacturer>(); ILogger _logger = new MockTruckCheckUpLogger(); TruckManufacturerService truckManufacturerService = new TruckManufacturerService(_truckManufacturerContext, _logger); truckManufacturerService.ValidateTruckManufacturerToAdd(new TruckManufacturerViewModel() { Id = "3", Description = "GMC" }); var manufacturerToInsertViewModel = new TruckManufacturerViewModel() { Id = "4", Description = "Chevy" }; if (!string.IsNullOrEmpty(manufacturerToInsertViewModel.Description)) { if (truckManufacturerService.ValidateManufacturerString(manufacturerToInsertViewModel.Description)) { if (!truckManufacturerService.RetrieveTruckManufacturerName(manufacturerToInsertViewModel.Description)) { truckManufacturerService.SaveNewTruckManufacturerData(manufacturerToInsertViewModel, new Log4NetLogger()); } } } //Act var result = truckManufacturerService.RetrieveAllTruckManufacturers(); //Assert Assert.AreEqual(2, result.Count); }
public void Test_ManufacturerDescriptionFieldContainsNotAllowedCharacters_ManufacturerNotUpdated() { //Arrange IRepository <TruckManufacturer> _truckManufacturerContext = new Mocks.MockTruckCheckUpContext <TruckManufacturer>(); ILogger _logger = new MockTruckCheckUpLogger(); TruckManufacturerService truckManufacturerService = new TruckManufacturerService(_truckManufacturerContext, _logger); truckManufacturerService.ValidateTruckManufacturerToAdd(new TruckManufacturerViewModel() { Id = "7", Description = "Hyundai" }); //Add record with characters not allowed var manufacturerToUpdate = new TruckManufacturerViewModel() { Id = "7", Description = "Kenw@rth" }; //Act if (truckManufacturerService.ValidateManufacturerString(manufacturerToUpdate.Description)) { truckManufacturerService.UpdateTruckManufacturerData(manufacturerToUpdate, new Log4NetLogger()); } var manufacturerUpdated = new TruckManufacturerViewModel(); manufacturerUpdated.Description = "Hyundai"; var result = truckManufacturerService.SearchTruckManufacturer(manufacturerUpdated); //Assert Assert.AreEqual("Hyundai", result.Description); }
public void Test_ManufacturerDescriptionFieldContainsCharactersNotAllowed_ManufacturerNotAdded() { //Arrange IRepository <TruckManufacturer> _truckManufacturerContext = new Mocks.MockTruckCheckUpContext <TruckManufacturer>(); ILogger _logger = new MockTruckCheckUpLogger(); TruckManufacturerService truckManufacturerService = new TruckManufacturerService(_truckManufacturerContext, _logger); truckManufacturerService.ValidateTruckManufacturerToAdd(new TruckManufacturerViewModel() { Id = "7", Description = "Hyundai" }); //Add record with characters not allowed var manufacturerToInsertViewModel = new TruckManufacturerViewModel() { Id = "8", Description = "Intern@tion@l" }; //Act if (truckManufacturerService.ValidateManufacturerString(manufacturerToInsertViewModel.Description)) { truckManufacturerService.SaveNewTruckManufacturerData(manufacturerToInsertViewModel, new Log4NetLogger()); } var result = truckManufacturerService.RetrieveAllTruckManufacturers(); //Assert Assert.AreEqual(1, result.Count); }
public void Test_ManufacturerDescriptionIsNotEmptyOrNullAndContainsOnlyLettersOrNumbersAndDoesNotExistAlreadyInDB_RecordUpdated() { //Arrange = IRepository <TruckManufacturer> _truckManufacturerContext = new Mocks.MockTruckCheckUpContext <TruckManufacturer>(); ILogger _logger = new MockTruckCheckUpLogger(); TruckManufacturerService truckManufacturerService = new TruckManufacturerService(_truckManufacturerContext, _logger); truckManufacturerService.ValidateTruckManufacturerToAdd( new TruckManufacturerViewModel() { Id = "1", Description = "Chevrolet" }); var manufacturerViewModel = new TruckManufacturerViewModel() { Id = "1", Description = "Chevrolet" }; var manufacturerSearchResult = truckManufacturerService.SearchTruckManufacturer(manufacturerViewModel); var manufacturerToUpdateViewModel = new TruckManufacturerViewModel() { Id = manufacturerSearchResult.Id, Description = "Chevy" }; if (!string.IsNullOrEmpty(manufacturerToUpdateViewModel.Description)) { if (truckManufacturerService.ValidateManufacturerString(manufacturerToUpdateViewModel.Description)) { if (!truckManufacturerService.RetrieveTruckManufacturerName(manufacturerToUpdateViewModel.Description)) { truckManufacturerService.UpdateTruckManufacturerData(manufacturerToUpdateViewModel, new Log4NetLogger()); } } } //Act var manufacturerToSearchAfterUpdate = new TruckManufacturerViewModel(); manufacturerToSearchAfterUpdate.Description = "Chevy"; var result = truckManufacturerService.SearchTruckManufacturer(manufacturerToSearchAfterUpdate); //Assert Assert.AreEqual("Chevy", result.Description); }