public async Task Handle_success() { //arrange var pedido = new Pedido( new List <ItemPedido> { new ItemPedido("001", "produto 001", 1, 12.34m), new ItemPedido("002", "produto 002", 2, 23.45m) }, "clienteId", "clienteNome", "*****@*****.**", "fone", "endereco", "complemento", "bairro", "municipio", "uf", "12345-678"); CancellationToken token = default(CancellationToken); CreatePedidoCommand command = new CreatePedidoCommand(new List <CreatePedidoCommandItem> { new CreatePedidoCommandItem("001", "produto 001", 1, 12.34m), new CreatePedidoCommandItem("002", "produto 002", 2, 23.45m) } , "clienteId", "clienteNome", "*****@*****.**", "fone", "endereco", "complemento", "bairro", "municipio", "uf", "12345-678"); IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(command, Guid.NewGuid()); pedidoRepositoryMock .Setup(r => r.CreateOrUpdate(It.IsAny <Pedido>())) .ReturnsAsync(pedido) .Verifiable(); var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object); //act bool result = await handler.Handle(request, token); //assert Assert.True(result); pedidoRepositoryMock.Verify(); }
public async Task Handle_guid_is_empty() { //arrange CancellationToken token = default(System.Threading.CancellationToken); IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(new CreatePedidoCommand(), Guid.Empty); var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object); //act //assert await Assert.ThrowsAsync <ArgumentException>(async() => await handler.Handle(request, token)); }
public async Task Handle_items_is_empty() { //arrange CancellationToken token = default(CancellationToken); CreatePedidoCommand command = new CreatePedidoCommand(); IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(command, Guid.NewGuid()); var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object); //act //assert await Assert.ThrowsAsync <NoItemsException>(async() => await handler.Handle(request, token)); }
public async Task Handle_invalid_item(string produtoCodigo, string produtoNome, int produtoQuantidade, decimal produtoPrecoUnitario) { //arrange CancellationToken token = default(CancellationToken); CreatePedidoCommand command = new CreatePedidoCommand(new List <CreatePedidoCommandItem> { new CreatePedidoCommandItem(produtoCodigo, produtoNome, produtoQuantidade, produtoPrecoUnitario) } , "clienteId", "clienteNome", "*****@*****.**", "fone", "endereco", "complemento", "bairro", "municipio", "uf", "12345-678"); IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(command, Guid.NewGuid()); var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object); //act //assert await Assert.ThrowsAsync <InvalidItemException>(async() => await handler.Handle(request, token)); }
public async Task Handle_invalid_user_data(string clienteId, string clienteNome, string clienteEmail, string clienteTelefone, string clienteEndereco, string clienteComplemento, string clienteBairro, string clienteMunicipio, string clienteUF, string clienteCEP) { //arrange CancellationToken token = default(CancellationToken); CreatePedidoCommand command = new CreatePedidoCommand(new List <CreatePedidoCommandItem> { new CreatePedidoCommandItem("001", "produto 001", 1, 12.34m) } , clienteId, clienteNome, clienteEmail, clienteTelefone, clienteEndereco, clienteComplemento, clienteBairro, clienteMunicipio, clienteUF, clienteCEP); IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(command, Guid.NewGuid()); var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object); //act //assert await Assert.ThrowsAsync <InvalidUserDataException>(async() => await handler.Handle(request, token)); }