diff --git a/src/GameServiceWarden.Host/Modules/ServiceManager.cs b/src/GameServiceWarden.Host/Modules/ServiceManager.cs index 26e3d90..c198493 100644 --- a/src/GameServiceWarden.Host/Modules/ServiceManager.cs +++ b/src/GameServiceWarden.Host/Modules/ServiceManager.cs @@ -47,6 +47,13 @@ namespace GameServiceWarden.Host.Modules services.Add(serviceName, new ServiceInfo(modules[assemblyName][moduleName].CreateGameService(), moduleName, assemblyName)); } + public void DeleteService(string serviceName) + { + if (!services.ContainsKey(serviceName)) throw new KeyNotFoundException($"Service under name \"{serviceName}\" not found."); + if (services[serviceName].GetServiceState() == ServiceState.Running) services[serviceName].Stop(); + services.Remove(serviceName); + } + public IReadOnlyCollection GetServiceNames() { string[] names = new string[services.Count]; diff --git a/src/GameServiceWarden.Host/UMLSketch.drawio b/src/GameServiceWarden.Host/UMLSketch.drawio index 660dfcb..b5305fc 100644 --- a/src/GameServiceWarden.Host/UMLSketch.drawio +++ b/src/GameServiceWarden.Host/UMLSketch.drawio @@ -1,240 +1,240 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -250,10 +250,10 @@ - + - + @@ -262,7 +262,7 @@ - + @@ -294,10 +294,10 @@ - + - + @@ -320,7 +320,7 @@ - + @@ -340,7 +340,7 @@ - + @@ -349,7 +349,7 @@ - + @@ -391,16 +391,16 @@ - + - + - + - + diff --git a/tests/GameServiceWarden.Host.Tests/Modules/ServiceManagerTest.cs b/tests/GameServiceWarden.Host.Tests/Modules/ServiceManagerTest.cs index 54493e7..30ada59 100644 --- a/tests/GameServiceWarden.Host.Tests/Modules/ServiceManagerTest.cs +++ b/tests/GameServiceWarden.Host.Tests/Modules/ServiceManagerTest.cs @@ -50,6 +50,22 @@ namespace GameServiceWarden.Host.Tests.Modules Assert.Contains(FAKE_SERVICE_NAME, serviceManager.GetServiceNames()); } + [Fact] + public void CreateService_OneService_ServiceDeleted() + { + //Given + const string ASSEMBLY_NAME = "FakeAssembly"; + const string FAKE_SERVICE_NAME = "FakeService"; + ServiceManager serviceManager = new ServiceManager(); + IGameServiceModule stubGameServiceModule = new FakeGameServiceModule(); + serviceManager.AddModule(ASSEMBLY_NAME, stubGameServiceModule); + serviceManager.CreateService(FAKE_SERVICE_NAME, ASSEMBLY_NAME, stubGameServiceModule.Name); + //When + serviceManager.DeleteService(FAKE_SERVICE_NAME); + //Then + Assert.DoesNotContain(FAKE_SERVICE_NAME, serviceManager.GetServiceNames()); + } + [Fact] public void GetServiceNames_MultipleServices_AllCorrectNames() {