Exemple #1
0
        public async void DeleteFavRetailer_CanDeleteFavRetailerById()
        {
            DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanDeleteFavRetailerById").Options;

            using (RimrockDBContext context = new RimrockDBContext(options))
            {
                // Arrange
                FavRetailer newFavRetailer = new FavRetailer();
                newFavRetailer.Id        = 1;
                newFavRetailer.Name      = "Second Ascents";
                newFavRetailer.Specialty = "Climbing";

                // Act
                FavRetailerService favRetailerService = new FavRetailerService(context);

                await context.FavRetailers.AddAsync(newFavRetailer);

                await context.SaveChangesAsync();

                // Act
                await favRetailerService.DeleteFavRetailer(1);

                List <FavRetailer> listOfRetailersInDb = await context.FavRetailers.Where(fr => fr.UserId == newFavRetailer.Id).ToListAsync();

                // Assert
                Assert.Empty(listOfRetailersInDb);
            };
        }
Exemple #2
0
        public async void DeleteFavLocation_CanDeleteFavLocationById()
        {
            DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanDeleteFavLocById").Options;

            using (RimrockDBContext context = new RimrockDBContext(options))
            {
                // Arrange
                FavLocation newFavLocation = new FavLocation();
                newFavLocation.Id       = 1;
                newFavLocation.UserId   = 1;
                newFavLocation.RegionId = 2;
                newFavLocation.Name     = "Grand Teton";
                newFavLocation.Cost     = "$$";

                FavLocationService favLocService = new FavLocationService(context);

                await context.FavLocations.AddAsync(newFavLocation);

                await context.SaveChangesAsync();

                // Act
                await favLocService.DeleteFavLocation(1);

                List <FavLocation> listOfLocationsInDb = await context.FavLocations.Where(fl => fl.UserId == newFavLocation.Id).ToListAsync();

                // Assert
                Assert.Empty(listOfLocationsInDb);
            };
        }
Exemple #3
0
        public async void GetFavRetailer_CanGetFavRetailerById(int numForFavRetailerId, int numToTest, int numForUserId, bool expectedBool)
        {
            DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanGetFavRetailerById").Options;

            using (RimrockDBContext context = new RimrockDBContext(options))
            {
                // Arrange
                FavRetailer newFavRetailer = new FavRetailer();
                newFavRetailer.Id        = numForFavRetailerId;
                newFavRetailer.UserId    = numForUserId;
                newFavRetailer.RegionId  = 2;
                newFavRetailer.Name      = "Grand Teton";
                newFavRetailer.Specialty = "Mountaineering";

                FavRetailerService favRetailerService = new FavRetailerService(context);

                await context.FavRetailers.AddAsync(newFavRetailer);

                await context.SaveChangesAsync();

                // Act
                List <FavRetailer> favRetailerListFromDb = await favRetailerService.GetFavRetailers(newFavRetailer.UserId);

                // Boolean test (needed for Theory-type unit test)
                bool actualBool = false;
                if (numToTest == favRetailerListFromDb[0].UserId)
                {
                    actualBool = true;
                }

                // Assert
                Assert.Equal(actualBool, expectedBool);
            };
        }
Exemple #4
0
        public async void GetFavLocation_CanGetFavLocationById
        (
            int numForFavLocId,
            int numToTest,
            int numForUserId,
            bool expectedBool
        )
        {
            DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanGetFavLocById").Options;

            using (RimrockDBContext context = new RimrockDBContext(options))
            {
                // Arrange
                FavLocation newFavLocation = new FavLocation();
                newFavLocation.Id       = numForFavLocId;
                newFavLocation.UserId   = numForUserId;
                newFavLocation.RegionId = 2;
                newFavLocation.Name     = "Grand Teton";
                newFavLocation.Cost     = "$$";

                FavLocationService favLocService = new FavLocationService(context);

                await context.FavLocations.AddAsync(newFavLocation);

                await context.SaveChangesAsync();

                // Act
                List <FavLocation> favLocationListFromDb = await favLocService.GetFavLocations(newFavLocation.UserId);

                // Boolean test (needed for Theory-type unit test)
                bool actualBool = false;
                if (numToTest == favLocationListFromDb[0].UserId)
                {
                    actualBool = true;
                }

                // Assert
                Assert.Equal(actualBool, expectedBool);
            };
        }
Exemple #5
0
        public async void GetUser_CanGetSingleUser()
        {
            DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanGetSingleUserByName").Options;

            using (RimrockDBContext context = new RimrockDBContext(options))
            {
                // Arrange
                User newUser = new User();
                newUser.ID   = 1;
                newUser.Name = "Jason Burns";

                // Act
                UserService userService = new UserService(context);
                await context.Users.AddAsync(newUser);

                await context.SaveChangesAsync();

                User userFromDb = await userService.GetUser(newUser.Name);

                // Assert
                Assert.Equal(userFromDb, newUser);
            };
        }
Exemple #6
0
        /// <summary>
        /// Adds new user to DB
        /// </summary>
        /// <param name="user">User object to save to DB</param>
        /// <returns>Task object</returns>
        public async Task CreateUser(User user)
        {
            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();
        }
        /// <summary>
        /// Saves new favorited retailer to DB
        /// </summary>
        /// <param name="favRetailer">object containing favorited retailer</param>
        /// <returns>Task</returns>
        public async Task CreateFavRetailer(FavRetailer favRetailer)
        {
            await _context.FavRetailers.AddAsync(favRetailer);

            await _context.SaveChangesAsync();
        }
Exemple #8
0
        /// <summary>
        /// Saves new favorited location to DB
        /// </summary>
        /// <param name="favLocation">favorited location to save</param>
        /// <returns>Task</returns>
        public async Task CreateFavLocation(FavLocation favLocation)
        {
            await _context.FavLocations.AddAsync(favLocation);

            await _context.SaveChangesAsync();
        }