-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show user not found in PM with deleted user update tests #321
This took me hours because of ADHD and an inability to focus. So on the off chance that you happen to read this, as a consumer of open source software, please thank the contributors who make the stuff that you use the most. It ain't easy, and it's free to you.
- Loading branch information
Showing
7 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/PopForums.Test/Composers/PrivateMessageStateComposerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System.Text.Json; | ||
using PopForums.Composers; | ||
|
||
namespace PopForums.Test.Composers; | ||
|
||
public class PrivateMessageStateComposerTests | ||
{ | ||
protected PrivateMessageStateComposer GetComposer() | ||
{ | ||
_privateMessageService = Substitute.For<IPrivateMessageService>(); | ||
return new PrivateMessageStateComposer(_privateMessageService); | ||
} | ||
|
||
private IPrivateMessageService _privateMessageService; | ||
|
||
public class GetState : PrivateMessageStateComposerTests | ||
{ | ||
[Fact] | ||
public async Task MessagesMappedWithBuffer() | ||
{ | ||
var composer = GetComposer(); | ||
var pm = new PrivateMessage { LastViewDate = DateTime.UtcNow, PMID = 123 }; | ||
var posts = new List<PrivateMessagePost>(); | ||
var post1 = new PrivateMessagePost{ PMID = pm.PMID, UserID = 2, Name = "Jeff", PostTime = new DateTime(2020,1,1), FullText = "post1", PMPostID = 1}; | ||
var post2 = new PrivateMessagePost{ PMID = pm.PMID, UserID = 3, Name = "Diana", PostTime = new DateTime(2021,1,1), FullText = "post2", PMPostID = 2}; | ||
var post3 = new PrivateMessagePost{ PMID = pm.PMID, UserID = 4, Name = "Simon", PostTime = new DateTime(2022,1,1), FullText = "post3", PMPostID = 3}; | ||
posts.Add(post1); | ||
posts.Add(post2); | ||
_privateMessageService.GetMostRecentPosts(pm.PMID, pm.LastViewDate).Returns(posts); | ||
_privateMessageService.GetPosts(pm.PMID, pm.LastViewDate).Returns(new List<PrivateMessagePost> { post3 }); | ||
|
||
var state = await composer.GetState(pm); | ||
|
||
Assert.Equal(post3.UserID, state.Messages[0].UserID); | ||
Assert.Equal(post3.Name, state.Messages[0].Name); | ||
Assert.Equal(post3.PostTime.ToString("o"), state.Messages[0].PostTime); | ||
Assert.Equal(post3.FullText, state.Messages[0].FullText); | ||
Assert.Equal(post3.PMPostID, state.Messages[0].PMPostID); | ||
|
||
Assert.Equal(post1.UserID, state.Messages[1].UserID); | ||
Assert.Equal(post1.Name, state.Messages[1].Name); | ||
Assert.Equal(post1.PostTime.ToString("o"), state.Messages[1].PostTime); | ||
Assert.Equal(post1.FullText, state.Messages[1].FullText); | ||
Assert.Equal(post1.PMPostID, state.Messages[1].PMPostID); | ||
|
||
Assert.Equal(post2.UserID, state.Messages[2].UserID); | ||
Assert.Equal(post2.Name, state.Messages[2].Name); | ||
Assert.Equal(post2.PostTime.ToString("o"), state.Messages[2].PostTime); | ||
Assert.Equal(post2.FullText, state.Messages[2].FullText); | ||
Assert.Equal(post2.PMPostID, state.Messages[2].PMPostID); | ||
} | ||
|
||
[Fact] | ||
public async Task NewestPostIDSet() | ||
{ | ||
var composer = GetComposer(); | ||
var pm = new PrivateMessage { LastViewDate = DateTime.UtcNow, PMID = 123 }; | ||
var posts = new List<PrivateMessagePost>(); | ||
var post1 = new PrivateMessagePost{ PMID = pm.PMID }; | ||
var post2 = new PrivateMessagePost{ PMID = pm.PMID }; | ||
var post3 = new PrivateMessagePost{ PMID = pm.PMID }; | ||
posts.Add(post1); | ||
posts.Add(post2); | ||
_privateMessageService.GetMostRecentPosts(pm.PMID, pm.LastViewDate).Returns(posts); | ||
_privateMessageService.GetPosts(pm.PMID, pm.LastViewDate).Returns(new List<PrivateMessagePost> { post3 }); | ||
|
||
var state = await composer.GetState(pm); | ||
|
||
Assert.Equal(post1.PMPostID, state.NewestPostID); | ||
} | ||
|
||
[Fact] | ||
public async Task PMIDSet() | ||
{ | ||
var composer = GetComposer(); | ||
var pm = new PrivateMessage { LastViewDate = DateTime.UtcNow, PMID = 123 }; | ||
_privateMessageService.GetMostRecentPosts(pm.PMID, pm.LastViewDate).Returns(new List<PrivateMessagePost>()); | ||
_privateMessageService.GetPosts(pm.PMID, pm.LastViewDate).Returns(new List<PrivateMessagePost>()); | ||
|
||
var state = await composer.GetState(pm); | ||
|
||
Assert.Equal(pm.PMID, state.PmID); | ||
} | ||
|
||
[Fact] | ||
public async Task PMUsersJsonSet() | ||
{ | ||
var composer = GetComposer(); | ||
var pm = new PrivateMessage { LastViewDate = DateTime.UtcNow, PMID = 123, Users = new JsonElement()}; | ||
_privateMessageService.GetMostRecentPosts(pm.PMID, pm.LastViewDate).Returns(new List<PrivateMessagePost>()); | ||
_privateMessageService.GetPosts(pm.PMID, pm.LastViewDate).Returns(new List<PrivateMessagePost>()); | ||
|
||
var state = await composer.GetState(pm); | ||
|
||
Assert.Equal(pm.Users, state.Users); | ||
} | ||
|
||
[Fact] | ||
public async Task IsUserNotFoundSet() | ||
{ | ||
var composer = GetComposer(); | ||
var pm = new PrivateMessage { LastViewDate = DateTime.UtcNow, PMID = 123, Users = new JsonElement()}; | ||
_privateMessageService.GetMostRecentPosts(pm.PMID, pm.LastViewDate).Returns(new List<PrivateMessagePost>()); | ||
_privateMessageService.GetPosts(pm.PMID, pm.LastViewDate).Returns(new List<PrivateMessagePost>()); | ||
_privateMessageService.IsUserNotFound(pm.PMID).Returns(true); | ||
|
||
var state = await composer.GetState(pm); | ||
|
||
Assert.True(state.IsUserNotFound); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters