Exemplo n.º 1
0
        public void CompleteUpdateRestaurant_ValidIDUpdateCuisine_Succeed()
        {
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });
            var expectedID          = 2;
            var expectedName        = "Restaurant Two";
            var expectedCuisine     = Cuisines[2].Id;
            var expectedCreatedById = 102;
            var expectedUpdatedById = 103;
            var restToUpdate        = new UpdateRestaurantRequestModel
            {
                UserId       = 103,
                RestaurantId = expectedID,
                Name         = expectedName,
                CuisineId    = expectedCuisine
            };
            var updateRestTran = new CompleteUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            var expectedResponse = new UpdateRestaurantResponseModel {
                WasSucessfull = true
            };

            //act
            updateRestTran.Execute();
            var actualResponse = updateRestTran.Response;

            //assert
            Assert.AreEqual(expectedResponse.WasSucessfull, actualResponse.WasSucessfull, "Invalid execution status");

            ValidateRestUpdate(expectedID, expectedName, expectedCuisine, expectedCreatedById, expectedUpdatedById, restToUpdate);
        }
        public void PartialUpdateRestaurant_NonExistingID_Fail()
        {
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });
            var restToUpdate = new UpdateRestaurantRequestModel
            {
                UserId       = 103,
                RestaurantId = 200,
                Name         = "New Name"
            };
            var expectedResponse = new UpdateRestaurantResponseModel {
                WasSucessfull = false
            };

            var updateRestTran = new PartialUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            //act
            updateRestTran.Execute();
            var actualResponse = updateRestTran.Response;

            //assert
            Assert.AreEqual(expectedResponse.WasSucessfull, actualResponse.WasSucessfull, "Invalid execution status");
        }
Exemplo n.º 3
0
        public void PatchRestaurant_ValidData_OK()
        {
            //arrange
            var originalCuisineName    = "Indian";
            var originalCuisineId      = 1;
            var originalRestaurantName = "No1 Indian Restaurant";
            var updatedRestaurantName  = "World Cafe";
            var restaruantIdToUpdate   = 155;
            var createdUser            = 10;
            var callingUserId          = 10;
            var originalCuisine        = new Cuisine
            {
                Name      = originalCuisineName,
                Id        = originalCuisineId,
                CreatedBy = createdUser,
                UpdatedBy = createdUser
            };

            var restaurantBeforeUpdate = new Restaurant
            {
                Id        = restaruantIdToUpdate,
                CreatedBy = createdUser,
                UpdatedBy = createdUser,
                Cuisine   = originalCuisine,
                Name      = originalRestaurantName
            };

            var requestModel = new API.ViewModels.Restaurant
            {
                Id   = restaruantIdToUpdate,
                Name = updatedRestaurantName,
            };

            var transactionRequest = new UpdateRestaurantRequestModel
            {
                RestaurantId = restaruantIdToUpdate,
                Name         = updatedRestaurantName,
                UserId       = callingUserId
            };

            MockRepository.Setup(m => m.UpdateRestaurant(transactionRequest));
            MockRepository.Setup(m => m.DoseCuisineIdExist(It.IsAny <int>())).Returns(true);
            MockRepository.Setup(m => m.GetRestaurantById(restaruantIdToUpdate)).Returns(restaurantBeforeUpdate);
            MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(callingUserId);

            var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object);

            //act
            var actionResult  = ctrl.Patch(restaruantIdToUpdate, requestModel);
            var contentResult = actionResult as OkNegotiatedContentResult <API.ViewModels.Restaurant>;

            //assert
            Assert.IsNotNull(contentResult, "ok -200 status was not returned");
            //Assert.AreEqual(HttpStatusCode..Accepted, responseRestaurants.StatusCode);
            //TODO: must check if se should return 201-accepted, 200-ok(with body) or 204 (ok with no content)
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(restaruantIdToUpdate, contentResult.Content.Id);
        }
Exemplo n.º 4
0
        public void CompleteUpdateRestaurant_WithExistingReviews_Succeed()
        {
            Users.Add(new User {
                Id = 1, FirstName = "Ruchira", LastName = "Kumara", UserName = "******"
            });
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });

            var expectedCuisine     = Cuisines[0].Id;
            var expectedCreatedById = 102;
            var expectedUpdatedById = Users[0].Id;

            Restaurants[1].AddReview(new Review
            {
                CreatedBy      = 4,
                UpdatedBy      = 4,
                Comment        = "First Comment for 3",
                Rating         = 3,
                PostedDateTime = new DateTime(2016, 10, 16),
                ReviewNumber   = 2,
                ReviewUser     = Users[0]
            });
            Restaurants[1].AddReview(new Review
            {
                CreatedBy      = 3,
                UpdatedBy      = 3,
                Comment        = "Second Comment for 3",
                Rating         = 5,
                PostedDateTime = new DateTime(2016, 10, 10),
                ReviewNumber   = 3,
                ReviewUser     = Users[0]
            });

            var expectedID   = 2;
            var expectedName = "New Restaurant Name";
            var restToUpdate = new UpdateRestaurantRequestModel
            {
                UserId       = expectedUpdatedById,
                CuisineId    = expectedCuisine,
                RestaurantId = expectedID,
                Name         = expectedName
            };
            var updateRestTran = new CompleteUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            //act
            updateRestTran.Execute();
            var actualResponse = updateRestTran.Response;

            Assert.AreEqual(true, actualResponse.WasSucessfull, "Invalid response");
            ValidateRestUpdate(expectedID, expectedName, expectedCuisine, expectedCreatedById, expectedUpdatedById, restToUpdate);
        }
