Beispiel #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);
            };
        }
        public IEnumerable <FavLocation> getnearby([FromBody] Form formData)
        {
            using (var webClient = new WebClient())
            {
                webClient.Headers.Add("user-key", "<api key>");
                webClient.Headers.Add("Accept", "application/json");
                string url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + formData.latitude + "," + formData.longitude + "&radius=" + formData.radius + "&type=" + formData.type + "&key=<api key>";

                String             rawData = webClient.DownloadString(url);
                dynamic            json    = JsonConvert.DeserializeObject(rawData);
                List <FavLocation> nearloc = new List <FavLocation>();
                int i      = 1;
                int length = json.results.Count;
                if (json.status == "OK")
                {
                    foreach (var data in json.results)
                    {
                        FavLocation loc = new FavLocation();
                        loc.Latitude  = data.geometry.location.lat;
                        loc.Longitude = data.geometry.location.lng;
                        loc.PlaceName = data.name;
                        nearloc.Add(loc);
                    }
                }

                return(nearloc);
            }
        }
Beispiel #3
0
        public void CanGetFavLoctionCost()
        {
            // Arrange
            FavLocation favLocation = new FavLocation();

            // Assert
            Assert.Null(favLocation.Cost);
        }
Beispiel #4
0
        public void CanGetFavLoctionID()
        {
            // Arrange
            FavLocation favLocation = new FavLocation();

            // Assert
            Assert.Equal(0, favLocation.Id);
        }
Beispiel #5
0
        public void CanGetFavLoctionName()
        {
            // Arrange
            FavLocation favLocation = new FavLocation();


            // Assert
            Assert.Null(favLocation.Name);
        }
Beispiel #6
0
        public void CanSetFavLoctionCost()
        {
            // Arrange
            FavLocation favLocation = new FavLocation();

            // Act
            favLocation.Cost = "$$";

            // Assert
            Assert.Equal("$$", favLocation.Cost);
        }
Beispiel #7
0
        public async Task <IActionResult> PostGrocery([FromBody] FavLocation favlocation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.FavLocation.Add(favlocation);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFavLocation", new { id = favlocation.Id }, favlocation));
        }
Beispiel #8
0
        public void CanSetFavLoctionName()
        {
            // Arrange
            FavLocation favLocation = new FavLocation();


            // Act
            favLocation.Name = "Climbing Rock";

            // Assert
            Assert.Equal("Climbing Rock", favLocation.Name);
        }
Beispiel #9
0
        public void CanSetFavLoctionRegionId()
        {
            // Arrange
            FavLocation favLocation = new FavLocation();


            // Act
            favLocation.RegionId = 3;

            // Assert
            Assert.Equal(3, favLocation.RegionId);
        }
Beispiel #10
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);
            };
        }
Beispiel #11
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);
            };
        }
Beispiel #12
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();
        }