diff options
Diffstat (limited to 'Timeline.Tests/IntegratedTests/UserDetailTest.cs')
-rw-r--r-- | Timeline.Tests/IntegratedTests/UserDetailTest.cs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Timeline.Tests/IntegratedTests/UserDetailTest.cs b/Timeline.Tests/IntegratedTests/UserDetailTest.cs index ff2c03a5..8f2b6925 100644 --- a/Timeline.Tests/IntegratedTests/UserDetailTest.cs +++ b/Timeline.Tests/IntegratedTests/UserDetailTest.cs @@ -2,6 +2,8 @@ using Microsoft.AspNetCore.Mvc.Testing;
using System;
using System.Net;
+using System.Net.Http.Headers;
+using System.Net.Mime;
using System.Threading.Tasks;
using Timeline.Tests.Helpers;
using Timeline.Tests.Helpers.Authentication;
@@ -79,5 +81,84 @@ namespace Timeline.Tests.IntegratedTests }
}
}
+
+ [Fact]
+ public async Task FunctionTest()
+ {
+ var url = $"users/{MockUser.User.Username}/nickname";
+ var userNotExistUrl = "users/usernotexist/nickname";
+ {
+ using var client = await _factory.CreateClientAsUser();
+ {
+ var res = await client.GetAsync(userNotExistUrl);
+ res.Should().HaveStatusCode(HttpStatusCode.NotFound)
+ .And.HaveCommonBody()
+ .Which.Code.Should().Be(ErrorCodes.Http.Filter.User.NotExist);
+
+ }
+ {
+ var res = await client.GetAsync(url);
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+ res.Content.Headers.ContentType.Should().Be(new MediaTypeHeaderValue(MediaTypeNames.Text.Plain) { CharSet = "utf-8" });
+ var body = await res.Content.ReadAsStringAsync();
+ body.Should().Be(MockUser.User.Username);
+ }
+ {
+ var res = await client.PutStringAsync(url, "");
+ res.Should().BeInvalidModel();
+ }
+ {
+ var res = await client.PutStringAsync(url, new string('a', 11));
+ res.Should().BeInvalidModel();
+ }
+ var nickname1 = "nnn";
+ var nickname2 = "nn2";
+ {
+ var res = await client.PutStringAsync(url, nickname1);
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+ (await client.GetStringAsync(url)).Should().Be(nickname1);
+ }
+ {
+ var res = await client.PutStringAsync(url, nickname2);
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+ (await client.GetStringAsync(url)).Should().Be(nickname2);
+ }
+ {
+ var res = await client.DeleteAsync(url);
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+ (await client.GetStringAsync(url)).Should().Be(MockUser.User.Username);
+ }
+ {
+ var res = await client.DeleteAsync(url);
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+ }
+ }
+ {
+ using var client = await _factory.CreateClientAsAdmin();
+ {
+ var res = await client.PutStringAsync(userNotExistUrl, "aaa");
+ res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
+ .And.HaveCommonBody()
+ .Which.Code.Should().Be(ErrorCodes.Http.Filter.User.NotExist);
+ }
+ {
+ var res = await client.DeleteAsync(userNotExistUrl);
+ res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
+ .And.HaveCommonBody()
+ .Which.Code.Should().Be(ErrorCodes.Http.Filter.User.NotExist);
+ }
+ var nickname = "nnn";
+ {
+ var res = await client.PutStringAsync(url, nickname);
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+ (await client.GetStringAsync(url)).Should().Be(nickname);
+ }
+ {
+ var res = await client.DeleteAsync(url);
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+ (await client.GetStringAsync(url)).Should().Be(MockUser.User.Username);
+ }
+ }
+ }
}
}
|