示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        public void Test_Index_IndexActionReturnsIndexView()
        {
            //Arrange
            IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>();
            ILogger            _logger            = new MockTruckCheckUpLogger();
            IValidateUserInput _validateUserInput = new ValidateUserInput();

            ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput);
            var situationController             = new SituationManagementController(_situationService);

            //Act
            ViewResult result = situationController.Index() as ViewResult;

            //Assert
            Assert.IsNotNull(result);
        }
示例#8
0
        public void Test_ListOfSituations_ReturnsZeroSituationsInDatabase()
        {
            //Arrange
            IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>();
            ILogger            _logger            = new MockTruckCheckUpLogger();
            IValidateUserInput _validateUserInput = new ValidateUserInput();

            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(0, resultData.Count);
        }