Example #1
0
        public void Test_AddSituationWhenSituationContainsOnlyLettersAndDoesNOTExistInDatabase_SituationsRetrievedEqualsToSituationsExpected()
        {
            //Arrange
            int situationsExpected = 3;
            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 = "Closed", Status = true, ExistInDB = true, IsValid = true
            }) as JsonResult;
            var situationsRetrieved = _situationService.RetrieveAllSituations();

            //Assert
            //dynamic resultData = result.Data;
            Assert.AreEqual(situationsExpected, situationsRetrieved.Count);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        public void Test_RetrieveAllSituationsFromDatabase_ZeroSituationsRetrieved()
        {
            //Arrange
            IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>();
            ILogger            _logger            = new MockTruckCheckUpLogger();
            IValidateUserInput _validateUserInput = new ValidateUserInput();
            ISituationService  _situationService  = new SituationService(_situationContext, _logger, _validateUserInput);

            //Act
            var result = _situationService.RetrieveAllSituations();

            //Assert
            Assert.AreEqual(0, result.Count);
        }
Example #5
0
        public void Test_RetrieveAllSituationsFromDatabase_SituationListViewModelObjectReturned()
        {
            //Arrange
            IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>();
            ILogger            _logger            = new MockTruckCheckUpLogger();
            IValidateUserInput _validateUserInput = new ValidateUserInput();
            ISituationService  _situationService  = new SituationService(_situationContext, _logger, _validateUserInput);
            bool expected = true;
            bool actual   = false;

            //Act
            var result = _situationService.RetrieveAllSituations();

            if (result is List <SituationListViewModel> )
            {
                actual = true;
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
Example #6
0
        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);
        }