public void CanGetAllRetailers()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetAllRetailers").Options;

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

                context.Add(retailer1);
                context.SaveChanges();

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

                context.Add(retailer2);
                context.SaveChanges();

                // Act
                List <Retailer> list = context.Retailers.ToList();

                // Assert
                Assert.Equal(list[1], retailer2);
            };
        }
        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);
            };
        }
        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);
            };
        }
        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);
            };
        }
        public void CanGetAllLocations()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetAllLocations").Options;

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

                context.Add(location1);
                context.SaveChanges();

                Location location2 = new Location();
                location2.ID   = 2;
                location2.Name = "Mt. St. Helens";

                context.Add(location2);
                context.SaveChanges();

                // Act
                List <Location> list = context.Locations.ToList();

                // Assert
                Assert.Equal(list[1], location2);
            };
        }
        public void CanGetAllRegions()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetAllRegions").Options;

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

                context.Add(region1);
                context.SaveChanges();

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

                context.Add(region2);
                context.SaveChanges();

                // Act
                List <Region> list = context.Regions.ToList();

                // Assert
                Assert.Equal(list[1], region2);
            };
        }
        public void CanGetRegion()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetRegion").Options;

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

                context.Add(region);
                context.SaveChanges();

                // Act
                var result = context.Regions.FirstOrDefault(r => r.Name == region.Name);

                // Assert
                Assert.Equal(result, region);
            };
        }
        public void CanGetLocation()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetLocation").Options;

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

                context.Add(location);
                context.SaveChanges();

                // Act
                var result = context.Locations.FirstOrDefault(loc => loc.Cost == location.Cost);

                // Assert
                Assert.Equal(result, location);
            };
        }
        public void CanGetRetailer()
        {
            DbContextOptions <RimRockApiDbContext> options = new DbContextOptionsBuilder <RimRockApiDbContext>().UseInMemoryDatabase("CanGetRetailer").Options;

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

                context.Add(retailer);
                context.SaveChanges();

                // Act
                var result = context.Retailers.FirstOrDefault(r => r.Specialty == retailer.Specialty);

                // Assert
                Assert.Equal(result, retailer);
            };
        }
        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);
            };
        }
        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);
            };
        }
        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);
            };
        }
 //DB set;
 public RetailerService(RimRockApiDbContext context)
 {
     _context = context;
 }
Exemple #14
0
 //DB set;
 public LocationService(RimRockApiDbContext context)
 {
     _context = context;
 }
 //DB set;
 public RegionService(RimRockApiDbContext context)
 {
     _context = context;
 }