mirror of
https://github.com/ncblakely/GiantsTools
synced 2024-12-04 02:33:10 +01:00
Add integration tests.
This commit is contained in:
parent
3ca6c77bc5
commit
2f198adbce
46
Giants.WebApi.Tests/BranchesControllerTests.cs
Normal file
46
Giants.WebApi.Tests/BranchesControllerTests.cs
Normal 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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
21
Giants.WebApi.Tests/Giants.WebApi.Tests.csproj
Normal file
21
Giants.WebApi.Tests/Giants.WebApi.Tests.csproj
Normal 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>
|
127
Giants.WebApi.Tests/VersionControllerTests.cs
Normal file
127
Giants.WebApi.Tests/VersionControllerTests.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
Giants.WebApi.Tests/appsettings.json
Normal file
9
Giants.WebApi.Tests/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
2223
Giants.WebApi.Tests/packages.lock.json
Normal file
2223
Giants.WebApi.Tests/packages.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user