示例#1
0
        public async Task Dd_Get5BestScore_ListRestaurantBefore_ReturnList5BestScoredRestaurant()
        {
            //Arrange
            var restaurantService = new RestaurantService();

            restaurantsToDelete.Add(new Restaurant()
            {
                Grade = new Grade()
                {
                    Score = 1
                }
            });
            restaurantService.Create(restaurantsToDelete.Last());
            restaurantsToDelete.Add(new Restaurant()
            {
                Grade = new Grade()
                {
                    Score = 3
                }
            });
            restaurantService.Create(restaurantsToDelete.Last());
            restaurantsToDelete.Add(new Restaurant()
            {
                Grade = new Grade()
                {
                    Score = 5
                }
            });
            restaurantService.Create(restaurantsToDelete.Last());
            restaurantsToDelete.Add(new Restaurant()
            {
                Grade = new Grade()
                {
                    Score = 8
                }
            });
            restaurantService.Create(restaurantsToDelete.Last());
            restaurantsToDelete.Add(new Restaurant()
            {
                Grade = new Grade()
                {
                    Score = 9
                }
            });
            restaurantService.Create(restaurantsToDelete.Last());
            var restosBefore = restaurantService.GetAll();

            //Act
            var result = restaurantService.Get5BestScore();

            //Assert
            //Assert.AreEqual(9, result.First().Grade.Score);
            Assert.AreNotEqual(restosBefore.First(), result.First());

            //Clean up database
            await deleteTestResto();
        }
示例#2
0
        public async Task E_Update_EditNameRestaurant_NameRestaurantChangeInDb()
        {
            //Arrange
            var restaurantService = new RestaurantService();
            var restaurant        = new Restaurant()
            {
                ID = new Guid("10000000-0000-0000-0000-000000000000"), Name = "TestUpgarde", Grade = new Grade()
                {
                    Score = 1
                }
            };

            restaurantsToDelete.Add(restaurant);
            restaurantService.Create(restaurantsToDelete.First());

            restaurant.Name           = "updateTest";
            restaurant.Grade.Score    = 5;
            restaurant.Address.Street = "test";

            //Act
            await restaurantService.Update(restaurant);

            var updateResto = restaurantService.GetAll().Where(e => e.ID == restaurant.ID).FirstOrDefault();

            //Assert
            Assert.AreEqual(restaurant.Name, updateResto.Name);
            Assert.AreEqual(restaurant.Grade.Score, updateResto.Grade.Score);
            Assert.AreEqual(restaurant.Address.Street, updateResto.Address.Street);

            //Clean up database
            await deleteTestResto();
        }
示例#3
0
        public async Task Db_GetByScore_TakeAScore_1RestaurantScore5()
        {
            //Arrange
            var restaurantService = new RestaurantService();

            restaurantsToDelete.Add(new Restaurant()
            {
                Grade = new Grade()
                {
                    Score = 1
                }
            });
            restaurantService.Create(restaurantsToDelete.Last());
            restaurantsToDelete.Add(new Restaurant()
            {
                Grade = new Grade()
                {
                    Score = 5
                }
            });
            restaurantService.Create(restaurantsToDelete.Last());
            restaurantsToDelete.Add(new Restaurant()
            {
                Grade = new Grade()
                {
                    Score = 8
                }
            });
            restaurantService.Create(restaurantsToDelete.Last());

            //Act
            var result = restaurantService.GetByScore(5);

            //Assert
            //Assert.AreEqual(1, result.Count());
            Assert.AreEqual(5, result.First().Grade.Score);

            //Clean up database
            await deleteTestResto();
        }
        public ActionResult <Restaurant> AddRestaurantAsync(Restaurant restaurant)
        {
            //_restaurantDBContext.Restaurant.InsertOne(restaurant);

            //return CreatedAtRoute("GetRestaurants", new { id = restaurant.RestaurentId.ToString() }, restaurant);
            if (ModelState.IsValid)
            {
                _restaurantService.Create(restaurant);
                return(CreatedAtRoute("GetRestaurants", new { id = restaurant.id.ToString() }, restaurant));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
示例#5
0
        public async Task Da_GetAll_AddARestaurant_NotNull()
        {
            //Arrange
            var restaurantService = new RestaurantService();
            var countBefore       = restaurantService.GetAll().Count();

            restaurantsToDelete.Add(new Restaurant());
            restaurantService.Create(restaurantsToDelete.Last());

            //Act
            var result = restaurantService.GetAll();

            //Assert
            Assert.AreNotEqual(countBefore, result);

            //Clean up database
            await deleteTestResto();
        }
示例#6
0
        public async Task F_Delete_TakeFirstRestaurant_OneLessRestaurantInDb()
        {
            //Arrange
            var restaurantService = new RestaurantService();

            restaurantsToDelete.Add(new Restaurant()
            {
                ID = new Guid("11000000-0000-0000-0000-000000000000")
            });
            restaurantService.Create(restaurantsToDelete.First());
            var count = restaurantService.GetAll().Count();

            //Act
            await restaurantService.Delete(restaurantsToDelete.First().ID);

            //Assert
            Assert.AreNotEqual(count, restaurantService.GetAll().Count());
        }
示例#7
0
        public async Task C_Create_ANewRestaurant_NewRestaurantInDb()
        {
            //Arrange
            var resto = new Restaurant();

            restaurantsToDelete.Add(resto);

            var restaurantService = new RestaurantService();
            var count             = restaurantService.GetAll().Count();

            //Act
            restaurantService.Create(resto);

            //Assert
            Assert.AreNotEqual(count, restaurantService.GetAll().Count());

            //Clean up database
            await deleteTestResto();
        }
示例#8
0
        public async Task G_GetByID_TakeFirstRestaurant_ReturnSameRestaurant()
        {
            //Arrange
            var restaurantService = new RestaurantService();

            restaurantsToDelete.Add(new Restaurant()
            {
                ID = Guid.NewGuid()
            });
            restaurantService.Create(restaurantsToDelete.First());

            //Act
            var result = restaurantService.GetById(restaurantsToDelete.First().ID);

            //Assert
            Assert.AreEqual(restaurantsToDelete.First().ID, result.ID);

            //Clean up database
            await deleteTestResto();
        }