public void ExecuteShould_ReturnCountryNameAlreadyExistsWhenCountryFoundInDB()
        {
            var countryName = "Mordor";
            var country     = new CountryMock()
            {
                Id = 1, Name = countryName
            };

            var providerMock = new Mock <ISqlServerDataProvider>();

            providerMock.Setup(p => p.Countries.Find(It.IsAny <Expression <Func <Country, bool> > >())).Returns(new List <CountryMock>()
            {
                country
            });

            var writerMock = new Mock <IWriter>();

            var command = new AddCountryCommand(providerMock.Object, writerMock.Object);

            string result = command.Execute(new List <string>()
            {
                countryName
            });

            Assert.That(result.Contains($"Country {countryName} already exists"));
        }
Esempio n. 2
0
        public void ExecuteShould_ReturnCitySuccessfullyAddedIfCityIsAddedToDB()
        {
            var countryName = "Mordor";
            var country     = new CountryMock()
            {
                Id = 1, Name = countryName
            };
            var cityName = "Varna";
            var city     = new CityMock()
            {
                Id = 1, Name = cityName, Country = country
            };

            var providerMock = new Mock <ISqlServerDataProvider>();

            providerMock.Setup(p => p.Countries.Find(It.IsAny <Expression <Func <Country, bool> > >())).Returns(new List <CountryMock>()
            {
                country
            });

            providerMock.Setup(p => p.Cities.Find(It.IsAny <Expression <Func <City, bool> > >())).Returns(new List <CityMock>()
            {
                null
            });

            providerMock.Setup(p => p.Cities.Add(It.IsAny <City>())).Verifiable();
            providerMock.Setup(p => p.UnitOfWork.Finished()).Verifiable();

            var writerMock = new Mock <IWriter>();
            var command    = new AddCityCommand(providerMock.Object, writerMock.Object);

            string result = command.Execute(new List <string>()
            {
                "Plovdiv", countryName
            });

            Assert.That(result.Contains($"City Plovdiv was successfully added"));
        }