Beispiel #1
0
        public void OrderConfirmation_CheckStatusOfOrder(bool success, double price, int id)
        {
            using (var homeController = new HomeController(MockData.MoqLogger(), MockData.MoqShopContext(),
                                                           MockData.MoqEmailSender(), MockData.MoqMyLogger()))
            {
                var culture = CultureInfo.CreateSpecificCulture("pl-PL");

                var controllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        Session = new MockHttpSession()
                    }
                };

                homeController.ControllerContext = controllerContext;

                var compareContext = MockData.MoqShopContext();
                var userId         = compareContext?
                                     .Orders.Include(u => u.User)?
                                     .SingleOrDefault(o => o.OrderId == id)?.User.UserId;
                if (userId == 1)
                {
                    homeController.HttpContext.Session.Set("userId", "6040582f-0c20-44dc-8acc-b684479454b0");
                }
                else if (userId == 2)
                {
                    homeController.HttpContext.Session.Set("userId", "8befe3cc-024b-4084-ab38-8f5c7663cd1d");
                }

                var result = homeController.OrderConfirmation(success, price, id) as ViewResult;
                (int id, double price, bool success)model = ((int id, double price, bool success))result.Model;
                ViewDataDictionary viewData = result?.ViewData;

                if (success)
                {
                    Assert.Equal($"Thank You for your order! {price.ToString("0.00", culture)} zł was successfully charged from your bank account.",
                                 viewData?["Message"]);
                }
                else
                {
                    Assert.Equal($"We couldn't charge your account...",
                                 viewData?["Message"]);
                }

                Assert.NotNull(result);
                Assert.NotNull(viewData);
                Assert.IsAssignableFrom <ViewResult>(result);
                Assert.Equal("OrderConfirmation", result.ViewName);
                Assert.Equal(id, model.id);
                Assert.Equal(price, model.price);
                Assert.Equal(success, model.success);
            }
        }