public async Task GetAllOrderAsync_ValidOrderId(PagingInfo pagingInfo) { //Arrange var orders = OrderDumbData.GetRandomEntities(5); var cancellationToken = new CancellationToken(); var expectedOrders = ReturnPagingInfoDumbData.GetForModel(pagingInfo, orders); var expectedValue = ReturnPagingInfoDumbData.GetWithModels <ReadOrderModel, Order>(expectedOrders, _mapper); _orderRepository.Setup(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken)).Returns(Task.FromResult(expectedOrders)); // Act var response = await _orderService.GetAllOrderAsync(pagingInfo, cancellationToken); // Assert _orderRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once); }
public async Task GetAllAsync_ValidOrderId() { //Arrange var users = UserDumbData.GetRandomEntities(5); var orders = OrderDumbData.GetRandomEntities(users.Count); var requestOrders = RequestOrderDumbData.GetEntities(users, orders); var cancellationToken = new CancellationToken(); var expectedRequestOrders = ReturnPagingInfoDumbData.GetForModel(new PagingInfo(), requestOrders); var expectedValue = ReturnPagingInfoDumbData.GetWithModels <ReadRequestOrderModel, RequestOrder>(expectedRequestOrders, _mapper); _requestOrderRepository.Setup(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken)).Returns(Task.FromResult(expectedRequestOrders)); _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns((Guid x) => Task.FromResult(users.FirstOrDefault(y => y.Id == x))); _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns((Guid x) => Task.FromResult(orders.FirstOrDefault(y => y.Id == x))); // Act var response = await _requestOrderService.GetAllAsync(cancellationToken); // Assert _requestOrderRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once); _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Exactly(users.Count)); _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Exactly(orders.Count)); }