public void GetOrdersByUserName_NotFound(string userName) { _orderRepoMock.Setup(p => p.GetOrdersByUserName(userName)).ReturnsAsync((IEnumerable <Order>)null); //GET QueryHandler _getOrdersListQueryHandler = new GetOrdersListQueryHandler(_orderRepoMock.Object, _mapper); _mockMediatr.Setup(m => m.Send(It.IsAny <GetOrdersListQuery>(), It.IsAny <CancellationToken>())) .Returns(async() => await _getOrdersListQueryHandler.Handle(new GetOrdersListQuery(userName), new CancellationToken())); var orders = _controller.GetOrdersByUserName(userName); if (orders.Result.Result is OkObjectResult okResult) { Assert.IsNull(orders.Result.Value); } else { Assert.Fail(); } }
public void GetOrdersByUserName(string userName) { _orderRepoMock.Setup(p => p.GetOrdersByUserName(userName)).ReturnsAsync(_orders); //GET QueryHandler _getOrdersListQueryHandler = new GetOrdersListQueryHandler(_orderRepoMock.Object, _mapper); _mockMediatr.Setup(m => m.Send(It.IsAny <GetOrdersListQuery>(), It.IsAny <CancellationToken>())) .Returns(async() => await _getOrdersListQueryHandler.Handle(new GetOrdersListQuery(userName), new CancellationToken())); var orders = _controller.GetOrdersByUserName(userName); if (orders.Result.Result is OkObjectResult okResult) { Assert.NotNull(orders.Result); Assert.AreEqual((int)HttpStatusCode.OK, okResult.StatusCode); } else { Assert.Fail(); } }