Пример #1
0
        public async Task CheckIfCountryExistsReturnsFalseIfCountryDoesntExists()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var addressesServiceMock = new Mock <IAddressesService>();
            var citiesRepository     = new EfDeletableEntityRepository <City>(dbContext);

            var repository        = new EfDeletableEntityRepository <Country>(dbContext);
            var citiesServiceMock = new Mock <CitiesService>(citiesRepository, addressesServiceMock.Object);

            var service = new CountriesService(repository, citiesServiceMock.Object);
            var country = new Country()
            {
                Id = 1,
            };

            dbContext.Add(country);
            await dbContext.SaveChangesAsync();

            var result = await service.CheckIfCountryExists(2);

            Assert.False(result);
        }