diff --git a/RefactorThis.Domain.Tests/InvoicePaymentProcessorTests.cs b/RefactorThis.Domain.Tests/InvoicePaymentProcessorTests.cs index 3a607fd..97f10be 100644 --- a/RefactorThis.Domain.Tests/InvoicePaymentProcessorTests.cs +++ b/RefactorThis.Domain.Tests/InvoicePaymentProcessorTests.cs @@ -1,247 +1,241 @@ -using System; +using NUnit.Framework; +using RefactorThis.Domain.Service; +using RefactorThis.Persistence.IRepository; +using RefactorThis.Persistence.Models; +using RefactorThis.Persistence.Repository; +using System; using System.Collections.Generic; -using NUnit.Framework; -using RefactorThis.Persistence; namespace RefactorThis.Domain.Tests { [TestFixture] - public class InvoicePaymentProcessorTests - { - [Test] - public void ProcessPayment_Should_ThrowException_When_NoInoiceFoundForPaymentReference( ) - { - var repo = new InvoiceRepository( ); - - Invoice invoice = null; - var paymentProcessor = new InvoiceService( repo ); - - var payment = new Payment( ); - var failureMessage = ""; - - try - { - var result = paymentProcessor.ProcessPayment( payment ); - } - catch ( InvalidOperationException e ) - { - failureMessage = e.Message; - } - - Assert.AreEqual( "There is no invoice matching this payment", failureMessage ); - } - - [Test] - public void ProcessPayment_Should_ReturnFailureMessage_When_NoPaymentNeeded( ) - { - var repo = new InvoiceRepository( ); - - var invoice = new Invoice( repo ) - { - Amount = 0, - AmountPaid = 0, - Payments = null - }; - - repo.Add( invoice ); - - var paymentProcessor = new InvoiceService( repo ); - - var payment = new Payment( ); - - var result = paymentProcessor.ProcessPayment( payment ); - - Assert.AreEqual( "no payment needed", result ); - } - - [Test] - public void ProcessPayment_Should_ReturnFailureMessage_When_InvoiceAlreadyFullyPaid( ) - { - var repo = new InvoiceRepository( ); - - var invoice = new Invoice( repo ) - { - Amount = 10, - AmountPaid = 10, - Payments = new List - { - new Payment - { - Amount = 10 - } - } - }; - repo.Add( invoice ); - - var paymentProcessor = new InvoiceService( repo ); - - var payment = new Payment( ); - - var result = paymentProcessor.ProcessPayment( payment ); - - Assert.AreEqual( "invoice was already fully paid", result ); - } - - [Test] - public void ProcessPayment_Should_ReturnFailureMessage_When_PartialPaymentExistsAndAmountPaidExceedsAmountDue( ) - { - var repo = new InvoiceRepository( ); - var invoice = new Invoice( repo ) - { - Amount = 10, - AmountPaid = 5, - Payments = new List - { - new Payment - { - Amount = 5 - } - } - }; - repo.Add( invoice ); - - var paymentProcessor = new InvoiceService( repo ); - - var payment = new Payment( ) - { - Amount = 6 - }; - - var result = paymentProcessor.ProcessPayment( payment ); - - Assert.AreEqual( "the payment is greater than the partial amount remaining", result ); - } - - [Test] - public void ProcessPayment_Should_ReturnFailureMessage_When_NoPartialPaymentExistsAndAmountPaidExceedsInvoiceAmount( ) - { - var repo = new InvoiceRepository( ); - var invoice = new Invoice( repo ) - { - Amount = 5, - AmountPaid = 0, - Payments = new List( ) - }; - repo.Add( invoice ); - - var paymentProcessor = new InvoiceService( repo ); - - var payment = new Payment( ) - { - Amount = 6 - }; - - var result = paymentProcessor.ProcessPayment( payment ); - - Assert.AreEqual( "the payment is greater than the invoice amount", result ); - } - - [Test] - public void ProcessPayment_Should_ReturnFullyPaidMessage_When_PartialPaymentExistsAndAmountPaidEqualsAmountDue( ) - { - var repo = new InvoiceRepository( ); - var invoice = new Invoice( repo ) - { - Amount = 10, - AmountPaid = 5, - Payments = new List - { - new Payment - { - Amount = 5 - } - } - }; - repo.Add( invoice ); - - var paymentProcessor = new InvoiceService( repo ); - - var payment = new Payment( ) - { - Amount = 5 - }; - - var result = paymentProcessor.ProcessPayment( payment ); - - Assert.AreEqual( "final partial payment received, invoice is now fully paid", result ); - } - - [Test] - public void ProcessPayment_Should_ReturnFullyPaidMessage_When_NoPartialPaymentExistsAndAmountPaidEqualsInvoiceAmount( ) - { - var repo = new InvoiceRepository( ); - var invoice = new Invoice( repo ) - { - Amount = 10, - AmountPaid = 0, - Payments = new List( ) { new Payment( ) { Amount = 10 } } - }; - repo.Add( invoice ); - - var paymentProcessor = new InvoiceService( repo ); - - var payment = new Payment( ) - { - Amount = 10 - }; - - var result = paymentProcessor.ProcessPayment( payment ); - - Assert.AreEqual( "invoice was already fully paid", result ); - } - - [Test] - public void ProcessPayment_Should_ReturnPartiallyPaidMessage_When_PartialPaymentExistsAndAmountPaidIsLessThanAmountDue( ) - { - var repo = new InvoiceRepository( ); - var invoice = new Invoice( repo ) - { - Amount = 10, - AmountPaid = 5, - Payments = new List - { - new Payment - { - Amount = 5 - } - } - }; - repo.Add( invoice ); - - var paymentProcessor = new InvoiceService( repo ); - - var payment = new Payment( ) - { - Amount = 1 - }; - - var result = paymentProcessor.ProcessPayment( payment ); - - Assert.AreEqual( "another partial payment received, still not fully paid", result ); - } - - [Test] - public void ProcessPayment_Should_ReturnPartiallyPaidMessage_When_NoPartialPaymentExistsAndAmountPaidIsLessThanInvoiceAmount( ) - { - var repo = new InvoiceRepository( ); - var invoice = new Invoice( repo ) - { - Amount = 10, - AmountPaid = 0, - Payments = new List( ) - }; - repo.Add( invoice ); - - var paymentProcessor = new InvoiceService( repo ); - - var payment = new Payment( ) - { - Amount = 1 - }; - - var result = paymentProcessor.ProcessPayment( payment ); - - Assert.AreEqual( "invoice is now partially paid", result ); - } - } + public class InvoicePaymentProcessorTests + { + [Test] + public void ProcessPayment_Should_ThrowException_When_NoInoiceFoundForPaymentReference() + { + IInvoiceRepository repo = new InvoiceRepository(); + + var paymentProcessor = new InvoiceService(repo); + + var payment = new Payment(); + + var result = paymentProcessor.ProcessPayment(payment); + + Assert.AreEqual("There is no invoice matching this payment", result); + } + + [Test] + public void ProcessPayment_Should_ReturnFailureMessage_When_NoPaymentNeeded() + { + IInvoiceRepository repo = new InvoiceRepository(); + + var invoice = new Invoice() + { + Amount = 0, + AmountPaid = 0, + Payments = null + }; + + repo.Add(invoice); + + var paymentProcessor = new InvoiceService(repo); + + var payment = new Payment(); + + var result = paymentProcessor.ProcessPayment(payment); + + Assert.AreEqual("no payment needed", result); + } + + [Test] + public void ProcessPayment_Should_ReturnFailureMessage_When_InvoiceAlreadyFullyPaid() + { + IInvoiceRepository repo = new InvoiceRepository(); + + var invoice = new Invoice() + { + Amount = 10, + AmountPaid = 10, + Payments = new List + { + new Payment + { + Amount = 10 + } + } + }; + repo.Add(invoice); + + var paymentProcessor = new InvoiceService(repo); + + var payment = new Payment(); + + var result = paymentProcessor.ProcessPayment(payment); + + Assert.AreEqual("invoice was already fully paid", result); + } + + [Test] + public void ProcessPayment_Should_ReturnFailureMessage_When_PartialPaymentExistsAndAmountPaidExceedsAmountDue() + { + IInvoiceRepository repo = new InvoiceRepository(); + var invoice = new Invoice() + { + Amount = 10, + AmountPaid = 5, + Payments = new List + { + new Payment + { + Amount = 5 + } + } + }; + repo.Add(invoice); + + var paymentProcessor = new InvoiceService(repo); + + var payment = new Payment() + { + Amount = 6 + }; + + var result = paymentProcessor.ProcessPayment(payment); + + Assert.AreEqual("the payment is greater than the partial amount remaining", result); + } + + [Test] + public void ProcessPayment_Should_ReturnFailureMessage_When_NoPartialPaymentExistsAndAmountPaidExceedsInvoiceAmount() + { + IInvoiceRepository repo = new InvoiceRepository(); + var invoice = new Invoice() + { + Amount = 5, + AmountPaid = 0, + Payments = new List() + }; + repo.Add(invoice); + + var paymentProcessor = new InvoiceService(repo); + + var payment = new Payment() + { + Amount = 6 + }; + + var result = paymentProcessor.ProcessPayment(payment); + + Assert.AreEqual("the payment is greater than the invoice amount", result); + } + + [Test] + public void ProcessPayment_Should_ReturnFullyPaidMessage_When_PartialPaymentExistsAndAmountPaidEqualsAmountDue() + { + IInvoiceRepository repo = new InvoiceRepository(); + var invoice = new Invoice() + { + Amount = 10, + AmountPaid = 5, + Payments = new List + { + new Payment + { + Amount = 5 + } + } + }; + repo.Add(invoice); + + var paymentProcessor = new InvoiceService(repo); + + var payment = new Payment() + { + Amount = 5 + }; + + var result = paymentProcessor.ProcessPayment(payment); + + Assert.AreEqual("final partial payment received, invoice is now fully paid", result); + } + + [Test] + public void ProcessPayment_Should_ReturnFullyPaidMessage_When_NoPartialPaymentExistsAndAmountPaidEqualsInvoiceAmount() + { + IInvoiceRepository repo = new InvoiceRepository(); + var invoice = new Invoice() + { + Amount = 10, + AmountPaid = 0, + Payments = new List() { new Payment() { Amount = 10 } } + }; + repo.Add(invoice); + + var paymentProcessor = new InvoiceService(repo); + + var payment = new Payment() + { + Amount = 10 + }; + + var result = paymentProcessor.ProcessPayment(payment); + + Assert.AreEqual("invoice was already fully paid", result); + } + + [Test] + public void ProcessPayment_Should_ReturnPartiallyPaidMessage_When_PartialPaymentExistsAndAmountPaidIsLessThanAmountDue() + { + IInvoiceRepository repo = new InvoiceRepository(); + var invoice = new Invoice() + { + Amount = 10, + AmountPaid = 5, + Payments = new List + { + new Payment + { + Amount = 5 + } + } + }; + repo.Add(invoice); + + var paymentProcessor = new InvoiceService(repo); + + var payment = new Payment() + { + Amount = 1 + }; + + var result = paymentProcessor.ProcessPayment(payment); + + Assert.AreEqual("another partial payment received, still not fully paid", result); + } + + [Test] + public void ProcessPayment_Should_ReturnPartiallyPaidMessage_When_NoPartialPaymentExistsAndAmountPaidIsLessThanInvoiceAmount() + { + IInvoiceRepository repo = new InvoiceRepository(); + var invoice = new Invoice() + { + Amount = 10, + AmountPaid = 0, + Payments = new List() + }; + repo.Add(invoice); + + var paymentProcessor = new InvoiceService(repo); + + var payment = new Payment() + { + Amount = 1 + }; + + var result = paymentProcessor.ProcessPayment(payment); + + Assert.AreEqual("invoice is now partially paid", result); + } + } } \ No newline at end of file diff --git a/RefactorThis.Domain.Tests/RefactorThis.Domain.Tests.csproj b/RefactorThis.Domain.Tests/RefactorThis.Domain.Tests.csproj index f118007..c7e786d 100644 --- a/RefactorThis.Domain.Tests/RefactorThis.Domain.Tests.csproj +++ b/RefactorThis.Domain.Tests/RefactorThis.Domain.Tests.csproj @@ -1,67 +1,148 @@  - - - Debug - AnyCPU - {7971BDEC-EAD1-4FB8-A4F5-B1F67E4F6355} - {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Properties - RefactorThis.Domain.Tests - RefactorThis.Domain.Tests - v4.7.2 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - ..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll - - - - - - - - - {5310b2fe-e26d-414e-b656-1f74c5a70368} - RefactorThis.Domain - - - {33cdc796-ff75-449c-9637-59c2efc46361} - RefactorThis.Persistence - - - - - - + \ No newline at end of file diff --git a/RefactorThis.Domain.Tests/app.config b/RefactorThis.Domain.Tests/app.config new file mode 100644 index 0000000..f10b4ac --- /dev/null +++ b/RefactorThis.Domain.Tests/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/RefactorThis.Domain.Tests/packages.config b/RefactorThis.Domain.Tests/packages.config index c108d44..76303f3 100644 --- a/RefactorThis.Domain.Tests/packages.config +++ b/RefactorThis.Domain.Tests/packages.config @@ -1,4 +1,20 @@  + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RefactorThis.Domain/InvoiceService.cs b/RefactorThis.Domain/InvoiceService.cs deleted file mode 100644 index fbd674c..0000000 --- a/RefactorThis.Domain/InvoiceService.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using System.Linq; -using RefactorThis.Persistence; - -namespace RefactorThis.Domain -{ - public class InvoiceService - { - private readonly InvoiceRepository _invoiceRepository; - - public InvoiceService( InvoiceRepository invoiceRepository ) - { - _invoiceRepository = invoiceRepository; - } - - public string ProcessPayment( Payment payment ) - { - var inv = _invoiceRepository.GetInvoice( payment.Reference ); - - var responseMessage = string.Empty; - - if ( inv == null ) - { - throw new InvalidOperationException( "There is no invoice matching this payment" ); - } - else - { - if ( inv.Amount == 0 ) - { - if ( inv.Payments == null || !inv.Payments.Any( ) ) - { - responseMessage = "no payment needed"; - } - else - { - throw new InvalidOperationException( "The invoice is in an invalid state, it has an amount of 0 and it has payments." ); - } - } - else - { - if ( inv.Payments != null && inv.Payments.Any( ) ) - { - if ( inv.Payments.Sum( x => x.Amount ) != 0 && inv.Amount == inv.Payments.Sum( x => x.Amount ) ) - { - responseMessage = "invoice was already fully paid"; - } - else if ( inv.Payments.Sum( x => x.Amount ) != 0 && payment.Amount > ( inv.Amount - inv.AmountPaid ) ) - { - responseMessage = "the payment is greater than the partial amount remaining"; - } - else - { - if ( ( inv.Amount - inv.AmountPaid ) == payment.Amount ) - { - switch ( inv.Type ) - { - case InvoiceType.Standard: - inv.AmountPaid += payment.Amount; - inv.Payments.Add( payment ); - responseMessage = "final partial payment received, invoice is now fully paid"; - break; - case InvoiceType.Commercial: - inv.AmountPaid += payment.Amount; - inv.TaxAmount += payment.Amount * 0.14m; - inv.Payments.Add( payment ); - responseMessage = "final partial payment received, invoice is now fully paid"; - break; - default: - throw new ArgumentOutOfRangeException( ); - } - - } - else - { - switch ( inv.Type ) - { - case InvoiceType.Standard: - inv.AmountPaid += payment.Amount; - inv.Payments.Add( payment ); - responseMessage = "another partial payment received, still not fully paid"; - break; - case InvoiceType.Commercial: - inv.AmountPaid += payment.Amount; - inv.TaxAmount += payment.Amount * 0.14m; - inv.Payments.Add( payment ); - responseMessage = "another partial payment received, still not fully paid"; - break; - default: - throw new ArgumentOutOfRangeException( ); - } - } - } - } - else - { - if ( payment.Amount > inv.Amount ) - { - responseMessage = "the payment is greater than the invoice amount"; - } - else if ( inv.Amount == payment.Amount ) - { - switch ( inv.Type ) - { - case InvoiceType.Standard: - inv.AmountPaid = payment.Amount; - inv.TaxAmount = payment.Amount * 0.14m; - inv.Payments.Add( payment ); - responseMessage = "invoice is now fully paid"; - break; - case InvoiceType.Commercial: - inv.AmountPaid = payment.Amount; - inv.TaxAmount = payment.Amount * 0.14m; - inv.Payments.Add( payment ); - responseMessage = "invoice is now fully paid"; - break; - default: - throw new ArgumentOutOfRangeException( ); - } - } - else - { - switch ( inv.Type ) - { - case InvoiceType.Standard: - inv.AmountPaid = payment.Amount; - inv.TaxAmount = payment.Amount * 0.14m; - inv.Payments.Add( payment ); - responseMessage = "invoice is now partially paid"; - break; - case InvoiceType.Commercial: - inv.AmountPaid = payment.Amount; - inv.TaxAmount = payment.Amount * 0.14m; - inv.Payments.Add( payment ); - responseMessage = "invoice is now partially paid"; - break; - default: - throw new ArgumentOutOfRangeException( ); - } - } - } - } - } - - inv.Save(); - - return responseMessage; - } - } -} \ No newline at end of file diff --git a/RefactorThis.Domain/RefactorThis.Domain.csproj b/RefactorThis.Domain/RefactorThis.Domain.csproj index 753e893..320e623 100644 --- a/RefactorThis.Domain/RefactorThis.Domain.csproj +++ b/RefactorThis.Domain/RefactorThis.Domain.csproj @@ -1,59 +1,58 @@  - - - Debug - AnyCPU - {5310B2FE-E26D-414E-B656-1F74C5A70368} - Library - Properties - RefactorThis.Domain - RefactorThis.Domain - v4.7.2 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - {33cdc796-ff75-449c-9637-59c2efc46361} - RefactorThis.Persistence - - - - - - + \ No newline at end of file diff --git a/RefactorThis.Domain/Service/InvoiceService.cs b/RefactorThis.Domain/Service/InvoiceService.cs new file mode 100644 index 0000000..f41b492 --- /dev/null +++ b/RefactorThis.Domain/Service/InvoiceService.cs @@ -0,0 +1,150 @@ +using RefactorThis.Persistence; +using RefactorThis.Persistence.IRepository; +using RefactorThis.Persistence.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RefactorThis.Domain.Service +{ + public class InvoiceService + { + private readonly IInvoiceRepository _invoiceRepository; + + public InvoiceService(IInvoiceRepository invoiceRepository) + { + _invoiceRepository = invoiceRepository; + } + + public string ProcessPayment(Payment payment) + { + var inv = _invoiceRepository.GetInvoice(payment.Reference); + + var responseMessage = string.Empty; + + if (inv == null) + { + responseMessage = "There is no invoice matching this payment"; + } + else + { + ValidateAndProcessInvoice(inv, payment, ref responseMessage); + } + + _invoiceRepository.SaveInvoice(inv); + + return responseMessage; + } + + private void ValidateAndProcessInvoice(Invoice inv, Payment payment, ref string responseMessage) + { + if (inv.Amount == 0) + { + responseMessage = (inv.Payments == null || !inv.Payments.Any()) ? "no payment needed" : "The invoice is in an invalid state, it has an amount of 0 and it has payments."; + } + else + { + ProcessInvoicePayment(inv, payment, ref responseMessage); + } + } + + private void ProcessInvoicePayment(Invoice inv, Payment payment, ref string responseMessage) + { + if (inv.Payments != null && inv.Payments.Any()) + { + HandleInvoiceWithBalancePayments(inv, payment, ref responseMessage); + + } + else + { + HandleNonPaidInvoice(inv, payment, ref responseMessage); + } + } + + private void HandleInvoiceWithBalancePayments(Invoice inv, Payment payment, ref string responseMessage) + { + decimal totalPayments = inv.Payments.Sum(x => x.Amount); + if (totalPayments != 0 && inv.Amount == totalPayments) + { + responseMessage = "invoice was already fully paid"; + } + else if (totalPayments != 0 && payment.Amount > (inv.Amount - inv.AmountPaid)) + { + responseMessage = "the payment is greater than the partial amount remaining"; + } + else + { + HandleInvoiceWithRemainingBalance(inv, payment, ref responseMessage); + } + } + + private void HandleInvoiceWithRemainingBalance(Invoice inv, Payment payment, ref string responseMessage) + { + if ((inv.Amount - inv.AmountPaid) == payment.Amount) + { + ProcessPaymentForPartiallyPaidInvoice(inv, payment, ref responseMessage, "final partial payment received, invoice is now fully paid"); + } + else + { + ProcessPaymentForPartiallyPaidInvoice(inv, payment, ref responseMessage, "another partial payment received, still not fully paid"); + } + } + + private void HandleNonPaidInvoice(Invoice inv, Payment payment, ref string responseMessage) + { + if (payment.Amount > inv.Amount) + { + responseMessage = "the payment is greater than the invoice amount"; + } + else if (inv.Amount == payment.Amount) + { + ProcessPaymentForNonPaidInvoice(inv, payment, ref responseMessage, "invoice is now fully paid"); + } + else + { + ProcessPaymentForNonPaidInvoice(inv, payment, ref responseMessage, "invoice is now partially paid"); + } + } + + private void ProcessPaymentForPartiallyPaidInvoice(Invoice inv, Payment payment, ref string responseMessage, string responseMessageContent) + { + switch (inv.Type) + { + case InvoiceType.Standard: + inv.AmountPaid += payment.Amount; + inv.Payments.Add(payment); + responseMessage = responseMessageContent; + break; + case InvoiceType.Commercial: + inv.AmountPaid += payment.Amount; + inv.TaxAmount += payment.Amount * 0.14m; + inv.Payments.Add(payment); + responseMessage = responseMessageContent; + break; + default: + responseMessage = "invoice type not recognized"; + break; + } + } + + private void ProcessPaymentForNonPaidInvoice(Invoice inv, Payment payment, ref string responseMessage, string responseMessageContent) + { + switch (inv.Type) + { + case InvoiceType.Standard: + case InvoiceType.Commercial: + inv.AmountPaid = payment.Amount; + inv.TaxAmount = payment.Amount * 0.14m; + inv.Payments.Add(payment); + responseMessage = responseMessageContent; + break; + default: + responseMessage = "invoice type not recognized"; + break; + } + } + + } +} diff --git a/RefactorThis.Persistence/IRepository/IInvoiceRepository.cs b/RefactorThis.Persistence/IRepository/IInvoiceRepository.cs new file mode 100644 index 0000000..f6a727b --- /dev/null +++ b/RefactorThis.Persistence/IRepository/IInvoiceRepository.cs @@ -0,0 +1,16 @@ +using RefactorThis.Persistence.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RefactorThis.Persistence.IRepository +{ + public interface IInvoiceRepository + { + Invoice GetInvoice(string reference); + void SaveInvoice(Invoice invoice); + void Add(Invoice invoice); + } +} diff --git a/RefactorThis.Persistence/Invoice.cs b/RefactorThis.Persistence/Invoice.cs deleted file mode 100644 index bd4370d..0000000 --- a/RefactorThis.Persistence/Invoice.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; - -namespace RefactorThis.Persistence -{ - public class Invoice - { - private readonly InvoiceRepository _repository; - public Invoice( InvoiceRepository repository ) - { - _repository = repository; - } - - public void Save( ) - { - _repository.SaveInvoice( this ); - } - - public decimal Amount { get; set; } - public decimal AmountPaid { get; set; } - public decimal TaxAmount { get; set; } - public List Payments { get; set; } - - public InvoiceType Type { get; set; } - } - - public enum InvoiceType - { - Standard, - Commercial - } -} \ No newline at end of file diff --git a/RefactorThis.Persistence/InvoiceRepository.cs b/RefactorThis.Persistence/InvoiceRepository.cs deleted file mode 100644 index 38548c7..0000000 --- a/RefactorThis.Persistence/InvoiceRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace RefactorThis.Persistence { - public class InvoiceRepository - { - private Invoice _invoice; - - public Invoice GetInvoice( string reference ) - { - return _invoice; - } - - public void SaveInvoice( Invoice invoice ) - { - //saves the invoice to the database - } - - public void Add( Invoice invoice ) - { - _invoice = invoice; - } - } -} \ No newline at end of file diff --git a/RefactorThis.Persistence/Models/Invoice.cs b/RefactorThis.Persistence/Models/Invoice.cs new file mode 100644 index 0000000..3ac2ce6 --- /dev/null +++ b/RefactorThis.Persistence/Models/Invoice.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RefactorThis.Persistence.Models +{ + public class Invoice + { + public decimal Amount { get; set; } + public decimal AmountPaid { get; set; } + public decimal TaxAmount { get; set; } + public List Payments { get; set; } + + public InvoiceType Type { get; set; } + } + + public enum InvoiceType + { + Standard, + Commercial + } +} diff --git a/RefactorThis.Persistence/Models/Payment.cs b/RefactorThis.Persistence/Models/Payment.cs new file mode 100644 index 0000000..5c63d5a --- /dev/null +++ b/RefactorThis.Persistence/Models/Payment.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RefactorThis.Persistence.Models +{ + public class Payment + { + public decimal Amount { get; set; } + public string Reference { get; set; } + } +} diff --git a/RefactorThis.Persistence/Payment.cs b/RefactorThis.Persistence/Payment.cs deleted file mode 100644 index db29372..0000000 --- a/RefactorThis.Persistence/Payment.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace RefactorThis.Persistence -{ - public class Payment - { - public decimal Amount { get; set; } - public string Reference { get; set; } - } -} \ No newline at end of file diff --git a/RefactorThis.Persistence/Repository/InvoiceRepository.cs b/RefactorThis.Persistence/Repository/InvoiceRepository.cs new file mode 100644 index 0000000..0073738 --- /dev/null +++ b/RefactorThis.Persistence/Repository/InvoiceRepository.cs @@ -0,0 +1,30 @@ +using RefactorThis.Persistence.IRepository; +using RefactorThis.Persistence.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RefactorThis.Persistence.Repository +{ + public class InvoiceRepository : IInvoiceRepository + { + private Invoice _invoice; + + public Invoice GetInvoice(string reference) + { + return _invoice; + } + + public void SaveInvoice(Invoice invoice) + { + //saves the invoice to the database + } + + public void Add(Invoice invoice) + { + _invoice = invoice; + } + } +}