public void ReturnAlreadyExist_WhenTarifWithSameDaysExist()
        {
            //Arrange
            var nameParam       = "Default";
            var dayParam        = 10;
            var price           = 1.5M;
            var validParameters = new List <string>()
            {
                nameParam, dayParam.ToString(), price.ToString()
            };
            var dbMock      = new Mock <IDatabasePostgre>();
            var factoryMock = new Mock <IModelsFactory>();

            var tarifMock = new Mock <Tarif>();

            var tarifRepositoryMock = new Mock <ITarifRepository>();

            tarifRepositoryMock.Setup(t => t.SingleOrDefault(It.IsAny <Expression <Func <Tarif, bool> > >())).Returns(tarifMock.Object);
            dbMock.Setup(d => d.Tarifs).Returns(tarifRepositoryMock.Object);

            var sut            = new CreateTarifCommand(dbMock.Object, factoryMock.Object);
            var expectedResult = "already exist";

            //Act
            var result = sut.Execute(validParameters);

            //Assert
            StringAssert.Contains(expectedResult, result);
        }
        public void ReturnTarifCreated_WhenTarifIsCreatedAddress()
        {
            //Arrange
            var nameParam       = "Default";
            var dayParam        = 10;
            var price           = 1.5M;
            var validParameters = new List <string>()
            {
                nameParam, dayParam.ToString(), price.ToString()
            };
            var dbMock      = new Mock <IDatabasePostgre>();
            var factoryMock = new Mock <IModelsFactory>();

            var tarifMock = new Mock <Tarif>();

            factoryMock.Setup(f => f.CreateTarif(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <decimal>())).Returns(tarifMock.Object);

            var tarifRepositoryMock = new Mock <ITarifRepository>();

            dbMock.Setup(d => d.Tarifs).Returns(tarifRepositoryMock.Object);

            var sut = new CreateTarifCommand(dbMock.Object, factoryMock.Object);

            var expectedResult = "Tarif created";

            //Act
            var result = sut.Execute(validParameters);

            //Assert
            StringAssert.Contains(expectedResult, result);
        }
        public void CallAddMethodOfDataBaseTarifRepository_WithCreatedTarif()
        {
            //Arrange
            var nameParam       = "Default";
            var dayParam        = 10;
            var price           = 1.5M;
            var validParameters = new List <string>()
            {
                nameParam, dayParam.ToString(), price.ToString()
            };
            var dbMock      = new Mock <IDatabasePostgre>();
            var factoryMock = new Mock <IModelsFactory>();

            var tarifMock = new Mock <Tarif>();

            factoryMock.Setup(f => f.CreateTarif(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <decimal>())).Returns(tarifMock.Object);

            var tarifRepositoryMock = new Mock <ITarifRepository>();

            dbMock.Setup(d => d.Tarifs).Returns(tarifRepositoryMock.Object);

            var sut = new CreateTarifCommand(dbMock.Object, factoryMock.Object);

            //Act
            var result = sut.Execute(validParameters);

            //Assert
            tarifRepositoryMock.Verify(t => t.Add(tarifMock.Object), Times.Once);
        }
        public void ReturnNotValidPrice_WhenPriceParameterCannotBeParsedToInt(params string[] parameters)
        {
            //Arrange
            var dbMock      = new Mock <IDatabasePostgre>();
            var factoryMock = new Mock <IModelsFactory>();

            var sut            = new CreateTarifCommand(dbMock.Object, factoryMock.Object);
            var expectedString = "Not Valid Price";

            //Act
            var result = sut.Execute(parameters);

            //Assert
            StringAssert.Contains(expectedString, result);
        }
        public void ReturnParametersAreEmpty_WhenSomeOfTheParametersIsEmpty(params string[] parameters)
        {
            //Arrange
            var dbMock      = new Mock <IDatabasePostgre>();
            var factoryMock = new Mock <IModelsFactory>();

            var sut            = new CreateTarifCommand(dbMock.Object, factoryMock.Object);
            var expectedString = "parameters are empty";

            //Act
            var result = sut.Execute(parameters);

            //Assert
            StringAssert.Contains(expectedString, result);
        }
        public void ReturnNotValidParameters_WhenParametersAreDifferentOfThree(params string[] parameters)
        {
            //Arrange
            var dbMock      = new Mock <IDatabasePostgre>();
            var factoryMock = new Mock <IModelsFactory>();

            var sut            = new CreateTarifCommand(dbMock.Object, factoryMock.Object);
            var expectedString = "Not valid number";

            //Act
            var result = sut.Execute(parameters);

            //Assert
            StringAssert.Contains(expectedString, result);
        }