Esempio n. 1
0
        public async Task GetAllAsyncWorksCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var addressesService = new Mock <IAddressesService>();

            var repository = new EfDeletableEntityRepository <City>(dbContext);

            var service = new CitiesService(repository, addressesService.Object);
            var city    = new City()
            {
                Id        = 1,
                CountryId = 1,
            };

            var city2 = new City()
            {
                Id        = 2,
                CountryId = 1,
            };

            var city3 = new City()
            {
                Id        = 3,
                CountryId = 2,
            };

            dbContext.Add(city);
            dbContext.Add(city2);
            dbContext.Add(city3);
            await dbContext.SaveChangesAsync();

            var result = await service.GetAllAsync <CityServiceModel>();

            Assert.Equal(3, result.Count());
        }