Exemplo n.º 1
0
        public void TestAddReview()
        {
            //Arrange
            List <Review> reviews = new List <Review>
            {
                new Review(DateTime.Now, "Great Movie", "Simon", 4),
                new Review(DateTime.Now, "Excellent", "Henk", 5)
            };

            Review review = new Review(DateTime.Now, "", "Sebastian", 4);

            Mock <IReviewContext> mock = new Mock <IReviewContext>();

            mock.Setup(x => x.GetReviews(1)).Returns(reviews);
            ReviewLogic logic = new ReviewLogic(mock.Object);

            ReviewController controller = new ReviewController(logic);

            //Act
            var result = controller.AddReview(1, "Shrek", review.Date, review.Text, review.StarRating)
                         as ViewResult;

            var viewmodel = result.Model as ReviewViewModel;

            //Assert
            Assert.Equal("Please insert all fields", viewmodel.Message);
        }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            var review = new
            {
                RestaurantId     = tbRestId.Text,
                RestaurantReview = tbReview.Text
            };
            var RestResult = RestaurantController.GetRestaurant(tbRestId.Text);

            if (RestResult != null)
            {
                var result = ReviewController.AddReview(review);
                if (result)
                {
                    MessageBox.Show("Review Recorded");
                }
                else
                {
                    MessageBox.Show("Review Recording failed");
                }
            }
            else
            {
                MessageBox.Show("Restaurant Not Found");
            }
        }
        public void TestAddReview()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new HomeMyDayDbContext(optionsBuilder.Options);

            var accommodation = new Accommodation()
            {
                Id   = 1,
                Name = "TestAccommodation"
            };

            context.Accommodations.Add(accommodation);
            context.SaveChanges();

            IAccommodationRepository accommodationRepository = new EFAccommodationRepository(context);

            IReviewRepository reviewRepository = new EFReviewRepository(context, accommodationRepository);

            var dummy       = Encoding.ASCII.GetBytes("{}");
            var sessionMock = new Mock <ISession>();

            sessionMock.Setup(x => x.TryGetValue(It.IsAny <string>(), out dummy)).Returns(true).Verifiable();

            var httpContext = new DefaultHttpContext
            {
                Session = sessionMock.Object
            };

            IReviewManager reviewManager = new ReviewManager(reviewRepository);

            var target = new ReviewController(reviewManager)
            {
                TempData = new TempDataDictionary(httpContext, new SessionStateTempDataProvider())
            };

            ReviewViewModel reviewViewModelToAdd = new ReviewViewModel()
            {
                AccommodationId = accommodation.Id,
                Name            = "TestReviewAddTest",
                Approved        = true,
                Date            = DateTime.Now,
                Title           = "TestReviewAdd",
                Text            = "Dit was goed!"
            };

            var result = target.AddReview(reviewViewModelToAdd) as RedirectToActionResult;

            Assert.NotNull(result.ActionName);
            Assert.NotNull(result.ControllerName);
            Assert.Equal("Detail", result.ActionName);
            Assert.Equal("Accommodation", result.ControllerName);
        }
        public void TestAddReviewWithoutToken()
        {
            var mockReviewService = new Mock <IReviewService>();

            mockReviewService.Setup(x => x.AddReview(reviewRequest));
            var cartService            = new Mock <ICartService>();
            var controller             = new ReviewController(mockReviewService.Object, cartService.Object);
            IHttpActionResult response = controller.AddReview(reviewRequest);
            var contentResult          = response as OkNegotiatedContentResult <ControllerResponse>;

            Assert.IsNotNull(contentResult.Content.Message);
        }
Exemplo n.º 5
0
        public void TestAddReview()
        {
            //Arrange
            logicmock.Setup(x => x.GetReviews(1)).Returns(reviews);

            Review review = new Review(DateTime.Now, "", "Sebastian", 4);

            //Act
            var result = controller.AddReview(1, review.Date, review.Text, review.StarRating, "Shrek") as RedirectToActionResult;

            RouteValueDictionary RouteDictionary = result.RouteValues;
            var Message = RouteDictionary["Message"];

            //Assert
            Assert.Equal("Please insert all fields", Message);
        }
Exemplo n.º 6
0
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    PortalSecurity security = new PortalSecurity();

                    ReviewInfo review = new ReviewInfo();
                    review            = ((ReviewInfo)CBO.InitializeObject(review, typeof(ReviewInfo)));
                    review.ReviewID   = _nav.ReviewID;
                    review.PortalID   = PortalId;
                    review.ProductID  = _nav.ProductID;
                    review.Rating     = int.Parse(cmbRating.SelectedValue);
                    review.Comments   = security.InputFilter(txtComments.Text, PortalSecurity.FilterFlag.NoMarkup);
                    review.Authorized = chkAuthorized.Checked;
                    string userName = txtUserName.Text;
                    if (!string.IsNullOrEmpty(userName))
                    {
                        review.UserName = security.InputFilter(userName, PortalSecurity.FilterFlag.NoMarkup);
                    }
                    else
                    {
                        review.UserName = Localization.GetString("Anonymous.Text", LocalResourceFile);
                    }
                    review.CreatedDate = DateTime.Now;

                    ReviewController controller = new ReviewController();
                    if (_nav.ReviewID == 0)
                    {
                        controller.AddReview(review);
                    }
                    else
                    {
                        controller.UpdateReview(review);
                    }

                    InvokeEditComplete();
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        public void TestAddReviewWithoutLogin()
        {
            var mockReviewService = new Mock <IReviewService>();

            mockReviewService.Setup(x => x.AddReview(reviewRequest));
            var cartService       = new Mock <ICartService>();
            var controller        = new ReviewController(mockReviewService.Object, cartService.Object);
            var controllerContext = new HttpControllerContext();
            var request           = new HttpRequestMessage();

            request.Headers.Add(ControllerHelper.TOKEN_NAME, new Guid().ToString());
            controllerContext.Request    = request;
            controller.ControllerContext = controllerContext;
            IHttpActionResult response = controller.AddReview(reviewRequest);
            var contentResult          = response as OkNegotiatedContentResult <ControllerResponse>;

            Assert.IsNotNull(contentResult.Content.Message);
        }
        public void TestAddReviewWithLogin()
        {
            string         token          = LoginContext.GetInstance().GenerateNewToken("1");
            UserContextDTO userContextDTO = GetUserContextDTO(token);

            LoginContext.GetInstance().SaveContext(userContextDTO);
            var mockReviewService = new Mock <IReviewService>();

            mockReviewService.Setup(x => x.AddReview(reviewRequest));
            var cartService       = new Mock <ICartService>();
            var controller        = new ReviewController(mockReviewService.Object, cartService.Object);
            var controllerContext = new HttpControllerContext();
            var request           = new HttpRequestMessage();

            request.Headers.Add(ControllerHelper.TOKEN_NAME, token);
            controllerContext.Request    = request;
            controller.ControllerContext = controllerContext;
            IHttpActionResult response = controller.AddReview(reviewRequest);
            var contentResult          = response as OkNegotiatedContentResult <ControllerResponse>;

            Assert.IsTrue(contentResult.Content.Success);
        }