Esempio n. 1
0
        public async Task GetByCountryIdWithTeamsWithServicesGenericWorksCorrectly()
        {
            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,
                Teams     = new List <Team>()
                {
                    new Team()
                    {
                        Services = new List <TeamService>()
                        {
                            new TeamService()
                        }
                    }
                },
            };

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

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

            var cities = await service.GetByCountryIdAsync(1, true);

            Assert.Single(cities);
        }
Esempio n. 2
0
        public async Task GetByCountryIdGenericWorksCorrectly()
        {
            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 cities = await service.GetByCountryIdAsync <CityServiceModel>(1);

            Assert.Equal(2, cities.Count());
        }