public async Task Remove_invoice_handler_should_be_called_the_same_number_of_times_as_remove_invoice_command1(int count)
        {
            // Arrange
            ServiceCollection services = TestHelper.PrepareServiceCollection();

            services.AddSingleton <Counter>();

            // Replace the registered event class
            ServiceDescriptor serviceDescriptor = services.FirstOrDefault(d => d.ServiceType == typeof(IRequestHandler <RemoveInvoiceCommand, RemoveInvoiceCommandResponse>));

            services.Remove(serviceDescriptor);
            services.AddScoped <IRequestHandler <RemoveInvoiceCommand, RemoveInvoiceCommandResponse>, FakeRemoveInvoiceHandler>();

            ServiceProvider serviceProvider = services.BuildServiceProvider();

            using (IServiceScope scope = serviceProvider.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;

                IMessageManager messageManager = scopedServices.GetRequiredService <IMessageManager>();

                Counter counter = scopedServices.GetRequiredService <Counter>();

                // Act
                for (int i = 0; i < count; i++)
                {
                    RemoveInvoiceCommandResponse removeResponse = await messageManager.SendCommand(new RemoveInvoiceCommand(Guid.NewGuid()));
                }

                // Assert
                counter.Get().Should().Be(count);
            }
        }
        public async Task <IActionResult> Delete(Guid id)
        {
            RemoveInvoiceCommandResponse result = await _messageManager.SendCommand(new RemoveInvoiceCommand(id));

            if (result.Removed)
            {
                return(NoContent());
            }

            return(NotFound("Not found"));
        }
        public async Task Id_should_be_possible_to_delete_all_created_invoices(int count)
        {
            ServiceProvider serviceProvider = TestHelper.PrepareServiceProvider();

            using (IServiceScope scope = serviceProvider.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;

                IMessageManager messageManager = scopedServices.GetRequiredService <IMessageManager>();

                // Arrange

                // empty repository
                var invoiceRepository = scopedServices.GetRequiredService <IInvoiceRepository>();

                List <CreateInvoiceCommandResponse> createInvoiceResponses = new List <CreateInvoiceCommandResponse>();

                // Act
                for (int i = 0; i < count; i++)
                {
                    CreateInvoiceCommandResponse createInvoiceResponse = await messageManager.SendCommand(
                        new CreateInvoiceCommand(new Invoice(id: Guid.NewGuid(), number: "JK/02/2019", creationDate: DateTime.Now)));

                    createInvoiceResponses.Add(createInvoiceResponse);
                }

                // Assert
                foreach (var createdInvoice in createInvoiceResponses)
                {
                    RemoveInvoiceCommandResponse removeResponse = await messageManager.SendCommand(new RemoveInvoiceCommand(createdInvoice.Id));

                    removeResponse.Removed.Should().BeTrue();
                }

                // Repo should be empty
                GetInvoicesQueryResponse queryResponse = await messageManager.SendCommand(new GetInvoicesQuery());

                queryResponse.Invoices.Should().HaveCount(0);
            }
        }