Пример #1
0
        public async void GetLocations_CanGetAllLocationsAsList()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetAllLocationsAsList").Options;

            using (RimRockApiDbContext context = new RimRockApiDbContext(options))
            {
                // Arrange
                Location location1 = new Location();
                location1.ID   = 1;
                location1.Name = "Mt. St. Helens";
                location1.Cost = "$";

                Location location2 = new Location();
                location2.ID   = 2;
                location2.Name = "Mt. Baker";
                location2.Cost = "$$";

                // Act
                LocationService locationService = new LocationService(context);
                await context.Locations.AddAsync(location1);

                await context.Locations.AddAsync(location2);

                await context.SaveChangesAsync();

                List <Location> list = await locationService.GetLocations();

                // Assert
                Assert.Equal(list[1], location2);
            };
        }
Пример #2
0
        public async void GetRetailers_CanGetAllRetailersAsList()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetAllRetailersAsList").Options;

            using (RimRockApiDbContext context = new RimRockApiDbContext(options))
            {
                // Arrange
                Retailer retailer1 = new Retailer();
                retailer1.ID   = 1;
                retailer1.Name = "Second Ascents";

                Retailer retailer2 = new Retailer();
                retailer2.ID   = 2;
                retailer2.Name = "Play It Again Sports";

                // Act
                RetailerService retailerService = new RetailerService(context);
                await context.Retailers.AddAsync(retailer1);

                await context.Retailers.AddAsync(retailer2);

                await context.SaveChangesAsync();

                List <Retailer> list = await retailerService.GetRetailers();

                // Assert
                Assert.Equal(list[1], retailer2);
            };
        }
Пример #3
0
        public async void GetRegions_CanGetAllRegionsAsList()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetAllRegionsAsList").Options;

            using (RimRockApiDbContext context = new RimRockApiDbContext(options))
            {
                // Arrange
                Region region1 = new Region();
                region1.ID   = 1;
                region1.Name = "Paris";

                Region region2 = new Region();
                region2.ID   = 2;
                region2.Name = "Bretagne";

                // Act
                RegionService regionService = new RegionService(context);
                await context.Regions.AddAsync(region1);

                await context.Regions.AddAsync(region2);

                await context.SaveChangesAsync();

                List <Region> list = await regionService.GetRegions();

                // Assert
                Assert.Equal(list[1], region2);
            };
        }
Пример #4
0
        public async void GetRetailer_CanGetSingleRetailer()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetSingleRetailer").Options;

            using (RimRockApiDbContext context = new RimRockApiDbContext(options))
            {
                // Arrange
                Retailer retailer = new Retailer();
                retailer.ID   = 1;
                retailer.Name = "Backcountry Essentials";

                // Act
                RetailerService retailerService = new RetailerService(context);
                await context.Retailers.AddAsync(retailer);

                await context.SaveChangesAsync();

                Retailer result = await retailerService.GetRetailer(retailer.ID);

                // Assert
                Assert.Equal(result, retailer);
            };
        }
Пример #5
0
        public async void GetRegion_CanGetSingleRegion()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetSingleRegion").Options;

            using (RimRockApiDbContext context = new RimRockApiDbContext(options))
            {
                // Arrange
                Region region = new Region();
                region.ID   = 1;
                region.Name = "The Palouse";

                // Act
                RegionService regionService = new RegionService(context);
                await context.Regions.AddAsync(region);

                await context.SaveChangesAsync();

                Region result = await regionService.GetRegion(region.ID);

                // Assert
                Assert.Equal(result, region);
            };
        }
Пример #6
0
        public async void GetLocation_CanGetSingleLocation()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetSingleLocation").Options;

            using (RimRockApiDbContext context = new RimRockApiDbContext(options))
            {
                // Arrange
                Location location = new Location();
                location.ID   = 1;
                location.Name = "Second Ascents";
                location.Cost = "$$";

                // Act
                LocationService locationService = new LocationService(context);
                await context.Locations.AddAsync(location);

                await context.SaveChangesAsync();

                Location result = await locationService.GetLocation(location.ID);

                // Assert
                Assert.Equal(result, location);
            };
        }