예제 #1
0
        public void ThrowArgumentException_WhenCityNameLengthIsNotInRange()
        {
            //Arrange
            int maxCityNameLength = 50;
            var longCityName      = new string('c', maxCityNameLength + 1);

            var cityService = new CityServices(unitOfWork.Object);

            //Act and Assert
            Assert.ThrowsException <ArgumentException>(() => cityService.AddNewCity(longCityName));
        }
예제 #2
0
        public void ThrowEntityAlreadyExistsException_WhenCityExist()
        {
            //Arrange
            unitOfWork.Setup(x => x.Cities).Returns(cityRepoMock.Object);
            cityRepoMock.Setup(repo => repo.AllAndDeleted()).Returns(predifinedListOfCities.AsQueryable());

            //Act and Assert
            var addCityCommand = new CityServices(unitOfWork.Object);

            Assert.ThrowsException <EntityAlreadyExistsException>(() => addCityCommand.AddNewCity(testCityName));
        }
예제 #3
0
        public void UnmarkCityAsDeleted_WhenCityExistButIsDeleted()
        {
            //Arrange
            city.IsDeleted = true;

            unitOfWork.Setup(x => x.Cities).Returns(cityRepoMock.Object);
            cityRepoMock.Setup(repo => repo.AllAndDeleted()).Returns(predifinedListOfCities.AsQueryable());

            //Act
            var addCityCommand = new CityServices(unitOfWork.Object);

            addCityCommand.AddNewCity(testCityName);

            //Assert
            Assert.IsFalse(city.IsDeleted);
        }
예제 #4
0
        public void CityServices_ShouldDeleteCity_WhenPassedValidParameter()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "CityServices_ShouldDeleteCity_WhenPassedValidParameter")
                                 .Options;

            City city = new City()
            {
                Name        = "TestName",
                Id          = 1,
                IsDeleted   = false,
                Projections = new List <Projection>()
            };

            var unitOfWorkMock = new Mock <IUnitOfWork>();


            // Act
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                var cityServicesRepo = new Repository <City>(actContext);
                unitOfWorkMock
                .Setup(u => u.Cities)
                .Returns(cityServicesRepo);

                var sut = new CityServices(unitOfWorkMock.Object);

                sut.AddNewCity(city.Name);                 // first add a city
                sut.DeleteCity(city.Name);
            }

            // Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                Assert.IsTrue(assertContext.Cities.Count() == 1);
                Assert.AreEqual(assertContext.Cities.FirstOrDefault().IsDeleted, true);
            }
        }
예제 #5
0
        public void CallAddMethodOnCities_WhenParametersAreCorrect()
        {
            //Arrange
            var cityMock = new Mock <City>();

            unitOfWork.Setup(x => x.Cities).Returns(cityRepoMock.Object);

            cityRepoMock
            .Setup(repo => repo.Add(It.IsAny <City>()))
            .Callback <City>((city) =>
            {
                predifinedListOfCities.Add(cityMock.Object);
            });

            //Act
            var addCityCommand = new CityServices(unitOfWork.Object);

            addCityCommand.AddNewCity(testCityName);

            //Assert
            Assert.AreEqual(2, predifinedListOfCities.Count);
        }