I am trying to write a couple of classes using SOLID principles and having some trouble.
The problem is quite simple. I have an application that tracks leads. Leads are created when events are raised by the customer - eg file download, registration, page view, etc. A lead can have multiple opportunities - ie opportunities are for different products.
- A lead should be created if it doesn't exist.
- An opportunity should be created for that lead if it does not exist
- The lead score should be incremented based on some event scoring table
The way I wanted to do it was to have a LeadEventHandler class that calls three services TrackLead, TrackOpportunity and IncrementLeadScore. This seems ok, but testing the LeadEventHandler required me to use any-instance which is a code smell.
Note I know I could test the whole chain in LeadEventHandler, but for learning's sake I wanted to test in isolation. I could have injected the dependencies into LeadEventHandler, but this just didn't seem correct.
It would be great if I can let the tests drive my code, but I seem to run into quite a few stumbling blocks.