Exemple #1
0
        public async Task ChangeStatusOfOrder_ShouldReturnUnathorized_IfUserIsNotAdmin()
        {
            var    mockRepo    = new Mock <ICustomerRepository>();
            var    mockMapper  = new Mock <IMapper>();
            int    mockOrderId = 2;
            string newStatus   = "NeverGonnaGiveYouUp";
            Client c1          = new Client {
                Id      = 2,
                IsAdmin = false
            };

            mockRepo.Setup(repo => repo.GetCustomer(c1.Id)).ReturnsAsync(c1);

            var controller = new OrdersController(mockRepo.Object, mockMapper.Object);

            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.Name, "Just Name"),
                new Claim(ClaimTypes.NameIdentifier, c1.Id.ToString())
            }));

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };

            var res = await controller.ChangeStatusOfOrder(c1.Id, mockOrderId, newStatus);

            Assert.IsType <UnauthorizedResult>(res);
        }