aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline.Tests')
-rw-r--r--Timeline.Tests/Helpers/TestApplication.cs2
-rw-r--r--Timeline.Tests/IntegratedTests/FrontEndTest.cs34
-rw-r--r--Timeline.Tests/IntegratedTests/IntegratedTestBase.cs30
-rw-r--r--Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs26
4 files changed, 79 insertions, 13 deletions
diff --git a/Timeline.Tests/Helpers/TestApplication.cs b/Timeline.Tests/Helpers/TestApplication.cs
index 6e0a4ca6..abdb0a60 100644
--- a/Timeline.Tests/Helpers/TestApplication.cs
+++ b/Timeline.Tests/Helpers/TestApplication.cs
@@ -54,7 +54,7 @@ namespace Timeline.Tests.Helpers
{
config.AddInMemoryCollection(new Dictionary<string, string>
{
- [ApplicationConfiguration.DisableFrontEndKey] = "true",
+ [ApplicationConfiguration.UseMockFrontEndKey] = "true",
["WorkDir"] = WorkDir
});
});
diff --git a/Timeline.Tests/IntegratedTests/FrontEndTest.cs b/Timeline.Tests/IntegratedTests/FrontEndTest.cs
new file mode 100644
index 00000000..a00d41b1
--- /dev/null
+++ b/Timeline.Tests/IntegratedTests/FrontEndTest.cs
@@ -0,0 +1,34 @@
+using FluentAssertions;
+using Microsoft.AspNetCore.Mvc.Testing;
+using System.Net.Mime;
+using System.Threading.Tasks;
+using Timeline.Tests.Helpers;
+using Xunit;
+
+namespace Timeline.Tests.IntegratedTests
+{
+ public class FrontEndTest : IntegratedTestBase
+ {
+ public FrontEndTest(WebApplicationFactory<Startup> factory) : base(factory)
+ {
+ }
+
+ [Fact]
+ public async Task Index()
+ {
+ using var client = await CreateDefaultClient(false);
+ var res = await client.GetAsync("index.html");
+ res.Should().HaveStatusCode(200);
+ res.Content.Headers.ContentType.MediaType.Should().Be(MediaTypeNames.Text.Html);
+ }
+
+ [Fact]
+ public async Task Fallback()
+ {
+ using var client = await CreateDefaultClient(false);
+ var res = await client.GetAsync("aaaaaaaaaaaaaaa");
+ res.Should().HaveStatusCode(200);
+ res.Content.Headers.ContentType.MediaType.Should().Be(MediaTypeNames.Text.Html);
+ }
+ }
+}
diff --git a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs
index e42483bd..01544828 100644
--- a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs
+++ b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs
@@ -117,17 +117,23 @@ namespace Timeline.Tests.IntegratedTests
await TestApp.DisposeAsync();
}
- public Task<HttpClient> CreateDefaultClient()
+ public Task<HttpClient> CreateDefaultClient(bool setApiBase = true)
{
var client = Factory.CreateDefaultClient();
- client.BaseAddress = new Uri(client.BaseAddress, "api/");
+ if (setApiBase)
+ {
+ client.BaseAddress = new Uri(client.BaseAddress, "api/");
+ }
return Task.FromResult(client);
}
- public async Task<HttpClient> CreateClientWithCredential(string username, string password)
+ public async Task<HttpClient> CreateClientWithCredential(string username, string password, bool setApiBase = true)
{
var client = Factory.CreateDefaultClient();
- client.BaseAddress = new Uri(client.BaseAddress, "api/");
+ if (setApiBase)
+ {
+ client.BaseAddress = new Uri(client.BaseAddress, "api/");
+ }
var response = await client.PostAsJsonAsync("token/create",
new CreateTokenRequest { Username = username, Password = password });
var token = response.Should().HaveStatusCode(200)
@@ -136,24 +142,24 @@ namespace Timeline.Tests.IntegratedTests
return client;
}
- public Task<HttpClient> CreateClientAs(int userNumber)
+ public Task<HttpClient> CreateClientAs(int userNumber, bool setApiBase = true)
{
if (userNumber < 0)
- return CreateDefaultClient();
+ return CreateDefaultClient(setApiBase);
if (userNumber == 0)
- return CreateClientWithCredential("admin", "adminpw");
+ return CreateClientWithCredential("admin", "adminpw", setApiBase);
else
- return CreateClientWithCredential($"user{userNumber}", $"user{userNumber}pw");
+ return CreateClientWithCredential($"user{userNumber}", $"user{userNumber}pw", setApiBase);
}
- public Task<HttpClient> CreateClientAsAdministrator()
+ public Task<HttpClient> CreateClientAsAdministrator(bool setApiBase = true)
{
- return CreateClientAs(0);
+ return CreateClientAs(0, setApiBase);
}
- public Task<HttpClient> CreateClientAsUser()
+ public Task<HttpClient> CreateClientAsUser(bool setApiBase = true)
{
- return CreateClientAs(1);
+ return CreateClientAs(1, setApiBase);
}
}
}
diff --git a/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs b/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs
new file mode 100644
index 00000000..40f818a7
--- /dev/null
+++ b/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs
@@ -0,0 +1,26 @@
+using FluentAssertions;
+using Microsoft.AspNetCore.Mvc.Testing;
+using System.Threading.Tasks;
+using Timeline.Models.Http;
+using Timeline.Tests.Helpers;
+using Xunit;
+
+namespace Timeline.Tests.IntegratedTests
+{
+ public class UnknownEndpointTest : IntegratedTestBase
+ {
+ public UnknownEndpointTest(WebApplicationFactory<Startup> factory) : base(factory)
+ {
+ }
+
+ [Fact]
+ public async Task UnknownEndpoint()
+ {
+ using var client = await CreateDefaultClient();
+ var res = await client.GetAsync("unknownEndpoint");
+ res.Should().HaveStatusCode(400)
+ .And.HaveCommonBody()
+ .Which.Code.Should().Be(ErrorCodes.Common.UnknownEndpoint);
+ }
+ }
+}