public void SimpleTwoServicesWithDependency() { logger.Clear(); var manager = ServiceManager.Create(); // REGISTER IService service; var serviceObject1 = new TestService1(out service); manager.Manager.Register(service); Assert.AreEqual(1, manager.Manager.ListServices().Count()); var serviceObject2 = new TestService2(out service); manager.Manager.Register(service); Assert.AreEqual(2, manager.Manager.ListServices().Count()); var services = manager.Manager.ListServices().ToArray(); Assert.AreEqual(2, services.Length); var deps = manager.Manager.ListUnregisteredDependencies().ToArray(); Assert.AreEqual(0, deps.Length); // START manager.StartServices(new TaskContextMock(logger)); Assert.AreEqual(ServiceManager.ServiceManagerState.Started, manager.Manager.State); var walker = new MiniLoggerWalker(logger.First); walker.ExpectNext("Initializing service TestService1 - Progress: 0"); walker.ExpectNext("Initializing service TestService2 - Progress: 1"); walker.ExpectNext("Starting service TestService1 - Progress: 2"); walker.ExpectNext("Start TestService1"); walker.ExpectNext("Starting service TestService2 - Progress: 3"); walker.ExpectNext("Start TestService2"); walker.ExpectNext("Started all services - Progress: 4"); walker.ExpectEnd(); // ACCESS object serviceFromManager = manager.Manager.Get <TestService1>(); Assert.IsNotNull(serviceFromManager); Assert.AreSame(serviceFromManager, serviceObject1); serviceFromManager = manager.Manager.Get <TestService2>(); Assert.IsNotNull(serviceFromManager); Assert.AreSame(serviceFromManager, serviceObject2); // STOP manager.StopServices(new TaskContextMock(logger)); Assert.AreEqual(ServiceManager.ServiceManagerState.Stopped, manager.Manager.State); walker.ContinueAgain(); walker.ExpectNext("Stopping service TestService2 - Progress: 0"); walker.ExpectNext("Stop TestService2"); walker.ExpectNext("Stopping service TestService1 - Progress: 1"); walker.ExpectNext("Stop TestService1"); walker.ExpectNext("Stopped all services - Progress: 2"); walker.ExpectEnd(); }
public void OneService() { logger.Clear(); IService service; var serviceObject = new TestService1(out service); // REGISTER var manager = ServiceManager.Create(); manager.Manager.Register(service); var deps = manager.Manager.ListUnregisteredDependencies().ToArray(); Assert.AreEqual(0, deps.Length); TestService1 serviceFromManager; try { serviceFromManager = manager.Manager.Get <TestService1>(); Assert.Fail("Expected exception"); } catch { } // START manager.StartServices(new TaskContextMock(logger)); Assert.AreEqual(ServiceManager.ServiceManagerState.Started, manager.Manager.State); var walker = new MiniLoggerWalker(logger.First); walker.ExpectNext("Initializing service TestService1 - Progress: 0"); walker.ExpectNext("Starting service TestService1 - Progress: 1"); walker.ExpectNext("Start TestService1"); walker.ExpectNext("Started all services - Progress: 2"); walker.ExpectEnd(); // ACCESS serviceFromManager = manager.Manager.Get <TestService1>(); Assert.IsNotNull(serviceFromManager); Assert.AreSame(serviceFromManager, serviceObject); // STOP manager.StopServices(new TaskContextMock(logger)); Assert.AreEqual(ServiceManager.ServiceManagerState.Stopped, manager.Manager.State); walker.ContinueAgain(); walker.ExpectNext("Stopping service TestService1 - Progress: 0"); walker.ExpectNext("Stop TestService1"); walker.ExpectNext("Stopped all services - Progress: 1"); walker.ExpectEnd(); }