Exemplo n.º 5
0
        private void FakeUpdateRestaurant(UpdateRestaurantRequestModel updateRestaurantRequestModel)
        {
            var cuisineRef       = Cuisines[updateRestaurantRequestModel.CuisineId - 1];
            var findRestToUpdate = Restaurants.Find(r => r.Id == updateRestaurantRequestModel.RestaurantId);

            if (findRestToUpdate != null)
            {
                findRestToUpdate.Cuisine   = cuisineRef;
                findRestToUpdate.Name      = updateRestaurantRequestModel.Name;
                findRestToUpdate.UpdatedBy = updateRestaurantRequestModel.UserId;
            }
        }
        private UpdateRestaurantRequestModel CreateUpdateRestaurantRequestModel(int restaurantId, string name, int cuisineId)
        {
            var reqModel = new UpdateRestaurantRequestModel
            {
                RestaurantId = restaurantId,
                Name         = name,
                CuisineId    = cuisineId,
                UserId       = _identity.GetRequestingUserId()
            };

            return(reqModel);
        }
Exemplo n.º 7
0
        public void UpdateRestaurant(UpdateRestaurantRequestModel request)
        {
            var relatedCuisine   = GetCuisineById(request.CuisineId);
            var findRestToUpdate = Restaurants.Find(r => r.Id == request.RestaurantId);

            if (findRestToUpdate != null)
            {
                findRestToUpdate.Cuisine   = relatedCuisine;
                findRestToUpdate.Name      = request.Name;
                findRestToUpdate.UpdatedBy = request.UserId;
            }
        }
Exemplo n.º 8
0
        public void UpdateRestaurant(UpdateRestaurantRequestModel request)
        {
            var restaurantFound = _restaurantDbContex.Restaurants.FirstOrDefault <Sql.Restaurant>(r => r.Id == request.RestaurantId);

            if (restaurantFound != null)
            {
                restaurantFound.CuisineId   = request.CuisineId;
                restaurantFound.Name        = request.Name;
                restaurantFound.UpdatedBy   = request.UserId;
                restaurantFound.UpdatedDate = DateTime.Now;

                _restaurantDbContex.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public void CompleteUpdateRestaurant_NonExistingID_Fail()
        {
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });
            var restToUpdate = new UpdateRestaurantRequestModel
            {
                UserId       = 103,
                RestaurantId = 200,
                Name         = "New Name"
            };

            var updateRestTran = new CompleteUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            //act
            updateRestTran.Execute();
        }
Exemplo n.º 10
0
        public void CompleteUpdateRestaurant_ValidIDWithBlankUpdatePaddedName_Succeed()
        {
            Restaurants.Add(new Restaurant {
                Id = 1, CreatedBy = 101, UpdatedBy = 101, Cuisine = Cuisines[0], Name = "Restaurant one"
            });
            Restaurants.Add(new Restaurant {
                Id = 2, CreatedBy = 102, UpdatedBy = 102, Cuisine = Cuisines[1], Name = "Restaurant Two"
            });
            var expectedID   = 2;
            var expectedName = "New Restaurant Name";
            var restToUpdate = new UpdateRestaurantRequestModel
            {
                UserId       = 103,
                RestaurantId = expectedID,
                Name         = "  " + expectedName + "   "
            };
            var updateRestTran = new CompleteUpdateRestaurantTransaction(Repo, Log, restToUpdate);

            //act
            updateRestTran.Execute();
        }
Exemplo n.º 11
0
        public void PatchRestaurant_DatabaseException_BadData()
        {
            //arrange
            var updatedCuisineName    = "Mexican";
            var updatedCuisineId      = 10;
            var updatedRestaurantName = "World Cafe";
            var restaruantIdToUpdate  = 155;
            var callingUserId         = 10;

            var requestModel = new API.ViewModels.Restaurant
            {
                Id          = restaruantIdToUpdate,
                CuisineName = updatedCuisineName,
                CuisineId   = updatedCuisineId,
                Name        = updatedRestaurantName,
            };

            var transactionRequest = new UpdateRestaurantRequestModel
            {
                RestaurantId = restaruantIdToUpdate,
                CuisineId    = updatedCuisineId,
                Name         = updatedRestaurantName,
                UserId       = callingUserId
            };


            MockRepository.Setup(m => m.UpdateRestaurant(transactionRequest))
            .Throws(new Exception());
            MockRepository.Setup(m => m.GetRestaurantById(restaruantIdToUpdate))
            .Throws(new Exception());
            MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10);

            var ctrl = new RestaurantsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object);

            //act
            var actionResult = ctrl.Patch(restaruantIdToUpdate, requestModel);

            // assert
            Assert.IsInstanceOfType(actionResult, typeof(BadRequestResult));
        }
Exemplo n.º 12
0
 public PartialUpdateRestaurantTransaction(IRepository repo, IApplicationLog log, UpdateRestaurantRequestModel reqeustModel) :
     base(repo, log, reqeustModel)
 {
 }
Exemplo n.º 13
0
        private void ValidateRestUpdate(int expectedId, string expectedName, int expectedCuisine, int expectedCreatedById, int expectedUpdatedById, UpdateRestaurantRequestModel restToUpdate)
        {
            var actualRest = Restaurants.Find(r => r.Id == restToUpdate.RestaurantId);

            Assert.IsNotNull(actualRest, "Update restaurant not found");
            Assert.AreEqual(expectedId, actualRest.Id, "Restaurant ID");
            Assert.AreEqual(expectedName, actualRest.Name, "Restaurant Name");
            Assert.AreEqual(expectedCuisine, actualRest.Cuisine.Id, "Restaurant CuisineId");
            Assert.AreEqual(expectedCreatedById, actualRest.CreatedBy, "Restaurant Created By");
            Assert.AreEqual(expectedUpdatedById, actualRest.UpdatedBy, "Restaurant Updated by");
        }