diff options
Diffstat (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs')
-rw-r--r-- | Timeline.Tests/IntegratedTests/TimelineTest.cs | 308 |
1 files changed, 198 insertions, 110 deletions
diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 720140f1..7206c675 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -43,7 +43,7 @@ namespace Timeline.Tests.IntegratedTests public TimelineTest(WebApplicationFactory<Startup> factory)
: base(factory, 3)
{
-
+ CreateTestTimelines().Wait();
}
private List<TimelineInfo> _testTimelines;
@@ -61,11 +61,38 @@ namespace Timeline.Tests.IntegratedTests }
}
+ private static string GeneratePersonalTimelineUrl(int id, string subpath = null)
+ {
+ return $"timelines/@{(id == 0 ? "admin" : ("user" + id))}{(subpath == null ? "" : ("/" + subpath))}";
+ }
+
+ private static string GenerateOrdinaryTimelineUrl(int id, string subpath = null)
+ {
+ return $"timelines/t{id}{(subpath == null ? "" : ("/" + subpath))}";
+ }
+
+ public static IEnumerable<object[]> TimelineUrlGeneratorData()
+ {
+ yield return new[] { new Func<int, string, string>(GeneratePersonalTimelineUrl) };
+ yield return new[] { new Func<int, string, string>(GenerateOrdinaryTimelineUrl) };
+ }
+
[Fact]
- public async Task TimelineList()
+ public async Task Personal_TimelineGet_Should_Work()
{
- await CreateTestTimelines();
+ using var client = await CreateDefaultClient();
+ var res = await client.GetAsync("timelines/@user1");
+ var body = res.Should().HaveStatusCode(200)
+ .And.HaveJsonBody<TimelineInfo>().Which;
+ body.Owner.Should().BeEquivalentTo(UserInfos[1]);
+ body.Visibility.Should().Be(TimelineVisibility.Register);
+ body.Description.Should().Be("");
+ body.Members.Should().NotBeNull().And.BeEmpty();
+ }
+ [Fact]
+ public async Task TimelineList()
+ {
TimelineInfo user1Timeline;
var client = await CreateDefaultClient();
@@ -91,8 +118,6 @@ namespace Timeline.Tests.IntegratedTests [Fact]
public async Task TimelineList_WithQuery()
{
- await CreateTestTimelines();
-
var testResultRelate = new List<TimelineInfo>();
var testResultOwn = new List<TimelineInfo>();
var testResultJoin = new List<TimelineInfo>();
@@ -336,7 +361,7 @@ namespace Timeline.Tests.IntegratedTests {
var res = await client.PostAsJsonAsync("timelines", new TimelineCreateRequest { Name = "aaa" });
res.Should().HaveStatusCode(400)
- .And.HaveCommonBody(ErrorCodes.TimelineCommon.NameConflict);
+ .And.HaveCommonBody(ErrorCodes.TimelineController.NameConflict);
}
}
}
@@ -344,8 +369,6 @@ namespace Timeline.Tests.IntegratedTests [Fact]
public async Task TimelineDelete_Should_Work()
{
- await CreateTestTimelines();
-
{
using var client = await CreateDefaultClient();
var res = await client.DeleteAsync("timelines/t1");
@@ -398,7 +421,7 @@ namespace Timeline.Tests.IntegratedTests }
[Fact]
- public async Task InvalidModel_BadName()
+ public async Task Ordinary_InvalidModel_BadName()
{
using var client = await CreateClientAsAdministrator();
{
@@ -432,49 +455,117 @@ namespace Timeline.Tests.IntegratedTests }
[Fact]
- public async Task NotFound()
+ public async Task Personal_InvalidModel_BadUsername()
+ {
+ using var client = await CreateClientAsAdministrator();
+ {
+ var res = await client.GetAsync("timelines/@user!!!");
+ res.Should().BeInvalidModel();
+ }
+ {
+ var res = await client.PatchAsJsonAsync("timelines/@user!!!", new TimelinePatchRequest { });
+ res.Should().BeInvalidModel();
+ }
+ {
+ var res = await client.PutAsync("timelines/@user!!!/members/user1", null);
+ res.Should().BeInvalidModel();
+ }
+ {
+ var res = await client.DeleteAsync("timelines/@user!!!/members/user1");
+ res.Should().BeInvalidModel();
+ }
+ {
+ var res = await client.GetAsync("timelines/@user!!!/posts");
+ res.Should().BeInvalidModel();
+ }
+ {
+ var res = await client.PostAsJsonAsync("timelines/@user!!!/posts", TimelineHelper.TextPostCreateRequest("aaa"));
+ res.Should().BeInvalidModel();
+ }
+ {
+ var res = await client.DeleteAsync("timelines/@user!!!/posts/123");
+ res.Should().BeInvalidModel();
+ }
+ }
+
+ [Fact]
+ public async Task Ordinary_NotFound()
{
using var client = await CreateClientAsAdministrator();
{
var res = await client.GetAsync("timelines/notexist");
- res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist);
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist);
}
{
var res = await client.PatchAsJsonAsync("timelines/notexist", new TimelinePatchRequest { });
- res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist);
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist);
}
{
var res = await client.PutAsync("timelines/notexist/members/user1", null);
- res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist);
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist);
}
{
var res = await client.DeleteAsync("timelines/notexist/members/user1");
- res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist);
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist);
}
{
var res = await client.GetAsync("timelines/notexist/posts");
- res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist);
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist);
}
{
var res = await client.PostAsJsonAsync("timelines/notexist/posts", TimelineHelper.TextPostCreateRequest("aaa"));
- res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist);
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist);
}
{
var res = await client.DeleteAsync("timelines/notexist/posts/123");
- res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineCommon.NotExist);
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.TimelineController.NotExist);
}
}
+
[Fact]
- public async Task Description_Should_Work()
+ public async Task PersonalNotFound()
{
- await CreateTestTimelines();
+ using var client = await CreateClientAsAdministrator();
+ {
+ var res = await client.GetAsync("timelines/@usernotexist");
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist);
+ }
+ {
+ var res = await client.PatchAsJsonAsync("timelines/@usernotexist", new TimelinePatchRequest { });
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist);
+ }
+ {
+ var res = await client.PutAsync("timelines/@usernotexist/members/user1", null);
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist);
+ }
+ {
+ var res = await client.DeleteAsync("timelines/@usernotexist/members/user1");
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist);
+ }
+ {
+ var res = await client.GetAsync("timelines/@usernotexist/posts");
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist);
+ }
+ {
+ var res = await client.PostAsJsonAsync("timelines/@usernotexist/posts", TimelineHelper.TextPostCreateRequest("aaa"));
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist);
+ }
+ {
+ var res = await client.DeleteAsync("timelines/@usernotexist/posts/123");
+ res.Should().HaveStatusCode(404).And.HaveCommonBody(ErrorCodes.UserCommon.NotExist);
+ }
+ }
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task Description_Should_Work(Func<int, string, string> generator)
+ {
using var client = await CreateClientAsUser();
async Task AssertDescription(string description)
{
- var res = await client.GetAsync("timelines/t1");
+ var res = await client.GetAsync(generator(1, null));
var body = res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelineInfo>()
.Which.Description.Should().Be(description);
@@ -484,21 +575,21 @@ namespace Timeline.Tests.IntegratedTests await AssertDescription("");
{
- var res = await client.PatchAsJsonAsync("timelines/t1",
+ var res = await client.PatchAsJsonAsync(generator(1, null),
new TimelinePatchRequest { Description = mockDescription });
res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelineInfo>().Which.Description.Should().Be(mockDescription);
await AssertDescription(mockDescription);
}
{
- var res = await client.PatchAsJsonAsync("timelines/t1",
+ var res = await client.PatchAsJsonAsync(generator(1, null),
new TimelinePatchRequest { Description = null });
res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelineInfo>().Which.Description.Should().Be(mockDescription);
await AssertDescription(mockDescription);
}
{
- var res = await client.PatchAsJsonAsync("timelines/t1",
+ var res = await client.PatchAsJsonAsync(generator(1, null),
new TimelinePatchRequest { Description = "" });
res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelineInfo>().Which.Description.Should().Be("");
@@ -506,12 +597,11 @@ namespace Timeline.Tests.IntegratedTests }
}
- [Fact]
- public async Task Member_Should_Work()
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task Member_Should_Work(Func<int, string, string> generator)
{
- await CreateTestTimelines();
-
- const string getUrl = "timelines/t1";
+ var getUrl = generator(1, null);
using var client = await CreateClientAsUser();
async Task AssertMembers(IList<UserInfo> members)
@@ -532,35 +622,40 @@ namespace Timeline.Tests.IntegratedTests await AssertEmptyMembers();
{
- var res = await client.PutAsync("/timelines/t1/members/usernotexist", null);
+ var res = await client.PutAsync(generator(1, "members/usernotexist"), null);
res.Should().HaveStatusCode(400)
- .And.HaveCommonBody(ErrorCodes.TimelineCommon.MemberPut_NotExist);
+ .And.HaveCommonBody(ErrorCodes.TimelineController.MemberPut_NotExist);
}
await AssertEmptyMembers();
{
- var res = await client.PutAsync("/timelines/t1/members/user2", null);
+ var res = await client.PutAsync(generator(1, "members/user2"), null);
res.Should().HaveStatusCode(200);
}
await AssertMembers(new List<UserInfo> { UserInfos[2] });
{
- var res = await client.DeleteAsync("/timelines/t1/members/user2");
+ var res = await client.DeleteAsync(generator(1, "members/user2"));
res.Should().BeDelete(true);
}
await AssertEmptyMembers();
{
- var res = await client.DeleteAsync("/timelines/t1/members/users2");
+ var res = await client.DeleteAsync(generator(1, "members/aaa"));
res.Should().BeDelete(false);
}
await AssertEmptyMembers();
}
[Theory]
- [InlineData(-1, 200, 401, 401, 401, 401)]
- [InlineData(1, 200, 200, 403, 200, 403)]
- [InlineData(0, 200, 200, 200, 200, 200)]
- public async Task Permission_Timeline(int userNumber, int get, int opPatchUser, int opPatchAdmin, int opMemberUser, int opMemberAdmin)
+ [InlineData(nameof(GenerateOrdinaryTimelineUrl), -1, 200, 401, 401, 401, 401)]
+ [InlineData(nameof(GenerateOrdinaryTimelineUrl), 1, 200, 200, 403, 200, 403)]
+ [InlineData(nameof(GenerateOrdinaryTimelineUrl), 0, 200, 200, 200, 200, 200)]
+ [InlineData(nameof(GeneratePersonalTimelineUrl), -1, 200, 401, 401, 401, 401)]
+ [InlineData(nameof(GeneratePersonalTimelineUrl), 1, 200, 200, 403, 200, 403)]
+ [InlineData(nameof(GeneratePersonalTimelineUrl), 0, 200, 200, 200, 200, 200)]
+
+ public async Task Permission_Timeline(string generatorName, int userNumber, int get, int opPatchUser, int opPatchAdmin, int opMemberUser, int opMemberAdmin)
{
- await CreateTestTimelines();
+ var method = GetType().GetMethod(generatorName, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
+ Func<int, string, string> generator = (int id, string subpath) => (string)method.Invoke(null, new object[] { id, subpath });
using var client = await CreateClientAs(userNumber);
{
@@ -569,48 +664,47 @@ namespace Timeline.Tests.IntegratedTests }
{
- var res = await client.PatchAsJsonAsync("timelines/t1", new TimelinePatchRequest { Description = "hahaha" });
+ var res = await client.PatchAsJsonAsync(generator(1, null), new TimelinePatchRequest { Description = "hahaha" });
res.Should().HaveStatusCode(opPatchUser);
}
{
- var res = await client.PatchAsJsonAsync("timelines/t0", new TimelinePatchRequest { Description = "hahaha" });
+ var res = await client.PatchAsJsonAsync(generator(0, null), new TimelinePatchRequest { Description = "hahaha" });
res.Should().HaveStatusCode(opPatchAdmin);
}
{
- var res = await client.PutAsync("timelines/t1/members/user2", null);
+ var res = await client.PutAsync(generator(1, "members/user2"), null);
res.Should().HaveStatusCode(opMemberUser);
}
{
- var res = await client.DeleteAsync("timelines/t1/members/user2");
+ var res = await client.DeleteAsync(generator(1, "members/user2"));
res.Should().HaveStatusCode(opMemberUser);
}
{
- var res = await client.PutAsync("timelines/t0/members/user2", null);
+ var res = await client.PutAsync(generator(0, "members/user2"), null);
res.Should().HaveStatusCode(opMemberAdmin);
}
{
- var res = await client.DeleteAsync("timelines/t0/members/user2");
+ var res = await client.DeleteAsync(generator(0, "members/user2"));
res.Should().HaveStatusCode(opMemberAdmin);
}
}
- [Fact]
- public async Task Visibility_Test()
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task Visibility_Test(Func<int, string, string> generator)
{
- await CreateTestTimelines();
-
- const string userUrl = "timelines/t1/posts";
- const string adminUrl = "timelines/t0/posts";
+ var userUrl = generator(1, "posts");
+ var adminUrl = generator(0, "posts");
{
using var client = await CreateClientAsUser();
using var content = new StringContent(@"{""visibility"":""abcdefg""}", System.Text.Encoding.UTF8, System.Net.Mime.MediaTypeNames.Application.Json);
- var res = await client.PatchAsync("timelines/t1", content);
+ var res = await client.PatchAsync(generator(1, null), content);
res.Should().BeInvalidModel();
}
{ // default visibility is registered
@@ -630,7 +724,7 @@ namespace Timeline.Tests.IntegratedTests { // change visibility to public
{
using var client = await CreateClientAsUser();
- var res = await client.PatchAsJsonAsync("timelines/t1",
+ var res = await client.PatchAsJsonAsync(generator(1, null),
new TimelinePatchRequest { Visibility = TimelineVisibility.Public });
res.Should().HaveStatusCode(200);
}
@@ -645,12 +739,12 @@ namespace Timeline.Tests.IntegratedTests {
using var client = await CreateClientAsAdministrator();
{
- var res = await client.PatchAsJsonAsync("timelines/t1",
+ var res = await client.PatchAsJsonAsync(generator(1, null),
new TimelinePatchRequest { Visibility = TimelineVisibility.Private });
res.Should().HaveStatusCode(200);
}
{
- var res = await client.PatchAsJsonAsync("timelines/t0",
+ var res = await client.PatchAsJsonAsync(generator(0, null),
new TimelinePatchRequest { Visibility = TimelineVisibility.Private });
res.Should().HaveStatusCode(200);
}
@@ -672,7 +766,7 @@ namespace Timeline.Tests.IntegratedTests }
{ // add member
using var client = await CreateClientAsAdministrator();
- var res = await client.PutAsync("/timelines/t0/members/user1", null);
+ var res = await client.PutAsync(generator(0, "members/user1"), null);
res.Should().HaveStatusCode(200);
}
{ // now user can read admin's
@@ -683,22 +777,20 @@ namespace Timeline.Tests.IntegratedTests }
}
-
- [Fact]
- public async Task Permission_Post_Create()
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task Permission_Post_Create(Func<int, string, string> generator)
{
- await CreateTestTimelines();
-
using (var client = await CreateClientAsUser())
{
- var res = await client.PutAsync("timelines/t1/members/user2", null);
+ var res = await client.PutAsync(generator(1, "members/user2"), null);
res.Should().HaveStatusCode(200);
}
using (var client = await CreateDefaultClient())
{
{ // no auth should get 401
- var res = await client.PostAsJsonAsync("timelines/t1/posts",
+ var res = await client.PostAsJsonAsync(generator(1, "posts"),
TimelineHelper.TextPostCreateRequest("aaa"));
res.Should().HaveStatusCode(401);
}
@@ -707,12 +799,12 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsUser())
{
{ // post self's
- var res = await client.PostAsJsonAsync("timelines/t1/posts",
+ var res = await client.PostAsJsonAsync(generator(1, "posts"),
TimelineHelper.TextPostCreateRequest("aaa"));
res.Should().HaveStatusCode(200);
}
{ // post other not as a member should get 403
- var res = await client.PostAsJsonAsync("timelines/t0/posts",
+ var res = await client.PostAsJsonAsync(generator(0, "posts"),
TimelineHelper.TextPostCreateRequest("aaa"));
res.Should().HaveStatusCode(403);
}
@@ -721,7 +813,7 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsAdministrator())
{
{ // post as admin
- var res = await client.PostAsJsonAsync("timelines/t1/posts",
+ var res = await client.PostAsJsonAsync(generator(1, "posts"),
TimelineHelper.TextPostCreateRequest("aaa"));
res.Should().HaveStatusCode(200);
}
@@ -730,22 +822,21 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAs(2))
{
{ // post as member
- var res = await client.PostAsJsonAsync("timelines/t1/posts",
+ var res = await client.PostAsJsonAsync(generator(1, "posts"),
TimelineHelper.TextPostCreateRequest("aaa"));
res.Should().HaveStatusCode(200);
}
}
}
- [Fact]
- public async Task Permission_Post_Delete()
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task Permission_Post_Delete(Func<int, string, string> generator)
{
- await CreateTestTimelines();
-
async Task<long> CreatePost(int userNumber)
{
using var client = await CreateClientAs(userNumber);
- var res = await client.PostAsJsonAsync($"timelines/t1/posts",
+ var res = await client.PostAsJsonAsync(generator(1, "posts"),
TimelineHelper.TextPostCreateRequest("aaa"));
return res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelinePostInfo>()
@@ -755,79 +846,78 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsUser())
{
{
- var res = await client.PutAsync("timelines/t1/members/user2", null);
+ var res = await client.PutAsync(generator(1, "members/user2"), null);
res.Should().HaveStatusCode(200);
}
{
- var res = await client.PutAsync("timelines/t1/members/user3", null);
+ var res = await client.PutAsync(generator(1, "members/user3"), null);
res.Should().HaveStatusCode(200);
}
}
{ // no auth should get 401
using var client = await CreateDefaultClient();
- var res = await client.DeleteAsync("timelines/t1/posts/12");
+ var res = await client.DeleteAsync(generator(1, "posts/12"));
res.Should().HaveStatusCode(401);
}
{ // self can delete self
var postId = await CreatePost(1);
using var client = await CreateClientAsUser();
- var res = await client.DeleteAsync($"timelines/t1/posts/{postId}");
+ var res = await client.DeleteAsync(generator(1, $"posts/{postId}"));
res.Should().HaveStatusCode(200);
}
{ // admin can delete any
var postId = await CreatePost(1);
using var client = await CreateClientAsAdministrator();
- var res = await client.DeleteAsync($"timelines/t1/posts/{postId}");
+ var res = await client.DeleteAsync(generator(1, $"posts/{postId}"));
res.Should().HaveStatusCode(200);
}
{ // owner can delete other
var postId = await CreatePost(2);
using var client = await CreateClientAsUser();
- var res = await client.DeleteAsync($"timelines/t1/posts/{postId}");
+ var res = await client.DeleteAsync(generator(1, $"posts/{postId}"));
res.Should().HaveStatusCode(200);
}
{ // author can delete self
var postId = await CreatePost(2);
using var client = await CreateClientAs(2);
- var res = await client.DeleteAsync($"timelines/t1/posts/{postId}");
+ var res = await client.DeleteAsync(generator(1, $"posts/{postId}"));
res.Should().HaveStatusCode(200);
}
{ // otherwise is forbidden
var postId = await CreatePost(2);
using var client = await CreateClientAs(3);
- var res = await client.DeleteAsync($"timelines/t1/posts/{postId}");
+ var res = await client.DeleteAsync(generator(1, $"posts/{postId}"));
res.Should().HaveStatusCode(403);
}
}
- [Fact]
- public async Task Post_Op_Should_Work()
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task Post_Op_Should_Work(Func<int, string, string> generator)
{
- await CreateTestTimelines();
-
{
using var client = await CreateClientAsUser();
{
- var res = await client.GetAsync("timelines/t1/posts");
+ var res = await client.GetAsync(generator(1, "posts"));
res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelinePostInfo[]>()
.Which.Should().NotBeNull().And.BeEmpty();
}
{
- var res = await client.PostAsJsonAsync("timelines/t1/posts",
+ var res = await client.PostAsJsonAsync(generator(1, "posts"),
TimelineHelper.TextPostCreateRequest(null));
res.Should().BeInvalidModel();
}
const string mockContent = "aaa";
TimelinePostInfo createRes;
{
- var res = await client.PostAsJsonAsync("timelines/t1/posts",
+ var res = await client.PostAsJsonAsync(generator(1, "posts"),
TimelineHelper.TextPostCreateRequest(mockContent));
var body = res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelinePostInfo>()
@@ -838,7 +928,7 @@ namespace Timeline.Tests.IntegratedTests createRes = body;
}
{
- var res = await client.GetAsync("timelines/t1/posts");
+ var res = await client.GetAsync(generator(1, "posts"));
res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelinePostInfo[]>()
.Which.Should().NotBeNull().And.BeEquivalentTo(createRes);
@@ -847,7 +937,7 @@ namespace Timeline.Tests.IntegratedTests var mockTime2 = DateTime.Now.AddDays(-1);
TimelinePostInfo createRes2;
{
- var res = await client.PostAsJsonAsync("timelines/t1/posts",
+ var res = await client.PostAsJsonAsync(generator(1, "posts"),
TimelineHelper.TextPostCreateRequest(mockContent2, mockTime2));
var body = res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelinePostInfo>()
@@ -859,25 +949,25 @@ namespace Timeline.Tests.IntegratedTests createRes2 = body;
}
{
- var res = await client.GetAsync("timelines/t1/posts");
+ var res = await client.GetAsync(generator(1, "posts"));
res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelinePostInfo[]>()
.Which.Should().NotBeNull().And.BeEquivalentTo(createRes, createRes2);
}
{
- var res = await client.DeleteAsync($"timelines/t1/posts/{createRes.Id}");
+ var res = await client.DeleteAsync(generator(1, $"posts/{createRes.Id}"));
res.Should().BeDelete(true);
}
{
- var res = await client.DeleteAsync($"timelines/t1/posts/{createRes.Id}");
+ var res = await client.DeleteAsync(generator(1, $"posts/{createRes.Id}"));
res.Should().BeDelete(false);
}
{
- var res = await client.DeleteAsync("timelines/t1/posts/30000");
+ var res = await client.DeleteAsync(generator(1, "posts/30000"));
res.Should().BeDelete(false);
}
{
- var res = await client.GetAsync("timelines/t1/posts");
+ var res = await client.GetAsync(generator(1, "posts"));
res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelinePostInfo[]>()
.Which.Should().NotBeNull().And.BeEquivalentTo(createRes2);
@@ -885,16 +975,15 @@ namespace Timeline.Tests.IntegratedTests }
}
- [Fact]
- public async Task GetPost_Should_Ordered()
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task GetPost_Should_Ordered(Func<int, string, string> generator)
{
- await CreateTestTimelines();
-
using var client = await CreateClientAsUser();
async Task<long> CreatePost(DateTime time)
{
- var res = await client.PostAsJsonAsync("timelines/t1/posts",
+ var res = await client.PostAsJsonAsync(generator(1, "posts"),
TimelineHelper.TextPostCreateRequest("aaa", time));
return res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelinePostInfo>()
@@ -907,54 +996,53 @@ namespace Timeline.Tests.IntegratedTests var id2 = await CreatePost(now);
{
- var res = await client.GetAsync("timelines/t1/posts");
+ var res = await client.GetAsync(generator(1, "posts"));
res.Should().HaveStatusCode(200)
.And.HaveJsonBody<TimelinePostInfo[]>()
.Which.Select(p => p.Id).Should().Equal(id1, id2, id0);
}
}
- [Fact]
- public async Task CreatePost_InvalidModel()
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task CreatePost_InvalidModel(Func<int, string, string> generator)
{
- await CreateTestTimelines();
-
using var client = await CreateClientAsUser();
{
- var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = null });
+ var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = null });
res.Should().BeInvalidModel();
}
{
- var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = null } });
+ var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = null } });
res.Should().BeInvalidModel();
}
{
- var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "hahaha" } });
+ var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "hahaha" } });
res.Should().BeInvalidModel();
}
{
- var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "text", Text = null } });
+ var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "text", Text = null } });
res.Should().BeInvalidModel();
}
{
- var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = null } });
+ var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = null } });
res.Should().BeInvalidModel();
}
{
// image not base64
- var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = "!!!" } });
+ var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = "!!!" } });
res.Should().BeInvalidModel();
}
{
// image base64 not image
- var res = await client.PostAsJsonAsync("timelines/t1/posts", new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = Convert.ToBase64String(new byte[] { 0x01, 0x02, 0x03 }) } });
+ var res = await client.PostAsJsonAsync(generator(1, "posts"), new TimelinePostCreateRequest { Content = new TimelinePostCreateRequestContent { Type = "image", Data = Convert.ToBase64String(new byte[] { 0x01, 0x02, 0x03 }) } });
res.Should().BeInvalidModel();
}
}
|