public void Test_ManufacturerDescriptionFieldEmptyOrNull_ManufacturerNotAdded() { //Arrange IRepository <TruckManufacturer> _truckManufacturerContext = new MockTruckCheckUpContext <TruckManufacturer>(); ILogger _logger = new MockTruckCheckUpLogger(); TruckManufacturerService truckManufacturerService = new TruckManufacturerService(_truckManufacturerContext, _logger); truckManufacturerService.ValidateTruckManufacturerToAdd(new TruckManufacturerViewModel() { Id = "5", Description = "Toyota" }); //Arrange - Add record with empty ManufacturerDescription var manufacturerToInsertViewModel = new TruckManufacturerViewModel() { Id = "6", Description = "" }; //Act if (!string.IsNullOrEmpty(manufacturerToInsertViewModel.Description)) { truckManufacturerService.SaveNewTruckManufacturerData(manufacturerToInsertViewModel, new Log4NetLogger()); } var result = truckManufacturerService.RetrieveAllTruckManufacturers(); //Assert Assert.AreEqual(1, result.Count); }
public void Test_ManufacturerAlreadyExistInDB_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 manufacturer that already exist var manufacturerToInsertViewModel = new TruckManufacturerViewModel() { Id = "8", Description = "Hyundai" }; //Act if (!truckManufacturerService.RetrieveTruckManufacturerName(manufacturerToInsertViewModel.Description)) { truckManufacturerService.SaveNewTruckManufacturerData(manufacturerToInsertViewModel, new Log4NetLogger()); } var result = truckManufacturerService.RetrieveAllTruckManufacturers(); //Assert Assert.AreEqual(1, result.Count); }
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_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); }