示例#1
0
        public void GetRestaurantRating()
        {
            //Arrange
            List <RestaurantRating> restaurantRatings = new List <RestaurantRating>();

            restaurantRatings.Add(new RestaurantRating()
            {
                RestaurantId  = 1,
                customerId    = 1,
                rating        = 2,
                user_Comments = "Not Bad",
            });
            var mockReview = new Mock <IReviewBusiness>();
            var mockLog    = new Mock <ILogService>();

            mockReview.Setup(x => x.GetRestaurantRating(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.GetResturantRating(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());
        }
示例#2
0
        public void ExceptionRestaurantRatingbyID()
        {
            //Arrange
            List <RestaurantRating> restaurantRatings = new List <RestaurantRating>();
            var mockReview = new Mock <IReviewBusiness>();
            var mockLog    = new Mock <ILogService>();

            mockReview.Setup(x => x.GetRestaurantRating(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"] = "aa";
            var data           = reviewcontroller.GetResturantRating(2);
            var exObjectResult = data as ObjectResult;

            //Assert
            Assert.AreEqual(500, exObjectResult.StatusCode);
        }