public void CallCompleteOfDataBase_WhenAddressIsCreatedAddress()
        {
            //Arrange
            var streetParam     = "street";
            var postalCodeParam = "1715";
            var townId          = 1;
            var validParameters = new List <string>()
            {
                streetParam, postalCodeParam, townId.ToString()
            };
            var dbMock      = new Mock <IDatabase>();
            var factoryMock = new Mock <IModelsFactory>();

            var addressMock = new Mock <Address>();

            factoryMock.Setup(f => f.CreateAddress(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Town>())).Returns(addressMock.Object);

            var townMock = new Mock <Town>();

            var townRepositoryMock = new Mock <ITownRepository>();

            townRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Town, bool> > >())).Returns(townMock.Object);
            dbMock.Setup(d => d.Towns).Returns(townRepositoryMock.Object);

            var addressRepositoryMock = new Mock <IAddessRepository>();

            dbMock.Setup(d => d.Addesses).Returns(addressRepositoryMock.Object);
            var sut = new CreateAddressCommand(dbMock.Object, factoryMock.Object);

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

            //Assert
            dbMock.Verify(d => d.Complete(), Times.Once);
        }
        public void ReturnNotValidTownId_WhenThirdParameterCannotBeParsedToInt(params string[] parameters)
        {
            //Arrange
            var dbMock      = new Mock <IDatabase>();
            var factoryMock = new Mock <IModelsFactory>();

            var sut            = new CreateAddressCommand(dbMock.Object, factoryMock.Object);
            var expectedString = "Not Valid Town Id";

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

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

            var sut            = new CreateAddressCommand(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 <IDatabase>();
            var factoryMock = new Mock <IModelsFactory>();

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

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

            //Assert
            StringAssert.Contains(expectedString, result);
        }
        public void ReturnSuchIdDoesNotExist_WhenTownIsNotInTheRepository()
        {
            //Arrange
            var validParameters = new List <string>()
            {
                "street", "postalcode", "1"
            };
            var dbMock      = new Mock <IDatabase>();
            var factoryMock = new Mock <IModelsFactory>();

            var townRepositoryMock = new Mock <ITownRepository>();

            townRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Town, bool> > >())).Returns((Town)null);
            dbMock.Setup(d => d.Towns).Returns(townRepositoryMock.Object);

            var sut            = new CreateAddressCommand(dbMock.Object, factoryMock.Object);
            var expectedString = "such id doesn't exist";

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

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