aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-11 18:22:43 +0800
committerGitHub <noreply@github.com>2020-08-11 18:22:43 +0800
commit2de24db92e892c6e3f18d9f5f05e8f3b7aba5c9e (patch)
tree56115decfb5e7e7e96c1d84161d7e7c920ce8cff /Timeline.Tests
parent06e79c99bbc810f16058b35f1c88c23148bf8e57 (diff)
parent12b5ecddb47e50c9f4597553a795c68b09acaddb (diff)
downloadtimeline-2de24db92e892c6e3f18d9f5f05e8f3b7aba5c9e.tar.gz
timeline-2de24db92e892c6e3f18d9f5f05e8f3b7aba5c9e.tar.bz2
timeline-2de24db92e892c6e3f18d9f5f05e8f3b7aba5c9e.zip
Merge pull request #146 from crupest/fix-141
Fix #141 .
Diffstat (limited to 'Timeline.Tests')
-rw-r--r--Timeline.Tests/Helpers/TestClock.cs4
-rw-r--r--Timeline.Tests/IntegratedTests/TimelineTest.cs4
-rw-r--r--Timeline.Tests/IntegratedTests/TokenTest.cs4
-rw-r--r--Timeline.Tests/Services/TimelineServiceTest.cs84
4 files changed, 90 insertions, 6 deletions
diff --git a/Timeline.Tests/Helpers/TestClock.cs b/Timeline.Tests/Helpers/TestClock.cs
index 0cbf236d..ed2d65a6 100644
--- a/Timeline.Tests/Helpers/TestClock.cs
+++ b/Timeline.Tests/Helpers/TestClock.cs
@@ -12,7 +12,7 @@ namespace Timeline.Tests.Helpers
public DateTime GetCurrentTime()
{
- return _currentTime ?? DateTime.Now;
+ return _currentTime ?? DateTime.UtcNow;
}
public void SetCurrentTime(DateTime? mockTime)
@@ -22,7 +22,7 @@ namespace Timeline.Tests.Helpers
public DateTime SetMockCurrentTime()
{
- var time = new DateTime(2000, 1, 1, 1, 1, 1);
+ var time = new DateTime(3000, 1, 1, 1, 1, 1, DateTimeKind.Utc);
_currentTime = time;
return time;
}
diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs
index 49672f29..16b3c7e4 100644
--- a/Timeline.Tests/IntegratedTests/TimelineTest.cs
+++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs
@@ -952,7 +952,7 @@ namespace Timeline.Tests.IntegratedTests
.Which.Should().NotBeNull().And.BeEquivalentTo(createRes);
}
const string mockContent2 = "bbb";
- var mockTime2 = DateTime.Now.AddDays(-1);
+ var mockTime2 = DateTime.UtcNow.AddDays(-1);
TimelinePostInfo createRes2;
{
var res = await client.PostAsJsonAsync(generator(1, "posts"),
@@ -1009,7 +1009,7 @@ namespace Timeline.Tests.IntegratedTests
.Which.Id;
}
- var now = DateTime.Now;
+ var now = DateTime.UtcNow;
var id0 = await CreatePost(now.AddDays(1));
var id1 = await CreatePost(now.AddDays(-1));
var id2 = await CreatePost(now);
diff --git a/Timeline.Tests/IntegratedTests/TokenTest.cs b/Timeline.Tests/IntegratedTests/TokenTest.cs
index d1c31606..480d66cd 100644
--- a/Timeline.Tests/IntegratedTests/TokenTest.cs
+++ b/Timeline.Tests/IntegratedTests/TokenTest.cs
@@ -119,9 +119,9 @@ namespace Timeline.Tests.IntegratedTests
using var client = await CreateDefaultClient();
var token = (await CreateUserTokenAsync(client, "user1", "user1pw")).Token;
- using (var scope = TestApp.Host.Services.CreateScope()) // UserService is scoped.
+ using (var scope = TestApp.Host.Services.CreateScope()) // UserDeleteService is scoped.
{
- var userService = scope.ServiceProvider.GetRequiredService<IUserService>();
+ var userService = scope.ServiceProvider.GetRequiredService<IUserDeleteService>();
await userService.DeleteUser("user1");
}
diff --git a/Timeline.Tests/Services/TimelineServiceTest.cs b/Timeline.Tests/Services/TimelineServiceTest.cs
index e129b49d..36e5ed0c 100644
--- a/Timeline.Tests/Services/TimelineServiceTest.cs
+++ b/Timeline.Tests/Services/TimelineServiceTest.cs
@@ -32,6 +32,8 @@ namespace Timeline.Tests.Services
private TimelineService _timelineService;
+ private UserDeleteService _userDeleteService;
+
public TimelineServiceTest()
{
}
@@ -43,6 +45,7 @@ namespace Timeline.Tests.Services
_dataManager = new DataManager(_databaseContext, _eTagGenerator);
_userService = new UserService(NullLogger<UserService>.Instance, _databaseContext, _passwordService, _clock);
_timelineService = new TimelineService(NullLogger<TimelineService>.Instance, _databaseContext, _dataManager, _userService, _imageValidator, _clock);
+ _userDeleteService = new UserDeleteService(NullLogger<UserDeleteService>.Instance, _databaseContext, _timelineService);
}
public async Task DisposeAsync()
@@ -187,5 +190,86 @@ namespace Timeline.Tests.Services
posts.Select(p => p.Deleted).Should().Equal(new bool[] { true, false, true, false });
posts.Where(p => !p.Deleted).Select(p => ((TextTimelinePostContent)p.Content).Text).Should().Equal(new string[] { "b", "d" });
}
+
+ [Theory]
+ [InlineData("@admin")]
+ [InlineData("tl")]
+ public async Task GetPosts_ModifiedSince_UsernameChange(string timelineName)
+ {
+ var time1 = _clock.ForwardCurrentTime();
+
+ var userId = await _userService.GetUserIdByUsername("user");
+
+ var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal);
+ if (!isPersonal)
+ await _timelineService.CreateTimeline(timelineName, userId);
+
+ var postContentList = new string[] { "a", "b", "c", "d" };
+
+ foreach (var (content, index) in postContentList.Select((v, i) => (v, i)))
+ {
+ await _timelineService.CreateTextPost(timelineName, userId, content, null);
+ }
+
+ var time2 = _clock.ForwardCurrentTime();
+
+ {
+ var posts = await _timelineService.GetPosts(timelineName, time2);
+ posts.Should().HaveCount(0);
+ }
+
+ {
+ await _userService.ModifyUser(userId, new User { Nickname = "haha" });
+ var posts = await _timelineService.GetPosts(timelineName, time2);
+ posts.Should().HaveCount(0);
+ }
+
+ {
+ await _userService.ModifyUser(userId, new User { Username = "haha" });
+ var posts = await _timelineService.GetPosts(timelineName, time2);
+ posts.Should().HaveCount(4);
+ }
+ }
+
+ [Theory]
+ [InlineData("@admin")]
+ [InlineData("tl")]
+ public async Task GetPosts_ModifiedSince_UserDelete(string timelineName)
+ {
+ var time1 = _clock.ForwardCurrentTime();
+
+ var userId = await _userService.GetUserIdByUsername("user");
+ var adminId = await _userService.GetUserIdByUsername("admin");
+
+ var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal);
+ if (!isPersonal)
+ await _timelineService.CreateTimeline(timelineName, adminId);
+
+ var postContentList = new string[] { "a", "b", "c", "d" };
+
+ foreach (var (content, index) in postContentList.Select((v, i) => (v, i)))
+ {
+ await _timelineService.CreateTextPost(timelineName, userId, content, null);
+ }
+
+ var time2 = _clock.ForwardCurrentTime();
+
+ {
+ var posts = await _timelineService.GetPosts(timelineName, time2);
+ posts.Should().HaveCount(0);
+ }
+
+ await _userDeleteService.DeleteUser("user");
+
+ {
+ var posts = await _timelineService.GetPosts(timelineName, time2);
+ posts.Should().HaveCount(0);
+ }
+
+ {
+ var posts = await _timelineService.GetPosts(timelineName, time2, true);
+ posts.Should().HaveCount(4);
+ }
+ }
}
}