Implement some server and console stuff

This commit is contained in:
Jordan Brown
2018-04-04 20:29:48 -04:00
parent 196005f3a6
commit 15dc6bb2de
13 changed files with 101 additions and 10 deletions
+12 -5
View File
@@ -1,20 +1,27 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using System.Threading;
using System.Threading.Tasks;
namespace Tgstation.Server.Host.Console
{
/// <summary>
/// Contains the entrypoint for the application
/// </summary>
public static class Program
static class Program
{
/// <summary>
/// The <see cref="IServerFactory"/> for the <see cref="Program"/>
/// </summary>
internal static IServerFactory ServerFactory { get; set; } = new ServerFactory();
/// <summary>
/// Entrypoint for the application
/// </summary>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
public static Task Main()
internal static async Task Main()
{
System.Console.WriteLine("Hello world!");
return Task.CompletedTask;
using (var server = ServerFactory.CreateServer())
await server.RunAsync().ConfigureAwait(false);
}
}
}
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Tgstation.Server.Host.Tests")]
+18
View File
@@ -0,0 +1,18 @@
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Tgstation.Server.Host
{
/// <summary>
/// Represents the host
/// </summary>
public interface IServer : IDisposable
{
/// <summary>
/// Runs the <see cref="IServer"/>
/// </summary>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task RunAsync();
}
}
@@ -0,0 +1,14 @@
namespace Tgstation.Server.Host
{
/// <summary>
/// For creating <see cref="IServer"/>s
/// </summary>
public interface IServerFactory
{
/// <summary>
/// Create a <see cref="IServer"/>
/// </summary>
/// <returns>A new <see cref="IServer"/></returns>
IServer CreateServer();
}
}
+15
View File
@@ -0,0 +1,15 @@
using System.Threading;
using System.Threading.Tasks;
namespace Tgstation.Server.Host
{
/// <inheritdoc />
sealed class Server : IServer
{
/// <inheritdoc />
public void Dispose() { }
/// <inheritdoc />
public Task RunAsync() => Task.CompletedTask;
}
}
@@ -0,0 +1,9 @@
namespace Tgstation.Server.Host
{
/// <inheritdoc />
public sealed class ServerFactory : IServerFactory
{
/// <inheritdoc />
public IServer CreateServer() => new Server();
}
}
@@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
</ItemGroup>
@@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
</ItemGroup>
@@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
</ItemGroup>
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System.Threading.Tasks;
namespace Tgstation.Server.Host.Console.Tests
@@ -9,7 +10,14 @@ namespace Tgstation.Server.Host.Console.Tests
[TestMethod]
public async Task TestProgramRuns()
{
var mockServer = new Mock<IServer>();
mockServer.Setup(x => x.RunAsync()).Returns(Task.CompletedTask).Verifiable();
var mockServerFactory = new Mock<IServerFactory>();
mockServerFactory.Setup(x => x.CreateServer()).Returns(mockServer.Object).Verifiable();
Program.ServerFactory = mockServerFactory.Object;
await Program.Main().ConfigureAwait(false);
mockServer.VerifyAll();
mockServerFactory.VerifyAll();
}
}
}
@@ -8,7 +8,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Moq" Version="4.8.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
</ItemGroup>
@@ -0,0 +1,16 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Tgstation.Server.Host.Tests
{
[TestClass]
public sealed class TestServer
{
[TestMethod]
public async Task TestRunAndDispose()
{
using (var server = new Server())
await server.RunAsync().ConfigureAwait(false);
}
}
}
@@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
</ItemGroup>