diff options
author | crupest <crupest@outlook.com> | 2020-06-14 16:34:42 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-14 16:34:42 +0800 |
commit | 53a0483ef11cce939b1df2f288563c888a1d0567 (patch) | |
tree | e998f8cdaf38ccd2c4725b16386f56b7162d7942 /Timeline.Tests/IntegratedTests/IntegratedTestBase.cs | |
parent | 5d467d950fd4078146709470084cbfae331b8b10 (diff) | |
download | timeline-53a0483ef11cce939b1df2f288563c888a1d0567.tar.gz timeline-53a0483ef11cce939b1df2f288563c888a1d0567.tar.bz2 timeline-53a0483ef11cce939b1df2f288563c888a1d0567.zip |
Many many bugs fix.
1. Add a way to test front end with mock page.
2. Unknown api returns 400 but not frontend page.
3. Fix a big bug that cause all data loss in database migration.
Diffstat (limited to 'Timeline.Tests/IntegratedTests/IntegratedTestBase.cs')
-rw-r--r-- | Timeline.Tests/IntegratedTests/IntegratedTestBase.cs | 30 |
1 files changed, 18 insertions, 12 deletions
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);
}
}
}
|