I have a trouble 'the Project Manager' give me a project (almost a final product) to test it.
It's a big project in Silverlight, that I coded the end part.
Here there a lot of problems (to Testing), the database connections(the data layer, services, session storage, etc) there in closed dll's from another project(which I don't have access to the source code), these dlls contains a Collection class like:
public class SomeCollection
{
public static SomeCollection GetCollectionByName(string name);
}
And there another utility class used to control threads, review errors, the finished/completion of data load, and probably more:
public static class BasicUtilities
{
public static T ExecuteAndFinish(this T baseclass, Action<T> loaded);
public static T ExecuteAndFinish(this T baseclass, Action<T> loaded, Action<bool> errors);
}
Then in the ViewModel where I need to load the data and populate it in a some kind of control, etc. A common call is like:
public class SomeViewModel : ViewModelBase
{
...
SomeCollection.GetCollectionByName("AIdentifier").ExecuteAndFinish
(collectionLoaded) =>
{
//do something with the collection, populate a control, grid, listbox, etc
});
...
}
Then I want to Test SomeViewModel, "clarifying" that I'm newbie in Tests. There a two frameworks that I could use, moq (for mocking special Models, UtilyClass, DataProviders , etc) or Ninject (for DI, I don't know much about it).
An approach could be overload the constructor of SomeViewModel for the test to pass a mocked object to a new Virtual property of type SomeCollection that replace the common call used:
public class SomeViewModel : ViewModelBase
{
...
SomeCollectionProperty.GetCollectionByName("AIdentifier").ExecuteAndFinish
(collectionLoaded) =>
{
//do something with the collection, populate a control, grid, listbox, etc
});
...
public virtual SomeClass SomeCollectionProperty { get; set; }
...
}
That don't will work because I can't mock the static method GetCollectionByName of the class SomeCollection, even worse I can't modify that dll's.
With DI seems that will happen something like this, and will not work, I don't know.
Seems that I need obligatorily modify the code of everywhere, but I can't modify the datalayer.dll(grouping it).
What I've to do? Many thanks.