public void Test_AddSituationDescriptionWhenSituationContainsOnlyLettersAndDoesNotExistInDatabase_SituationAdded() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act var result = situationController.Add(new SituationViewModel() { Id = "", Description = "Open", Status = true, ExistInDB = true, IsValid = true }) as JsonResult; //Assert dynamic resultData = result.Data; Assert.AreEqual(true, resultData.IsValid); }
public void Test_UpdateSituationDescriptionWhenSituationIsNull_IsValidPropertyReturnsFalse() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add some records to populate the Mock table _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act var result = situationController.Update(new SituationViewModel() { Id = "2", Description = "", Status = true, IsValid = true, ExistInDB = true }); dynamic resultData = result.Data; //Assert Assert.AreEqual(false, resultData.IsValid); }
public void Test_DeleteSituationDescriptionByIdWhenSituationExist_SituationDescriptionDeleted() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add some records to populate the Mock table _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act situationController.Delete("2"); //Search for Id deleted to validate deletion var result = situationController.GetSituationById("2"); dynamic resultData = result.Data; //Assert Assert.AreEqual(null, resultData.Description); }
public void Test_SearchLowerCaseLettersSituationDescriptionWhenSituationIsValidAndExistInDatabase_ExistInDBPropertyReturnsTrue() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add some records to populate the Mock table _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act var result = situationController.SearchSituationDescription(new SituationViewModel() { Id = "", Description = "open", Status = true, IsValid = true, ExistInDB = true }) as JsonResult; //Assert dynamic resultData = result.Data; Assert.AreEqual(true, resultData.ExistInDB); }
public void Test_UpdateSituationDescriptionWhenSituationIsValidAndDoesNOTExistInDatabase_SituationDescriptionUpdated() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add some records to populate the Mock table _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act situationController.Update(new SituationViewModel() { Id = "2", Description = "Opened", Status = true, IsValid = true, ExistInDB = true }); var result = situationController.GetSituationById("2") as JsonResult; dynamic resultData = result.Data; //Assert Assert.AreEqual("Opened", resultData.Description); }
public void Test_UpdateSituationWhenSituationEnteredExistInDatabaseAndDoesNOTContainsOnlyLetters_SituationDescriptionNOTUpdated() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); IValidateUserInput _validate = new ValidateUserInput(); ILogger _logger = new MockTruckCheckUpLogger(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validate); //Populate table, so we can test whether there is data available _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act _situationService.EvaluateSituationDescriptionBeforeUpdating(new SituationViewModel() { Id = "1", Description = "Open88", Status = true, ExistInDB = true, IsValid = true }); var result = _situationService.RetrieveSituationById("1"); //Assert Assert.AreEqual("InProgress", result.Description); }
public void Test_ListOfSituations_ReturnsListOfSituationsInDatabase() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act var result = situationController.ListOfSituations() as JsonResult; //Assert dynamic resultData = result.Data; Assert.AreEqual(2, resultData.Count); Assert.AreEqual("2", resultData[0].Id); }
public void Test_AddSituationDescriptionInLowerCaseLettersWhenSituationEXISTInDatabaseAndContainsOnlyLetters_SituationNotAddedToDatabase() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); //Populate table, so we can test whether service is adding records. _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act //Add a third record to test _situationService.EvaluateSituationDescriptionBeforeAdding(new SituationViewModel() { Id = "3", Description = "open", Status = true, ExistInDB = false, IsValid = true }); var result = _situationService.RetrieveAllSituations(); //Assert Assert.AreEqual(2, result.Count); }
public void Test_SearchSituationWhenSituationEXISTInDatabaseAndSituationContainsAlphanumericCharacters_IsValidPropertyReturnsFalse() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); IValidateUserInput _validate = new ValidateUserInput(); ILogger _logger = new MockTruckCheckUpLogger(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validate); //Populate table, so we can test whether there is data available _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act var result = _situationService.EvaluateSituationDescriptionBeforeSearching(new SituationViewModel() { Id = "1", Description = "InProgress88", Status = true, ExistInDB = true, IsValid = true }); //Assert Assert.AreEqual(false, result.IsValid); }
public void Test_SearchSituationWhenSituationIsEnteredInLowerCaseLettersAndSituationEXISTInDatabase_RetrieveSituationRequested() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); IValidateUserInput _validate = new ValidateUserInput(); ILogger _logger = new MockTruckCheckUpLogger(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validate); //Populate table, so we can test whether there is data available _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act var result = _situationService.EvaluateSituationDescriptionBeforeSearching(new SituationViewModel() { Id = "1", Description = "inprogress", Status = true, ExistInDB = true, IsValid = true }); //Assert Assert.AreEqual("InProgress", result.Description); }
public void Test_DeleteSituationDescriptionWhenSituationExist_SituationDescriptionDeletedFromDatabase() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); //Populate table, so we can test whether service is adding records. _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act _situationService.DeleteSituation("2"); var result = _situationService.RetrieveAllSituations(); //Assert Assert.AreEqual(1, result.Count); }
public void Test_RetrieveTruckManufacturers_AllRecords() { //Arrange IRepository <TruckManufacturer> _truckManufacturerContext = new MockTruckCheckUpContext <TruckManufacturer>(); ILogger _logger = new MockTruckCheckUpLogger(); //Add couple records to truck manufacturer mock class _truckManufacturerContext.Insert(new TruckManufacturer() { Id = "1", ManufacturerDescription = "Isuzu" }); _truckManufacturerContext.Insert(new TruckManufacturer() { Id = "2", ManufacturerDescription = "Ford" }); TruckManufacturerService truckManufacturerService = new TruckManufacturerService(_truckManufacturerContext, _logger); //Act var result = truckManufacturerService.RetrieveAllTruckManufacturers(); _logger.Info("Test-RetrieveTruckManufacturers-AllRecords"); //Assert Assert.AreEqual(2, result.Count); }
public void Test_RetrieveSituationRecordByIdWhenSearchingForNonExistentId_ReturnsNullSituationViewModelObject() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); //Populate table, so we can test whether the method is returning the right record _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act var result = _situationService.RetrieveSituationById("3"); //Assert Assert.AreEqual(null, result.Description); }
public void Test_RetrieveAllSituationsFromDatabase_AllSituationsRetrieved() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); IValidateUserInput _validate = new ValidateUserInput(); ILogger _logger = new MockTruckCheckUpLogger(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validate); //Populate table, so we can test whether there is data available _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act var result = _situationService.RetrieveAllSituations(); //Assert Assert.AreEqual(2, result.Count); }