my Silverlight application architecture looks like this
BusinessLogic
Repository
DomainDataContext
Because of this everything happens asynchronously.
My business logic pulls data from the repositories, but again because
it is Async, I need to wait for a callback before I can do anything
with the data.
e.g.
interface IDataRepository
{
void GetMyData(Action<MyData> callback);
}
List<Entities> myList = new List<Entities>();
PopulateDropdownList()
{
IDataRepository repo = new DataRepository();
repo.GetMyData(callback =>
{
foreach(var item in callback.enities)
myList.Add(item);
});
}
I now want to unit test test the PopulateDropdownList() method to
check that when i get 5 items back from the repository, that the code
did update myList to have 5 items.
Doing it this way
http://gist.github.com/604153 does not work, as that
implies I have access to the callbac, which I wouldn't in this case.
Here is an example of how I'm trying to do the unit test
[TestMethod]
public void MyListShouldHave5Items()
{
// Arrange
var data = new List<MyData>{ new MyDa.....
var dataRepository = Substitute.For<IDataRepository>();
// need some code here to invoke the callback with the data
//dataRepository.WhenForAnyArgs(x =>
x.GetMyData()).Do( x(data)??
var viewModel = new ViewModel(dataRepository);
// Act
viewModel.PopulateDropdownList();
// Assert
Assert.AreEqual(5, viewModel.MyList.Count);
}