How to test functions with complex data interactions

I am currently working on a system that performs quite a lot of reporting-style functions, which consumes many different data points and converts them into larger, sometimes flattened outputs. Most of my application is based on the repository template. Because of this, I have a set of mock repositories that I use to test scripts. The problem I am facing is that the interaction between these data points is so complex that it quickly becomes a service nightmare in order to maintain a “data layout”. Here is an example:

public class SomeReportingEntity
{
private IProductRepo ProductRepo;
private IManagerRepo ManagerRepo;
private ILocationRepo LocationRepo;
private IOrdersService OrdersService;
private IEmployeeRepo EmployeeRepo;

public ReportingEntity(IProductRepo ipr, IManagerRepo imr, ILocationRepo ilr, IOrdersService ios, 
    IEmployeeRepo ier){
        //Load these to private vars...
}

    //This is the function that I want to test...
public SomeReportingEntity GetManagerSalesByRegionReport()
{
    //Make a complex join on all sub collections.  These
    //sub collections are all under test individually.
    var MangerSalesByRegionItems = From x in ProductRepo.CurrentProducts()
                              Join y in OrdersService.FutureOrders() On ...
                              Join z in EmployeeRepo.ActiveEmployees() On  ...
                              Join a in LocationRepo.GetAllRegions() On ...
                              Join b In ManagerRepo.GetActiveManagers On ...
                              Select new SomeReportingEntity() With { ... }

    return MangerSalesByRegionItems.ToList();       
}

}

, , , , , , , , . - , , , - , . , mocks (, , ), , .

, :

  • "" , ? , .
  • ? , , . Linq , , .
+3
3

, , , , . , , .

, , , ( ). , . .

, . - , . UoW .

InMemoryUnitOfWork .

+1

. , , - , XML. XML . , , .

...

var object1 = XmlUtil.LoadObject1("filename1");
var object2 = XmlUtil.LoadObject2("filename2");

var result = SomeConverter.Convert(object1, object2);

Assert("somevalue", result.Property1);

, mock-, .

. , . , , . , , .

+1

, .

, , TDD. , GetManagerSalesByRegionReport ( ). :

  • unit test. : , .
  • , . void, .
  • .
  • List , .
  • , , , null. , , List, .

? INNER join, , . , : , , . . , , - .

, , , , .

, .

-1
source

All Articles