Exemplo n.º 1
0
        [InlineData(9, 10, false, OrderFormRestrictedView)]  // Is not owner, cannot edit
        public async void GetOrderFormEdit_WithSellerUser_ShouldReturnView(long userId, long ownerId,
                                                                           bool canEditOrder, string expectedView)
        {
            // Arrange
            const int OrderId  = 1;
            var       mockUser = new Mock <ClaimsPrincipal>();

            mockUser.Setup(user => user.IsInRole(RoleName.Admin)).Returns(false);
            _controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext {
                    User = mockUser.Object
                }
            };
            _mockWorkContext.Setup(context => context.GetCurrentUser()).Returns(Task.FromResult(new User {
                Id = userId
            }));

            var order = new GetOrderVm()
            {
                CanEdit     = canEditOrder,
                CreatedById = ownerId
            };
            var orderResult = ActionFeedback <GetOrderVm> .Succeed(order);

            _mockOrderService.Setup(service => service.GetOrderAsync(OrderId)).Returns(Task.FromResult(orderResult));

            // Action
            var result = await _controller.GetOrderFormEdit(OrderId);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal(expectedView, viewResult.ViewName);
        }