public async Task BookOrderReturnUnauthorized_IfIdOfUserDoesntMatch_WithIdInClaims() { var mockRepo = new Mock <ICustomerRepository>(); var mockMapper = new Mock <IMapper>(); int mockUserId = 2; //mockRepo.Setup(repo => repo.) OrderForCreationDto d1 = new OrderForCreationDto(); 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, "1") })); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var res = await controller.BookOrder(mockUserId, d1); Assert.IsType <UnauthorizedResult>(res); }
public async Task BookOrderReturnBadRequest_IfBasketDoesntExist() { var mockRepo = new Mock <ICustomerRepository>(); var mockMapper = new Mock <IMapper>(); int mockUserId = 1; OrderForCreationDto d1 = new OrderForCreationDto(); mockRepo.Setup(repo => repo.RetrieveBasket(mockUserId)).ReturnsAsync((Order)null); 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, "1") })); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var res = await controller.BookOrder(mockUserId, d1); Assert.IsType <BadRequestObjectResult>(res); }
public async Task BookOrderReturnOkObjectResult_IfExistingBasketIsNotEmpty() { var mockRepo = new Mock <ICustomerRepository>(); var mockMapper = new Mock <IMapper>(); int mockUserId = 1; int mockOrderId = 2; OrderForCreationDto d1 = new OrderForCreationDto(); Order basket = new Order { ClientId = mockUserId, Id = mockOrderId }; List <Product> orderToBasket = new List <Product> { new Product(), new Product() }; mockRepo.Setup(repo => repo.RetrieveBasket(mockUserId)).ReturnsAsync(basket); mockRepo.Setup(repo => repo.GetOrderItems(mockOrderId)).ReturnsAsync(orderToBasket); mockRepo.Setup(repo => repo.SaveOrder(mockOrderId, d1)).ReturnsAsync(basket); 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, "1") })); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var res = await controller.BookOrder(mockUserId, d1); Assert.IsType <OkObjectResult>(res); }