aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline.Tests/Services
diff options
context:
space:
mode:
Diffstat (limited to 'BackEnd/Timeline.Tests/Services')
-rw-r--r--BackEnd/Timeline.Tests/Services/BookmarkTimelineServiceTest.cs102
-rw-r--r--BackEnd/Timeline.Tests/Services/HighlightTimelineServiceTest.cs96
-rw-r--r--BackEnd/Timeline.Tests/Services/TimelinePostServiceTest.cs200
-rw-r--r--BackEnd/Timeline.Tests/Services/TimelineServiceTest.cs149
4 files changed, 0 insertions, 547 deletions
diff --git a/BackEnd/Timeline.Tests/Services/BookmarkTimelineServiceTest.cs b/BackEnd/Timeline.Tests/Services/BookmarkTimelineServiceTest.cs
deleted file mode 100644
index 849936ec..00000000
--- a/BackEnd/Timeline.Tests/Services/BookmarkTimelineServiceTest.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-using FluentAssertions;
-using Microsoft.Extensions.Logging.Abstractions;
-using System.Threading.Tasks;
-using Timeline.Services;
-using Timeline.Tests.Helpers;
-using Xunit;
-
-namespace Timeline.Tests.Services
-{
- public class BookmarkTimelineServiceTest : DatabaseBasedTest
- {
- private BookmarkTimelineService _service = default!;
- private UserService _userService = default!;
- private TimelineService _timelineService = default!;
-
- protected override void OnDatabaseCreated()
- {
- var clock = new TestClock();
- _userService = new UserService(NullLogger<UserService>.Instance, Database, new PasswordService(), new UserPermissionService(Database), clock);
- _timelineService = new TimelineService(Database, _userService, clock);
- _service = new BookmarkTimelineService(Database, _userService, _timelineService);
- }
-
- [Fact]
- public async Task Should_Work()
- {
- var userId = await _userService.GetUserIdByUsername("user");
-
- {
- var b = await _service.GetBookmarks(userId);
- b.Should().BeEmpty();
- }
-
- await _timelineService.CreateTimeline("tl", userId);
- await _service.AddBookmark(userId, "tl");
-
- {
- var b = await _service.GetBookmarks(userId);
- b.Should().HaveCount(1).And.BeEquivalentTo(await _timelineService.GetTimeline("tl"));
- }
- }
-
- [Fact]
- public async Task NewOne_Should_BeAtLast()
- {
- var userId = await _userService.GetUserIdByUsername("user");
- await _timelineService.CreateTimeline("t1", userId);
- await _service.AddBookmark(userId, "t1");
-
- await _timelineService.CreateTimeline("t2", userId);
- await _service.AddBookmark(userId, "t2");
-
- var b = await _service.GetBookmarks(userId);
-
- b.Should().HaveCount(2);
- b[0].Name.Should().Be("t1");
- b[1].Name.Should().Be("t2");
- }
-
- [Fact]
- public async Task Multiple_Should_Work()
- {
- var userId = await _userService.GetUserIdByUsername("user");
-
- // make timeline id not same as entity id.
- await _timelineService.CreateTimeline("t0", userId);
-
- await _timelineService.CreateTimeline("t1", userId);
- await _service.AddBookmark(userId, "t1");
-
- await _timelineService.CreateTimeline("t2", userId);
- await _service.AddBookmark(userId, "t2");
-
- await _timelineService.CreateTimeline("t3", userId);
- await _service.AddBookmark(userId, "t3");
-
- await _service.MoveBookmark(userId, "t3", 2);
- (await _service.GetBookmarks(userId))[1].Name.Should().Be("t3");
-
- await _service.MoveBookmark(userId, "t1", 3);
- (await _service.GetBookmarks(userId))[2].Name.Should().Be("t1");
-
- await _service.RemoveBookmark(userId, "t2");
- await _service.RemoveBookmark(userId, "t1");
- await _service.RemoveBookmark(userId, "t3");
- (await _service.GetBookmarks(userId)).Should().BeEmpty();
- }
-
- [Fact]
- public async Task AddExist_Should_DoNothing()
- {
- var userId = await _userService.GetUserIdByUsername("user");
-
- await _timelineService.CreateTimeline("t", userId);
-
- await _service.AddBookmark(userId, "t");
- await _service.AddBookmark(userId, "t");
-
- (await _service.GetBookmarks(userId)).Should().HaveCount(1);
- }
- }
-}
diff --git a/BackEnd/Timeline.Tests/Services/HighlightTimelineServiceTest.cs b/BackEnd/Timeline.Tests/Services/HighlightTimelineServiceTest.cs
deleted file mode 100644
index f48404a9..00000000
--- a/BackEnd/Timeline.Tests/Services/HighlightTimelineServiceTest.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-using FluentAssertions;
-using Microsoft.Extensions.Logging.Abstractions;
-using System.Threading.Tasks;
-using Timeline.Services;
-using Timeline.Tests.Helpers;
-using Xunit;
-using Xunit.Abstractions;
-
-namespace Timeline.Tests.Services
-{
- public class HighlightTimelineServiceTest : DatabaseBasedTest
- {
- private readonly TestClock _clock = new TestClock();
- private UserService _userService = default!;
- private TimelineService _timelineService = default!;
-
- private HighlightTimelineService _service = default!;
-
- public HighlightTimelineServiceTest(ITestOutputHelper testOutputHelper)
- : base(testOutputHelper)
- {
-
- }
-
- protected override void OnDatabaseCreated()
- {
- _userService = new UserService(NullLogger<UserService>.Instance, Database, new PasswordService(), new UserPermissionService(Database), _clock);
- _timelineService = new TimelineService(Database, _userService, _clock);
- _service = new HighlightTimelineService(Database, _userService, _timelineService, _clock);
- }
-
- [Fact]
- public async Task Should_Work()
- {
- {
- var ht = await _service.GetHighlightTimelines();
- ht.Should().BeEmpty();
- }
-
- var userId = await _userService.GetUserIdByUsername("user");
- await _timelineService.CreateTimeline("tl", userId);
- await _service.AddHighlightTimeline("tl", userId);
-
- {
- var ht = await _service.GetHighlightTimelines();
- ht.Should().HaveCount(1).And.BeEquivalentTo(await _timelineService.GetTimeline("tl"));
- }
- }
-
- [Fact]
- public async Task NewOne_Should_BeAtLast()
- {
- var userId = await _userService.GetUserIdByUsername("user");
- await _timelineService.CreateTimeline("t1", userId);
- await _service.AddHighlightTimeline("t1", userId);
-
- await _timelineService.CreateTimeline("t2", userId);
- await _service.AddHighlightTimeline("t2", userId);
-
- var ht = await _service.GetHighlightTimelines();
-
- ht.Should().HaveCount(2);
- ht[0].Name.Should().Be("t1");
- ht[1].Name.Should().Be("t2");
- }
-
- [Fact]
- public async Task Multiple_Should_Work()
- {
- var userId = await _userService.GetUserIdByUsername("user");
-
- // make timeline id not same as entity id.
- await _timelineService.CreateTimeline("t0", userId);
-
- await _timelineService.CreateTimeline("t1", userId);
- await _service.AddHighlightTimeline("t1", userId);
-
- await _timelineService.CreateTimeline("t2", userId);
- await _service.AddHighlightTimeline("t2", userId);
-
- await _timelineService.CreateTimeline("t3", userId);
- await _service.AddHighlightTimeline("t3", userId);
-
- await _service.MoveHighlightTimeline("t3", 2);
- (await _service.GetHighlightTimelines())[1].Name.Should().Be("t3");
-
- await _service.MoveHighlightTimeline("t1", 3);
- (await _service.GetHighlightTimelines())[2].Name.Should().Be("t1");
-
- await _service.RemoveHighlightTimeline("t2", userId);
- await _service.RemoveHighlightTimeline("t1", userId);
- await _service.RemoveHighlightTimeline("t3", userId);
- (await _service.GetHighlightTimelines()).Should().BeEmpty();
- }
- }
-}
diff --git a/BackEnd/Timeline.Tests/Services/TimelinePostServiceTest.cs b/BackEnd/Timeline.Tests/Services/TimelinePostServiceTest.cs
deleted file mode 100644
index 7771ae0b..00000000
--- a/BackEnd/Timeline.Tests/Services/TimelinePostServiceTest.cs
+++ /dev/null
@@ -1,200 +0,0 @@
-using FluentAssertions;
-using Microsoft.Extensions.Logging.Abstractions;
-using System;
-using System.Linq;
-using System.Threading.Tasks;
-using Timeline.Models;
-using Timeline.Services;
-using Timeline.Tests.Helpers;
-using Xunit;
-
-namespace Timeline.Tests.Services
-{
- public class TimelinePostServiceTest : DatabaseBasedTest
- {
- private readonly PasswordService _passwordService = new PasswordService();
-
- private readonly ETagGenerator _eTagGenerator = new ETagGenerator();
-
- private readonly ImageValidator _imageValidator = new ImageValidator();
-
- private readonly TestClock _clock = new TestClock();
-
- private DataManager _dataManager = default!;
-
- private UserPermissionService _userPermissionService = default!;
-
- private UserService _userService = default!;
-
- private TimelineService _timelineService = default!;
-
- private TimelinePostService _timelinePostService = default!;
-
- private UserDeleteService _userDeleteService = default!;
-
- protected override void OnDatabaseCreated()
- {
- _dataManager = new DataManager(Database, _eTagGenerator);
- _userPermissionService = new UserPermissionService(Database);
- _userService = new UserService(NullLogger<UserService>.Instance, Database, _passwordService, _userPermissionService, _clock);
- _timelineService = new TimelineService(Database, _userService, _clock);
- _timelinePostService = new TimelinePostService(NullLogger<TimelinePostService>.Instance, Database, _timelineService, _userService, _dataManager, _imageValidator, _clock);
- _userDeleteService = new UserDeleteService(NullLogger<UserDeleteService>.Instance, Database, _timelinePostService);
- }
-
- protected override void BeforeDatabaseDestroy()
- {
- _eTagGenerator.Dispose();
- }
-
- [Theory]
- [InlineData("@user")]
- [InlineData("tl")]
- public async Task GetPosts_ModifiedSince(string timelineName)
- {
- _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" };
-
- DateTime testPoint = new DateTime();
-
- foreach (var (content, index) in postContentList.Select((v, i) => (v, i)))
- {
- var t = _clock.ForwardCurrentTime();
- if (index == 1)
- testPoint = t;
- await _timelinePostService.CreateTextPost(timelineName, userId, content, null);
- }
-
- var posts = await _timelinePostService.GetPosts(timelineName, testPoint);
- posts.Should().HaveCount(3)
- .And.Subject.Select(p => ((TextTimelinePostContent)p.Content!).Text).Should().Equal(postContentList.Skip(1));
- }
-
- [Theory]
- [InlineData("@user")]
- [InlineData("tl")]
- public async Task GetPosts_IncludeDeleted(string timelineName)
- {
- 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 in postContentList)
- {
- await _timelinePostService.CreateTextPost(timelineName, userId, content, null);
- }
-
- var posts = await _timelinePostService.GetPosts(timelineName);
- posts.Should().HaveCount(4);
- posts.Select(p => p.Deleted).Should().Equal(Enumerable.Repeat(false, posts.Count));
- posts.Select(p => ((TextTimelinePostContent)p.Content!).Text).Should().Equal(postContentList);
-
- foreach (var id in new long[] { posts[0].Id, posts[2].Id })
- {
- await _timelinePostService.DeletePost(timelineName, id);
- }
-
- posts = await _timelinePostService.GetPosts(timelineName);
- posts.Should().HaveCount(2);
- posts.Select(p => p.Deleted).Should().Equal(Enumerable.Repeat(false, posts.Count));
- posts.Select(p => ((TextTimelinePostContent)p.Content!).Text).Should().Equal(new string[] { "b", "d" });
-
- posts = await _timelinePostService.GetPosts(timelineName, includeDeleted: true);
- posts.Should().HaveCount(4);
- 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 _timelinePostService.CreateTextPost(timelineName, userId, content, null);
- }
-
- var time2 = _clock.ForwardCurrentTime();
-
- {
- var posts = await _timelinePostService.GetPosts(timelineName, time2);
- posts.Should().HaveCount(0);
- }
-
- {
- await _userService.ModifyUser(userId, new ModifyUserParams { Nickname = "haha" });
- var posts = await _timelinePostService.GetPosts(timelineName, time2);
- posts.Should().HaveCount(0);
- }
-
- {
- await _userService.ModifyUser(userId, new ModifyUserParams { Username = "haha" });
- var posts = await _timelinePostService.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 _timelinePostService.CreateTextPost(timelineName, userId, content, null);
- }
-
- var time2 = _clock.ForwardCurrentTime();
-
- {
- var posts = await _timelinePostService.GetPosts(timelineName, time2);
- posts.Should().HaveCount(0);
- }
-
- await _userDeleteService.DeleteUser("user");
-
- {
- var posts = await _timelinePostService.GetPosts(timelineName, time2);
- posts.Should().HaveCount(0);
- }
-
- {
- var posts = await _timelinePostService.GetPosts(timelineName, time2, true);
- posts.Should().HaveCount(4);
- }
- }
- }
-}
diff --git a/BackEnd/Timeline.Tests/Services/TimelineServiceTest.cs b/BackEnd/Timeline.Tests/Services/TimelineServiceTest.cs
deleted file mode 100644
index 70f54ede..00000000
--- a/BackEnd/Timeline.Tests/Services/TimelineServiceTest.cs
+++ /dev/null
@@ -1,149 +0,0 @@
-using FluentAssertions;
-using Microsoft.Extensions.Logging.Abstractions;
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Timeline.Models;
-using Timeline.Services;
-using Timeline.Services.Exceptions;
-using Timeline.Tests.Helpers;
-using Xunit;
-
-namespace Timeline.Tests.Services
-{
- public class TimelineServiceTest : DatabaseBasedTest
- {
- private readonly PasswordService _passwordService = new PasswordService();
-
- private readonly TestClock _clock = new TestClock();
-
- private UserPermissionService _userPermissionService = default!;
-
- private UserService _userService = default!;
-
- private TimelineService _timelineService = default!;
-
- protected override void OnDatabaseCreated()
- {
- _userPermissionService = new UserPermissionService(Database);
- _userService = new UserService(NullLogger<UserService>.Instance, Database, _passwordService, _userPermissionService, _clock);
- _timelineService = new TimelineService(Database, _userService, _clock);
- }
-
- [Theory]
- [InlineData("@user")]
- [InlineData("tl")]
- public async Task Timeline_GetLastModified(string timelineName)
- {
- var time = _clock.ForwardCurrentTime();
-
- var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal);
- if (!isPersonal)
- await _timelineService.CreateTimeline(timelineName, await _userService.GetUserIdByUsername("user"));
-
- var t = await _timelineService.GetTimelineLastModifiedTime(timelineName);
-
- t.Should().Be(time);
- }
-
- [Theory]
- [InlineData("@user")]
- [InlineData("tl")]
- public async Task Timeline_GetUnqiueId(string timelineName)
- {
- var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal);
- if (!isPersonal)
- await _timelineService.CreateTimeline(timelineName, await _userService.GetUserIdByUsername("user"));
-
- var uniqueId = await _timelineService.GetTimelineUniqueId(timelineName);
-
- uniqueId.Should().NotBeNullOrEmpty();
- }
-
- [Theory]
- [InlineData("@user")]
- [InlineData("tl")]
- public async Task Timeline_LastModified(string timelineName)
- {
- var initTime = _clock.ForwardCurrentTime();
-
- void Check(TimelineInfo timeline)
- {
- timeline.NameLastModified.Should().Be(initTime);
- timeline.LastModified.Should().Be(_clock.GetCurrentTime());
- }
-
- async Task GetAndCheck()
- {
- Check(await _timelineService.GetTimeline(timelineName));
- }
-
- var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal);
- if (!isPersonal)
- Check(await _timelineService.CreateTimeline(timelineName, await _userService.GetUserIdByUsername("user")));
-
- await GetAndCheck();
-
- _clock.ForwardCurrentTime();
- await _timelineService.ChangeProperty(timelineName, new TimelineChangePropertyRequest { Visibility = TimelineVisibility.Public });
- await GetAndCheck();
-
- _clock.ForwardCurrentTime();
- await _timelineService.ChangeMember(timelineName, new List<string> { "admin" }, null);
- await GetAndCheck();
- }
-
- [Theory]
- [InlineData("@admin")]
- [InlineData("tl")]
- public async Task Title(string timelineName)
- {
- var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal);
- if (!isPersonal)
- await _timelineService.CreateTimeline(timelineName, await _userService.GetUserIdByUsername("user"));
-
- {
- var timeline = await _timelineService.GetTimeline(timelineName);
- timeline.Title.Should().Be(timelineName);
- }
-
- {
- await _timelineService.ChangeProperty(timelineName, new TimelineChangePropertyRequest { Title = null });
- var timeline = await _timelineService.GetTimeline(timelineName);
- timeline.Title.Should().Be(timelineName);
- }
-
- {
- await _timelineService.ChangeProperty(timelineName, new TimelineChangePropertyRequest { Title = "atitle" });
- var timeline = await _timelineService.GetTimeline(timelineName);
- timeline.Title.Should().Be("atitle");
- }
- }
-
- [Fact]
- public async Task ChangeName()
- {
- _clock.ForwardCurrentTime();
-
- await _timelineService.Awaiting(s => s.ChangeTimelineName("!!!", "newtl")).Should().ThrowAsync<ArgumentException>();
- await _timelineService.Awaiting(s => s.ChangeTimelineName("tl", "!!!")).Should().ThrowAsync<ArgumentException>();
- await _timelineService.Awaiting(s => s.ChangeTimelineName("tl", "newtl")).Should().ThrowAsync<TimelineNotExistException>();
-
- await _timelineService.CreateTimeline("tl", await _userService.GetUserIdByUsername("user"));
- await _timelineService.CreateTimeline("tl2", await _userService.GetUserIdByUsername("user"));
-
- await _timelineService.Awaiting(s => s.ChangeTimelineName("tl", "tl2")).Should().ThrowAsync<EntityAlreadyExistException>();
-
- var time = _clock.ForwardCurrentTime();
-
- await _timelineService.ChangeTimelineName("tl", "newtl");
-
- {
- var timeline = await _timelineService.GetTimeline("newtl");
- timeline.Name.Should().Be("newtl");
- timeline.LastModified.Should().Be(time);
- timeline.NameLastModified.Should().Be(time);
- }
- }
- }
-}