public void ThrowEntityDoesntExistException_WhenCityDoesNotExist()
        {
            //Arrange
            unitOfWork.Setup(x => x.Cities).Returns(cityRepoMock.Object);

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

            Assert.ThrowsException <EntityDoesntExistException>(() => command.DeleteCity(testCityName));
        }
        public void ThrowEntityDoesntExistException_WhenCityIsDeleted()
        {
            //Arrange
            cityMock.Object.IsDeleted = true;

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

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

            Assert.ThrowsException <EntityDoesntExistException>(() => command.DeleteCity(testCityName));
        }
        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);
            }
        }
        public void DeleteCity_WhenCityExists()
        {
            //Arrange
            cityMock.Object.IsDeleted = false;

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

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

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

            command.DeleteCity(cityMock.Object.Name);

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