This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
gameservicewarden/tests/GameServiceWarden.Host.Tests/Modules/FakeService.cs
Harrison Deng 4996982c89 ServiceManager completed and ServiceInfo modified to increase encapsulation.
ServiceManager tested and ServiceInfo tests updated to reflect changes.
2020-12-26 13:50:09 -06:00

47 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using GameServiceWarden.ModuleAPI;
namespace GameServiceWarden.Host.Tests.Modules
{
public class FakeService : IGameService
{
public IReadOnlyCollection<IConfigurable> Configurables { get; set; }
public event EventHandler<ServiceState> StateChangeEvent;
public ServiceState CurrentState { get; private set; } = ServiceState.Stopped;
private TextWriter consoleStream;
public FakeService(params IConfigurable[] configurables)
{
HashSet<IConfigurable> modifiable = new HashSet<IConfigurable>();
foreach (IConfigurable configurable in configurables)
{
modifiable.Add(configurable);
}
this.Configurables = modifiable;
}
public void ElegantShutdown()
{
CurrentState = ServiceState.Stopped;
StateChangeEvent?.Invoke(this, CurrentState);
}
public void ExecuteCommand(string command)
{
consoleStream.WriteLine(command);
consoleStream.Flush();
}
public void InitializeService(TextWriter stream)
{
CurrentState = ServiceState.Running;
StateChangeEvent?.Invoke(this, CurrentState);
this.consoleStream = stream;
}
}
}