-
Notifications
You must be signed in to change notification settings - Fork 543
/
EditTests.cs
53 lines (46 loc) · 1.81 KB
/
EditTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Linq;
using System.Threading.Tasks;
using Conduit.Features.Articles;
using Xunit;
namespace Conduit.IntegrationTests.Features.Articles;
public class EditTests : SliceFixture
{
[Fact]
public async Task Expect_Edit_Article()
{
var createCommand = new Create.Command(
new Create.ArticleData
{
Title = "Test article dsergiu77",
Description = "Description of the test article",
Body = "Body of the test article",
TagList = ["tag1", "tag2"]
}
);
var createdArticle = await ArticleHelpers.CreateArticle(this, createCommand);
var command = new Edit.Command(
new(
new Edit.ArticleData(
"Updated " + createdArticle.Title,
"Updated " + createdArticle.Description,
"Updated " + createdArticle.Body,
[createdArticle.TagList[1], "tag3"]
)
),
createdArticle.Slug ?? throw new InvalidOperationException()
);
var dbContext = GetDbContext();
var articleEditHandler = new Edit.Handler(dbContext);
var edited = await articleEditHandler.Handle(
command,
new System.Threading.CancellationToken()
);
Assert.NotNull(edited);
Assert.Equal(edited.Article.Title, command.Model.Article.Title);
Assert.Equal(edited.Article.TagList.Count, command.Model.Article.TagList?.Count() ?? 0);
// use assert Contains because we do not know the order in which the tags are saved/retrieved
Assert.Contains(edited.Article.TagList[0], command.Model.Article.TagList ?? []);
Assert.Contains(edited.Article.TagList[1], command.Model.Article.TagList ?? []);
}
}