[TestFixture]
public class ServiceStartupManagerTests
{
[Test, Category("TypeMock"), ClearMocks, VerifyMocks]
public void TestStartServices()
{
ServiceStartupOrder ds = new ServiceStartupOrder();
ds.ServiceList.AddServiceListRow("Test0", 0, 0); //ignore
ds.ServiceList.AddServiceListRow("Test1", 1, 2);
ds.ServiceList.AddServiceListRow("Test2", 2, 1);
//Setup the test
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
// CAUTION: ALL calls here are mocked!!!
ServiceManagerHelper helper = new ServiceManagerHelper();
StartupValidator val = new StartupValidator();
recorder.ExpectAndReturn(helper.StartService("Test1"), true);
recorder.ExpectAndReturn(helper.StartService("Test2"), true);
//recorder.ExpectAndReturn(val.ReadyForStartup(Guid.Empty),true);
recorder.CheckArguments();
}
ServiceStartupManager mgr = new ServiceStartupManager();
mgr.StartServices(ds);
MockManager.Verify();
MockManager.ClearAll();
}
[Test, Category("TypeMock"), ClearMocks, VerifyMocks]
//Test fails right now, we need to figure out how to clear the recorder between each test
public void TestStartServices_NotReady()
{
ServiceStartupOrder ds = new ServiceStartupOrder();
ds.ServiceList.AddServiceListRow("Test0", 0, 0); //ignore
ds.ServiceList.AddServiceListRow("Test1", 1, 2);
ds.ServiceList.AddServiceListRow("Test2", 2, 1);
//Setup the test
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
// CAUTION: ALL calls here are mocked!!!
ServiceManagerHelper helper = new ServiceManagerHelper();
StartupValidator val = new StartupValidator();
recorder.ExpectAndReturn(val.ReadyForStartup(Guid.Empty), false);
recorder.CheckArguments();
}
ServiceStartupManager mgr = new ServiceStartupManager();
mgr.StartServices(ds);
MockManager.Verify();
MockManager.ClearAll();
}
[Test, Category("TypeMock"), ClearMocks, VerifyMocks]
public void TestStopServices()
{
ServiceStartupOrder ds = new ServiceStartupOrder();
ds.ServiceList.AddServiceListRow("Test0", 0, 0); //ignore
ds.ServiceList.AddServiceListRow("Test1", 1, 2);
ds.ServiceList.AddServiceListRow("Test2", 2, 1);
//Setup the test
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
// CAUTION: ALL calls here are mocked!!!
ServiceManagerHelper helper = new ServiceManagerHelper();
recorder.ExpectAndReturn(helper.StopService("Test2"), true);
recorder.ExpectAndReturn(helper.StopService("Test1"), true);
recorder.CheckArguments();
}
ServiceStartupManager mgr = new ServiceStartupManager();
mgr.StopServices(ds);
MockManager.ClearAll();
MockManager.Verify();
}
}
the test TestStartServices_NotReady fails. This is because the call recorder.ExpectAndReturn(val.ReadyForStartup(Guid.Empty), false) did not really return false, it returned true. I guess this is because of the prev test. I tried clearMock, same thing.
Thanks for the fast response