Exemple #1
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 #2
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 #3
0
        public async void CreateFavLocation_CanAddNewFavLocationInDatabase()
        {
            DbContextOptions <RimrockDBContext> options = new DbContextOptionsBuilder <RimrockDBContext>().UseInMemoryDatabase("CanCreateNewFavLocation").Options;

            using (RimrockDBContext context = new RimrockDBContext(options))
            {
                // Arrange
                FavLocation favLocation = new FavLocation();
                favLocation.Id   = 1;
                favLocation.Name = "Yosemite";
                favLocation.Cost = "$$";

                // Act
                FavLocationService favLocService = new FavLocationService(context);

                await favLocService.CreateFavLocation(favLocation);

                FavLocation favLocationFromDb = await context.FavLocations
                                                .FirstOrDefaultAsync(fl => fl.Name == favLocation.Name);

                // Assert
                Assert.Equal(favLocationFromDb, favLocation);
            };
        }