public class TestableRootWorkItem : WorkItem
{
public TestableRootWorkItem()
{
InitializeRootWorkItem(CreateBuilder());
Services.AddNew
Services.AddNew
Services.AddNew
}
public Builder Builder
{
get { return InnerBuilder; }
}
public IReadWriteLocator Locator
{
get { return InnerLocator; }
}
private Builder CreateBuilder()
{
Builder builder = new Builder(); builder.Strategies.AddNew
builder.Policies.SetDefault
return builder;
}
}
Mocks can be created using any Mocking Framework. In this example I have used Rhino Mocks. The dependencies can be added to the TesttableWorkItem class during the TestInitialize stage and then get it resolved in the TestMethods
[TestInitialize()]
public void MyTestInitialize()
{
IEmployeeService _employeeService = mocks.StrictMock
IListEmployeesView view = mocks.StrictMock
using (mocks.Record())
{
Expect.Call(_employeeService.GetCount()).Return(4);
}
workItem = new TestableRootWorkItem();
workItem.Services.Add
eventPublisher = workItem.Items.AddNew
eventSubscriber = workItem.Items.AddNew
presenter = workItem.Items.AddNew
presenter.View = view;
}
[TestMethod()]
public void GetCountTest()
{
int expected = 4;
int actual;
actual = presenter.GetCount();
Assert.AreEqual
}
[TestMethod]
public void EventPublicationSubscriptionTest()
{
eventPublisher.OnInsertEmployee(new EventArgs
Assert.AreEqual
Assert.AreEqual
}
No comments:
Post a Comment