public async Task Should_Not_Generate_Same_Invoice_Number() { var invoiceCountToGenerate = 100; var invoiceNumbers = new List <string>(); for (int i = 0; i < invoiceCountToGenerate; i++) { var invoiceNo = await _invoiceNumberGenerator.GetNewInvoiceNumber(); invoiceNo.ShouldNotBeNullOrEmpty(); invoiceNo.Length.ShouldBe(11);//Should be YYYYMM00001 _invoiceRepository.Insert(new Invoice { InvoiceNo = invoiceNo, InvoiceDate = Clock.Now, TenantAddress = "USA", TenantLegalName = "AspNet Zero", TenantTaxNo = "123456789" }); invoiceNumbers.ShouldNotContain(invNo => invNo == invoiceNo); invoiceNumbers.Add(invoiceNo); } invoiceNumbers.Count.ShouldBe(invoiceCountToGenerate); }
public async Task CreateInvoice(CreateInvoiceDto input) { var payment = await _subscriptionPaymentRepository.GetAsync(input.SubscriptionPaymentId); if (!string.IsNullOrEmpty(payment.InvoiceNo)) { throw new Exception("Invoice is already generated for this payment."); } var invoiceNo = await _invoiceNumberGenerator.GetNewInvoiceNumber(); var tenantLegalName = await SettingManager.GetSettingValueAsync(AppSettings.TenantManagement.BillingLegalName); var tenantAddress = await SettingManager.GetSettingValueAsync(AppSettings.TenantManagement.BillingAddress); var tenantTaxNo = await SettingManager.GetSettingValueAsync(AppSettings.TenantManagement.BillingTaxVatNo); if (string.IsNullOrEmpty(tenantLegalName) || string.IsNullOrEmpty(tenantAddress) || string.IsNullOrEmpty(tenantTaxNo)) { throw new UserFriendlyException(L("InvoiceInfoIsMissingOrNotCompleted")); } await _invoiceRepository.InsertAsync(new Invoice { InvoiceNo = invoiceNo, InvoiceDate = Clock.Now, TenantLegalName = tenantLegalName, TenantAddress = tenantAddress, TenantTaxNo = tenantTaxNo }); payment.InvoiceNo = invoiceNo; }