Esempio n. 1
0
        public void ExceptionRestaurantRatingByCustomerID()
        {
            //Arrange
            List <RestaurantRating> restaurantRatings = new List <RestaurantRating>();

            restaurantRatings.Add(new RestaurantRating()
            {
                RestaurantId  = 1,
                customerId    = 1,
                rating        = 5,
                user_Comments = "Good",
            });
            var mockOrder  = new Mock <IReviewBusiness>();
            var mockOrder1 = new Mock <ILogService>();

            mockOrder.Setup(x => x.GetRestaurantRatingByCustomer(It.IsAny <int>())).Returns(restaurantRatings.AsQueryable());
            mockOrder1.Setup(x => x.LogMessage("GetRestaurentRatingbyCustomerID Test case"));
            //Act
            var reviewcontroller = new ReviewController(mockOrder.Object, mockOrder1.Object);

            reviewcontroller.ControllerContext             = new ControllerContext();
            reviewcontroller.ControllerContext.HttpContext = new DefaultHttpContext();
            reviewcontroller.ControllerContext.HttpContext.Request.Headers["CustomerId"] = "abc";
            var data = reviewcontroller.GetResturantRatingByCustomerID(2);
            var exceptionObjectResult = data as ObjectResult;

            //Assert
            Assert.AreEqual(500, exceptionObjectResult.StatusCode);
        }
Esempio n. 2
0
        public void GetRestaurantRatingByCustomerID()
        {
            //Arrange
            List <RestaurantRating> restaurantRatings = new List <RestaurantRating>();

            restaurantRatings.Add(new RestaurantRating()
            {
                RestaurantId  = 1,
                customerId    = 1,
                rating        = 8,
                user_Comments = "Good",
            });
            var mockOrder  = new Mock <IReviewBusiness>();
            var mockOrder1 = new Mock <ILogService>();

            mockOrder.Setup(x => x.GetRestaurantRatingByCustomer(It.IsAny <int>())).Returns(restaurantRatings.AsQueryable());
            mockOrder1.Setup(x => x.LogMessage("GetRestaurentRatingbyCustomerID Test case"));
            //Act
            var reviewcontroller = new ReviewController(mockOrder.Object, mockOrder1.Object);

            reviewcontroller.ControllerContext             = new ControllerContext();
            reviewcontroller.ControllerContext.HttpContext = new DefaultHttpContext();
            reviewcontroller.ControllerContext.HttpContext.Request.Headers["CustomerId"] = "1";
            var data           = reviewcontroller.GetResturantRatingByCustomerID(1);
            var okObjectResult = data as OkObjectResult;

            //Assert
            Assert.AreEqual(200, okObjectResult.StatusCode);
            Assert.IsNotNull(okObjectResult);
            Assert.AreEqual((okObjectResult.Value as IEnumerable <RestaurantRating>).Count(), restaurantRatings.Count());
        }
Esempio n. 3
0
        public void NotFoundRestaurantRatingbyCustomerID()
        {
            //Arrange
            List <RestaurantRating> restaurantRatings = new List <RestaurantRating>();
            var mockReview = new Mock <IReviewBusiness>();
            var mockLog    = new Mock <ILogService>();

            mockReview.Setup(x => x.GetRestaurantRatingByCustomer(It.IsAny <int>())).Returns(restaurantRatings.AsQueryable());
            mockLog.Setup(x => x.LogMessage("GetRestaurentRating Test case"));
            //Act
            var reviewcontroller = new ReviewController(mockReview.Object, mockLog.Object);

            reviewcontroller.ControllerContext             = new ControllerContext();
            reviewcontroller.ControllerContext.HttpContext = new DefaultHttpContext();
            reviewcontroller.ControllerContext.HttpContext.Request.Headers["CustomerId"] = "1";
            var data = reviewcontroller.GetResturantRatingByCustomerID(2);
            var notFoundObjectResult = data as NotFoundObjectResult;

            //Assert
            Assert.AreEqual(404, notFoundObjectResult.StatusCode);
        }