1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-12-03 18:33:08 +01:00

Add integration tests.

This commit is contained in:
Nick Blakely 2022-09-09 19:46:25 -07:00
parent 3ca6c77bc5
commit 2f198adbce
5 changed files with 2426 additions and 0 deletions

View File

@ -0,0 +1,46 @@
using Giants.Web;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text.Json;
using static System.Net.Mime.MediaTypeNames;
namespace Giants.WebApi.Tests
{
[TestClass]
public class BranchesControllerTests
{
private readonly JsonSerializerOptions options = new(JsonSerializerDefaults.Web);
private static WebApplicationFactory<Program>? application;
private static HttpClient? client;
[ClassInitialize]
public static void Initialize(TestContext context)
{
application = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
});
client = application.CreateClient();
}
[TestMethod]
public async Task GetBranchesReturnsExpectedBranches()
{
using (var response = await client!.GetAsync("api/branches?appName=Giants"))
{
response.EnsureSuccessStatusCode();
string responseContent = await response.Content.ReadAsStringAsync();
var responseObject = JsonSerializer.Deserialize<IEnumerable<string>>(responseContent, options);
Assert.IsNotNull(responseObject);
Assert.AreEqual(2, responseObject.Count());
Assert.IsTrue(responseObject.Any(x => x == "Release"));
Assert.IsTrue(responseObject.Any(x => x == "Beta"));
}
}
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Giants.WebApi\Giants.WebApi.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,127 @@
using Giants.DataContract.V1;
using Giants.Web;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text.Json;
namespace Giants.WebApi.Tests
{
[TestClass]
public class VersionControllerTests
{
private readonly JsonSerializerOptions options = new(JsonSerializerDefaults.Web);
private static WebApplicationFactory<Program>? application;
private static HttpClient? client;
[ClassInitialize]
public static void Initialize(TestContext context)
{
application = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
});
client = application.CreateClient();
}
[TestMethod]
public async Task GetVersionSupportsApiVersion1_0()
{
using (var response = await client!.GetAsync("api/version?appName=Giants"))
{
response.EnsureSuccessStatusCode();
string responseContent = await response.Content.ReadAsStringAsync();
var responseObject = JsonSerializer.Deserialize<VersionInfo>(responseContent, options);
Assert.IsNotNull(responseObject);
Assert.AreEqual("Giants", responseObject.AppName);
Assert.IsNotNull(responseObject.Version);
Assert.IsTrue(responseObject.InstallerUri.ToString().StartsWith("https://giants.blob.core.windows.net/public/GPatch"));
Assert.AreEqual("Release", responseObject.BranchName);
}
}
[TestMethod]
public async Task GetLauncherVersionSupportsApiVersion1_0()
{
using (var response = await client!.GetAsync("api/version?appName=GiantsLauncher"))
{
response.EnsureSuccessStatusCode();
string responseContent = await response.Content.ReadAsStringAsync();
var responseObject = JsonSerializer.Deserialize<VersionInfo>(responseContent, options);
Assert.IsNotNull(responseObject);
Assert.AreEqual("GiantsLauncher", responseObject.AppName);
Assert.IsNotNull(responseObject.Version);
Assert.IsTrue(responseObject.InstallerUri.ToString().StartsWith("about:blank"));
Assert.AreEqual("Release", responseObject.BranchName);
}
}
[TestMethod]
public async Task GetVersionFiltersByBranchNameCorrectly()
{
using (var response = await client!.GetAsync("api/version?appName=Giants&branchName=Release&apiVersion=1.1"))
{
response.EnsureSuccessStatusCode();
string responseContent = await response.Content.ReadAsStringAsync();
var responseObject = JsonSerializer.Deserialize<VersionInfo>(responseContent, options);
Assert.IsNotNull(responseObject);
Assert.AreEqual("Giants", responseObject.AppName);
Assert.IsNotNull(responseObject.Version);
Assert.IsTrue(responseObject.InstallerUri.ToString().StartsWith("https://giants.blob.core.windows.net/public/GPatch"));
Assert.AreEqual("Release", responseObject.BranchName);
}
using (var response = await client!.GetAsync("api/version?appName=Giants&branchName=Beta&apiVersion=1.1"))
{
response.EnsureSuccessStatusCode();
string responseContent = await response.Content.ReadAsStringAsync();
var responseObject = JsonSerializer.Deserialize<VersionInfo>(responseContent, options);
Assert.IsNotNull(responseObject);
Assert.AreEqual("Giants", responseObject.AppName);
Assert.IsNotNull(responseObject.Version);
Assert.IsTrue(responseObject.InstallerUri.ToString().StartsWith("https://giants.blob.core.windows.net/public/GPatch"));
Assert.AreEqual("Beta", responseObject.BranchName);
}
}
[TestMethod]
public async Task GetLauncherVersionFiltersByBranchNameCorrectly()
{
using (var response = await client!.GetAsync("api/version?appName=GiantsLauncher&branchName=Release&apiVersion=1.1"))
{
response.EnsureSuccessStatusCode();
string responseContent = await response.Content.ReadAsStringAsync();
var responseObject = JsonSerializer.Deserialize<VersionInfo>(responseContent, options);
Assert.IsNotNull(responseObject);
Assert.AreEqual("GiantsLauncher", responseObject.AppName);
Assert.IsNotNull(responseObject.Version);
Assert.IsTrue(responseObject.InstallerUri.ToString().StartsWith("about:blank"));
Assert.AreEqual("Release", responseObject.BranchName);
}
using (var response = await client!.GetAsync("api/version?appName=GiantsLauncher&branchName=Beta&apiVersion=1.1"))
{
response.EnsureSuccessStatusCode();
string responseContent = await response.Content.ReadAsStringAsync();
var responseObject = JsonSerializer.Deserialize<VersionInfo>(responseContent, options);
Assert.IsNotNull(responseObject);
Assert.AreEqual("GiantsLauncher", responseObject.AppName);
Assert.IsNotNull(responseObject.Version);
Assert.IsTrue(responseObject.InstallerUri.ToString().StartsWith("about:blank"));
Assert.AreEqual("Beta", responseObject.BranchName);
}
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

File diff suppressed because it is too large Load Diff