aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline.Tests
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-11 19:26:58 +0800
committercrupest <crupest@outlook.com>2022-04-11 19:26:58 +0800
commit88339df298016496d814e4df7d3abdf26e84447c (patch)
treec0bfbcc876cb40c4191830dea4dbbf2953187521 /BackEnd/Timeline.Tests
parentbd8ac38bae4cab90ccec79dbc48660ea990d3ead (diff)
downloadtimeline-88339df298016496d814e4df7d3abdf26e84447c.tar.gz
timeline-88339df298016496d814e4df7d3abdf26e84447c.tar.bz2
timeline-88339df298016496d814e4df7d3abdf26e84447c.zip
...
Diffstat (limited to 'BackEnd/Timeline.Tests')
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs15
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs1
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs51
3 files changed, 62 insertions, 5 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs b/BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs
index cd7daf3e..48496853 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs
@@ -12,7 +12,7 @@ namespace Timeline.Tests.IntegratedTests2
public static class HttpClientTestExtensions
{
- public static async Task<HttpResponseMessage> TestSendAsync(this HttpClient client, HttpMethod method, string url, HttpContent? body = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, RequestSetupAsync? requestSetup = null)
+ public static async Task<HttpResponseMessage> TestSendAsync(this HttpClient client, HttpMethod method, string url, HttpContent? body = null, HttpStatusCode? expectedStatusCode = null, RequestSetupAsync? requestSetup = null)
{
using var req = new HttpRequestMessage
{
@@ -23,7 +23,14 @@ namespace Timeline.Tests.IntegratedTests2
var task = requestSetup?.Invoke(req);
if (task is not null) await task;
var res = await client.SendAsync(req);
- res.StatusCode.Should().Be(expectedStatusCode);
+ if (expectedStatusCode is null)
+ {
+ ((int)res.StatusCode).Should().BeGreaterThanOrEqualTo(200).And.BeLessThan(300);
+ }
+ else
+ {
+ res.StatusCode.Should().Be(expectedStatusCode.Value);
+ }
return res;
}
@@ -34,13 +41,13 @@ namespace Timeline.Tests.IntegratedTests2
return body!;
}
- public static async Task TestJsonSendAsync(this HttpClient client, HttpMethod method, string url, object? jsonBody = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, RequestSetupAsync? requestSetup = null)
+ public static async Task TestJsonSendAsync(this HttpClient client, HttpMethod method, string url, object? jsonBody = null, HttpStatusCode? expectedStatusCode = null, RequestSetupAsync? requestSetup = null)
{
using JsonContent? reqContent = jsonBody is null ? null : JsonContent.Create(jsonBody, options: CommonJsonSerializeOptions.Options);
await client.TestSendAsync(method, url, reqContent, expectedStatusCode, requestSetup);
}
- public static async Task<T> TestJsonSendAsync<T>(this HttpClient client, HttpMethod method, string url, object? jsonBody = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, RequestSetupAsync? requestSetup = null)
+ public static async Task<T> TestJsonSendAsync<T>(this HttpClient client, HttpMethod method, string url, object? jsonBody = null, HttpStatusCode? expectedStatusCode = null, RequestSetupAsync? requestSetup = null)
{
using JsonContent? reqContent = jsonBody == null ? null : JsonContent.Create(jsonBody, options: CommonJsonSerializeOptions.Options);
var res = await client.TestSendAsync(method, url, reqContent, expectedStatusCode, requestSetup);
diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs
index bac132ba..f708381f 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs
@@ -23,7 +23,6 @@ namespace Timeline.Tests.IntegratedTests2
{
Name = "hello"
}, expectedStatusCode: HttpStatusCode.Created);
-
}
[Fact]
diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs
new file mode 100644
index 00000000..6bc93836
--- /dev/null
+++ b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest2.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Net;
+using System.Net.Http;
+using System.Threading.Tasks;
+using FluentAssertions;
+using Timeline.Models;
+using Timeline.Models.Http;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace Timeline.Tests.IntegratedTests2
+{
+ public class TimelineBookmarkTest2 : IntegratedTestBase
+ {
+ public TimelineBookmarkTest2(ITestOutputHelper testOutput) : base(testOutput)
+ {
+ }
+
+ protected override async Task OnInitializeAsync()
+ {
+ using var client = CreateClientAsUser();
+ await client.TestJsonSendAsync(HttpMethod.Post, "v2/timelines", new HttpTimelineCreateRequest
+ {
+ Name = "hello"
+ }, expectedStatusCode: HttpStatusCode.Created);
+
+ await client.TestJsonSendAsync(HttpMethod.Post, "v2/users/user/bookmarks", new HttpTimelineBookmarkCreateRequest
+ {
+ TimelineOwner = "user",
+ TimelineName = "hello"
+ }, expectedStatusCode: HttpStatusCode.Created);
+ }
+
+ [Fact]
+ public async Task ChangeVisibilityShouldWork()
+ {
+ using var client = CreateClientAsUser();
+ var a = await client.TestJsonSendAsync<HttpTimelineBookmarkVisibility>(HttpMethod.Get, "v2/users/user/bookmarks/visibility", expectedStatusCode: HttpStatusCode.OK);
+ a.Visibility.Should().Be(TimelineVisibility.Private);
+
+ await client.TestJsonSendAsync(HttpMethod.Put, "v2/users/user/bookmarks/visibility", new HttpTimelineBookmarkVisibility { Visibility = TimelineVisibility.Register }, expectedStatusCode: HttpStatusCode.NoContent);
+ var b = await client.TestJsonSendAsync<HttpTimelineBookmarkVisibility>(HttpMethod.Get, "v2/users/user/bookmarks/visibility", expectedStatusCode: HttpStatusCode.OK);
+ b.Visibility.Should().Be(TimelineVisibility.Register);
+
+ await client.TestJsonSendAsync(HttpMethod.Put, "v2/users/user/bookmarks/visibility", new HttpTimelineBookmarkVisibility { Visibility = TimelineVisibility.Public }, expectedStatusCode: HttpStatusCode.NoContent);
+ var c = await client.TestJsonSendAsync<HttpTimelineBookmarkVisibility>(HttpMethod.Get, "v2/users/user/bookmarks/visibility", expectedStatusCode: HttpStatusCode.OK);
+ c.Visibility.Should().Be(TimelineVisibility.Public);
+ }
+ }
+}
+