public async void SetStatusCancelled_CurrentStatusValid_RedirectsToDetails(OrderStatus status)
        {
            List<WebOrder> orders = new List<WebOrder>
            {
                new WebOrder
                {
                    Id = 1,
                    MemberId = UserId,
                    OrderStatus = status,
                    OrderItems = new List<OrderItem>
                    {
                        new OrderItem
                        {
                            IsNew = true,
                            ProductId = Id,
                            Quantity = 2
                        },
                        new OrderItem
                        {
                            IsNew = false,
                            ProductId = Id,
                            Quantity = 1
                        },
                    }
                }
            };

            ProductLocationInventory inventory = new ProductLocationInventory
            {
                Location = new Location
                {
                    SiteName = Location.ONLINE_WAREHOUSE_NAME
                },
                ProductId = Id,
                NewOnHand = 0,
                UsedOnHand = 0
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<IUserStore<User, Guid>> userStoreStub = new Mock<IUserStore<User, Guid>>();
            dbStub.Setup(db => db.UserStore).Returns(userStoreStub.Object);

            Mock<DbSet<WebOrder>> webOrdersDbSetStub = TestHelpers.GetFakeAsyncDbSet(orders.AsQueryable());
            webOrdersDbSetStub.Setup(wo => wo.FindAsync(orders[0].Id)).ReturnsAsync(orders[0]);
            dbStub.Setup(db => db.WebOrders).Returns(webOrdersDbSetStub.Object);

            Mock<DbSet<ProductLocationInventory>> inventoryDbSetStub =
                TestHelpers.GetFakeAsyncDbSet(new List<ProductLocationInventory> { inventory }.AsQueryable());
            dbStub.Setup(db => db.ProductLocationInventories).Returns(inventoryDbSetStub.Object);

            Mock<IStripeService> stripeServiceStub = new Mock<IStripeService>();
            stripeServiceStub.Setup(s => s.RefundCharge(It.IsAny<string>())).Returns(true);

            Mock<VeilUserManager> userManagerMock = new Mock<VeilUserManager>(dbStub.Object, null /*messageService*/, null /*dataProtectionProvider*/);
            userManagerMock.
                Setup(um => um.SendEmailAsync(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<string>())).
                Returns(Task.FromResult(0)).
                Verifiable();

            Mock<ControllerContext> context = new Mock<ControllerContext>();

            Mock<IView> partialViewStub = new Mock<IView>();
            Mock<IViewEngine> viewEngineStub = new Mock<IViewEngine>();
            var viewEngineResult = new ViewEngineResult(partialViewStub.Object, viewEngineStub.Object);
            viewEngineStub.Setup(ve => ve.FindPartialView(It.IsAny<ControllerContext>(), It.IsAny<string>(), It.IsAny<bool>())).Returns(viewEngineResult);
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(viewEngineStub.Object);

            WebOrdersController controller = new WebOrdersController(dbStub.Object, null, stripeServiceStub.Object, userManagerMock.Object)
            {
                ControllerContext = context.Object
            };

            var result = await controller.SetStatusCancelled(1, "TestReason", true) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Details"));
            Assert.That(orders[0].OrderStatus, Is.EqualTo(OrderStatus.EmployeeCancelled));
            Assert.That(orders[0].ReasonForCancellationMessage, Is.EqualTo("TestReason"));
            Assert.That(inventory.NewOnHand, Is.EqualTo(2));
            Assert.That(inventory.UsedOnHand, Is.EqualTo(1));

            Assert.That(
                () =>
                    userManagerMock.Verify(um => um.SendEmailAsync(It.Is<Guid>(val => val == orders[0].MemberId), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(1)),
                Throws.Nothing);
        }
        public async void SetStatusCancelled_Unconfirmed_PresentsError()
        {
            WebOrdersController controller = new WebOrdersController(veilDataAccess: null, idGetter: null, stripeService: null, userManager: null);

            var result = await controller.SetStatusCancelled(null, "TestReason", false) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Details"));

            var alerts = controller.TempData["AlertMessages"];
            Assert.That(alerts is List<AlertMessage>);

            AlertMessage message = ((List<AlertMessage>)alerts)[0];
            Assert.That(message.Message, Is.EqualTo("You must confirm your action by checking \"Confirm Cancellation.\""));
        }
        public async void SetStatusCancelled_CurrentStatusInvalid_PresentsError(OrderStatus status)
        {
            List<WebOrder> orders = new List<WebOrder>
            {
                new WebOrder
                {
                    Id = 1,
                    MemberId = UserId,
                    OrderStatus = status
                }
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<WebOrder>> webOrdersDbSetStub = TestHelpers.GetFakeAsyncDbSet(orders.AsQueryable());
            webOrdersDbSetStub.Setup(wo => wo.FindAsync(orders[0].Id)).ReturnsAsync(orders[0]);
            dbStub.Setup(db => db.WebOrders).Returns(webOrdersDbSetStub.Object);

            WebOrdersController controller = new WebOrdersController(dbStub.Object, idGetter: null, stripeService: null, userManager: null);

            var result = await controller.SetStatusCancelled(1, "TestReason", true) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Details"));

            var alerts = controller.TempData["AlertMessages"];
            Assert.That(alerts is List<AlertMessage>);

            AlertMessage message = ((List<AlertMessage>)alerts)[0];
            Assert.That(message.Message, Is.EqualTo("You can only cancel an order if it is pending processing or being processed."));
        }
        public async void SetStatusCancelled_ReasonIsNull_PresentsError()
        {
            WebOrdersController controller = new WebOrdersController(veilDataAccess: null, idGetter: null, stripeService: null, userManager: null);

            var result = await controller.SetStatusCancelled(null, null, true) as RedirectToRouteResult;

            Assert.That(result != null);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Details"));

            var alerts = controller.TempData["AlertMessages"];
            Assert.That(alerts is List<AlertMessage>);

            AlertMessage message = ((List<AlertMessage>) alerts)[0];
            Assert.That(message.Message, Is.EqualTo("You must provide a reason for cancellation."));
        }