c# - Refactoring Service Layer classes -


My company is on a unit test kick, and I'm having some difficulty with the refactoring service layer code. Here's an example of some code I wrote:

  Public class invoice Customer: IInvoiceCalculator {Public CalculateInvoice {Invoice Invoice} {foreach (invoiceIll in invoice.line) {UpdateLine (IL); } // Get tons of other stuff here;} Private Update Line (invoicing line) {line.Amount = line.Qty * line.Rate; // do a bunch of other stuff including calls for other personal methods}}  

In this simplified case (it has been reduced from 1,000 line squares which has 1 public method and ~ 30 Private people), my boss says that I should be able to check my CalculateInvoice and UpdateLine separately (UpdateLine actually calls 3 other personal methods, as well as calls the database). But how do I do this? Their suggested refactoring seemed a little complicated for me:

  Short code of the original code: Public class invoice: Clinicator: IInvoiceCalculator {public ILineUpdater _lineUpdater; Public Invoice Calculator (Ilinine Updater Line Updater) {_lineUpdater = lineUpdater; } Public Calculation Invoice (Invoice Invoice) {foreach (Invoice IL In Invoice Lines.) {_lineUpdater.UpdateLine (IL); } // Make a ton of other goods}} Public Square LineUpdater: ILineUpdater {Public UpdateLine (InvoiceLine line) {line.Amount = line.Qty * line.Rate; // do a bunch of other stuff}}  

I can see how dependency is broken now, and I can test both pieces, but this is my 20- 30 additional classes will also be created, we calculate the invoice only in one place, so these pieces will not actually be reusable.

Thank you!

Jess

IMO It all depends on the UpdateLine () method actually How important is it? If this is just an implementation description (like it can be easily inline with the calculated method) and the only thing that has hurt is readability), then you probably do not need to test it separately from the master class .

On the other hand, if UpdateLine () method has some value for business logic, you can imagine the situation when you will need to change this method independently from the remaining class (and hence Check it separately), then you should refract it with a separate lineupdater class.

You probably will not end this kind of with 20-30 squares, because most of these private methods are actually just implementation details and are not worth it to be tested separately.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -