public async Task CreateInvoiceExceptionCatch()
        {
            // Arrange
            var invoice = new Invoice();

            mockRepo.Setup(x => x.Invoice).Returns(_invoiceRepoMock.Object);
            _invoiceRepoMock.Setup(x => x.CreateInvoice(invoice)).Throws(new Exception());

            // Act
            var result = await _sut.CreateInvoice(new InvoiceForCreationDto());

            // Assert
            mockLogger.Verify(x => x.LogError("Something went wrong inside CreateInvoice() action: Object reference not set to an instance of an object."), Times.Once);
            Assert.IsType <ObjectResult>(result);
        }
        public void CreateInvoice_Returns201AndInvoice_WhenInvoiceCreated()
        {
            //arrange
            service.Setup(s => s.CreateInvoice(It.IsAny <InvoiceForCreationDto>())).Returns(new Invoice());

            //act
            var result = controller.CreateInvoice(new InvoiceForCreationDto());

            //assert
            var createdAtAction = (result is CreatedAtActionResult);

            Assert.IsTrue(createdAtAction);

            var created = result as CreatedAtActionResult;

            Assert.IsTrue(created.Value is InvoiceDto);
            Assert.IsTrue(created.StatusCode == 201);
        }
Exemplo n.º 3
0
        public async Task NormalEmployee()
        {
            var request = new CreateEmployeeRequest()
            {
                PersonalIdentificationNumber = "1234567890",
                UserName = "******",
            };
            var employeeId = await _employeeController.CreateEmployee(request);

            var customerRequest = new CreateCustomerRequest()
            {
                EmployeeId = employeeId,
                PersonalIdentificationNumber = "customer ssn",
                UserName = "******",
                Address  = "address"
            };
            var customerId = await _customerController.CreateCustomer(customerRequest);

            var createInvoiceRequest = new CreateInvoiceRequest()
            {
                EmployeeId   = employeeId,
                CustomerId   = customerId,
                PayInAdvance = false,
                InvoiceItems = new List <InvoiceItemDto>()
                {
                    new InvoiceItemDto()
                    {
                        Price = 10000.0m, Description = "städning"
                    }
                }.ToArray(),
                EndDate            = DateTime.Now,
                StartDate          = DateTime.Now,
                Name               = "invoiceName",
                Vat                = 25m,
                InvoiceDescription = "invoice description"
            };
            var invoiceId = await _invoiceController.CreateInvoice(createInvoiceRequest);

            var assignment = await _assignmentController.GetAssignment(invoiceId);

            Assert.Equal(Status.Created, assignment.CurrentStatus);

            await _invoiceController.SendInvoice(invoiceId);

            var payment = await _paymentController.GetPayment(invoiceId);

            Assert.Equal(PaymentState.WaitingForPayment, payment.CurrentState);

            // simulate payment
            await _paymentController.SimulateReceivePayment(new ReceivePaymentRequest()
            {
                InvoiceId = invoiceId
            });

            payment = await _paymentController.GetPayment(invoiceId);

            Assert.Equal(PaymentState.PaymentReceived, payment.CurrentState);

            var payout = await _payoutController.GetPayout(invoiceId);

            Assert.Equal(5060m, Math.Floor(payout.Amount));

            assignment = await _assignmentController.GetAssignment(invoiceId);

            Assert.Equal(Status.Closed, assignment.CurrentStatus);
        }