Created unit test project for MTSC

This commit is contained in:
2019-11-11 13:07:10 +01:00
parent 85f00e9dcd
commit 7850f6e4c2
4 changed files with 81 additions and 2 deletions
+49
View File
@@ -0,0 +1,49 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MTSC.Common.Http.ServerModules;
using MTSC.Exceptions;
using MTSC.Logging;
using MTSC.Server;
using MTSC.Server.Handlers;
using MTSC.Server.UsageMonitors;
using System;
using System.Net.Http;
using System.Runtime.CompilerServices;
namespace MTSC.UnitTests
{
[TestClass]
public class E2ETests
{
public TestContext TestContext { get; set; }
static Server.Server Server { get; set; }
[ClassInitialize]
public static void InitializeServer(TestContext testContext)
{
Server = new Server.Server(800)
.AddHandler(new HttpHandler()
.AddHttpModule(new HelloWorldModule())
)
.AddLogger(new ConsoleLogger())
.AddLogger(new DebugConsoleLogger())
.AddExceptionHandler(new ExceptionConsoleLogger())
.AddServerUsageMonitor(new TickrateEnforcer().SetTicksPerSecond(60));
Server.RunAsync().Start();
}
[TestMethod]
public void TestMethod1()
{
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://localhost:800");
var result = httpClient.GetAsync("").Result;
Assert.AreEqual(result.StatusCode, System.Net.HttpStatusCode.OK);
}
[ClassCleanup]
public static void CleanupServer()
{
Server.Stop();
}
}
}
+20
View File
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MTSC\MTSC.csproj" />
</ItemGroup>
</Project>