public void UpdateOrder_ReturnNoContent() { _updateCommandLogger = new Mock <ILogger <UpdateOrderCommandHandler> >(); _orderRepoMock.Setup(p => p.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(_order); //GET QueryHandler _updateOrderCommandHandler = new UpdateOrderCommandHandler(_orderRepoMock.Object, _mapper, _updateCommandLogger.Object); _mockMediatr.Setup(m => m.Send(It.IsAny <UpdateOrderCommand>(), It.IsAny <CancellationToken>())) .Returns(async() => await _updateOrderCommandHandler.Handle(new UpdateOrderCommand(), new CancellationToken())); _orderRepoMock.Setup(p => p.UpdateAsync(It.IsAny <Order>())); var orders = _controller.UpdateOrder(_updateOrderCommand); if (orders.Result is NoContentResult okObject) { Assert.Pass(); } else { Assert.Fail(); } }
public async Task Handle_GivenNullRequest_ShouldThrowArgumentNullException() { // Arrange var sut = new UpdateOrderCommandHandler(this.deletableEntityRepository); // Act & Assert await Should.ThrowAsync <ArgumentNullException>(sut.Handle(null, It.IsAny <CancellationToken>())); }
public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException() { // Arrange var command = new UpdateOrderCommand { Id = 500, Description = "NewDesc", Quantity = "321", Price = "123", Status = "Tested", }; var sut = new UpdateOrderCommandHandler(this.deletableEntityRepository); // Act & Assert await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>())); }
public async Task Handle_GivenValidRequest_ShouldReturnOrderId() { // Arrange var command = new UpdateOrderCommand { Id = 1, Description = "NewDesc", Quantity = "321", Status = "Tested", }; var sut = new UpdateOrderCommandHandler(this.deletableEntityRepository); // Act var id = await sut.Handle(command, It.IsAny <CancellationToken>()); // Assert var order = await this.dbContext.Orders.SingleOrDefaultAsync(x => x.Id == id); order.ShouldNotBeNull(); order.Description.ShouldBe("NewDesc"); order.Quantity.ShouldBe(321); order.Status.ShouldBe("Tested"); }
public async void Handle_ShouldCallRepositoryAddAsync() { await _testee.Handle(new UpdateOrderCommand(), default); A.CallTo(() => _repository.UpdateRangeAsync(A <List <Order> > ._)).MustHaveHappenedOnceExactly(); }