Skip to content

Commit

Permalink
Articles (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
umerfaruk authored Jan 18, 2024
1 parent 85b30ff commit d026396
Show file tree
Hide file tree
Showing 358 changed files with 11,761 additions and 1,312 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Inshapardaz.Api.Entities;
using Inshapardaz.Api.Models.Accounts;
using Inshapardaz.Api.Models.Accounts;
using Inshapardaz.Api.Tests.Asserts;
using Inshapardaz.Api.Tests.Helpers;
using Inshapardaz.Domain.Models;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Inshapardaz.Api.Entities;
using Inshapardaz.Api.Models.Accounts;
using Inshapardaz.Api.Models.Accounts;
using Inshapardaz.Api.Tests.Asserts;
using Inshapardaz.Api.Tests.Helpers;
using Inshapardaz.Domain.Models;
Expand Down
468 changes: 337 additions & 131 deletions src/Inshapardaz.Api.Tests/Asserts/ArticleAssert.cs

Large diffs are not rendered by default.

84 changes: 29 additions & 55 deletions src/Inshapardaz.Api.Tests/Asserts/ArticleContentAssert.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentAssertions;
using FluentAssertions.Common;
using Inshapardaz.Api.Tests.DataHelpers;
using Inshapardaz.Api.Tests.Dto;
using Inshapardaz.Api.Tests.Helpers;
Expand All @@ -15,31 +14,28 @@ internal class ArticleContentAssert
private HttpResponseMessage _response;
private readonly int _libraryId;
private ArticleContentView _articleContent;
private IssueDto _issue;
private LibraryDto _library;

public ArticleContentAssert(HttpResponseMessage response, int libraryId, IssueDto issue)
public ArticleContentAssert(HttpResponseMessage response, int libraryId)
{
_response = response;
_libraryId = libraryId;
_issue = issue;
_articleContent = response.GetContent<ArticleContentView>().Result;
}

public ArticleContentAssert(HttpResponseMessage response, LibraryDto library, IssueDto issue)
public ArticleContentAssert(HttpResponseMessage response, LibraryDto library)
{
_response = response;
_libraryId = library.Id;
_library = library;
_issue = issue;
_articleContent = response.GetContent<ArticleContentView>().Result;
}

internal ArticleContentAssert ShouldHaveSelfLink()
{
_articleContent.SelfLink()
.ShouldBeGet()
.EndingWith($"/libraries/{_libraryId}/periodicals/{_articleContent.PeriodicalId}/volumes/{_articleContent.VolumeNumber}/issues/{_articleContent.IssueNumber}/articles/{_articleContent.SequenceNumber}/contents")
.EndingWith($"/libraries/{_libraryId}/articles/{_articleContent.ArticleId}/contents")
.ShouldHaveAcceptLanguage(_articleContent.Language);

return this;
Expand All @@ -63,7 +59,7 @@ internal ArticleContentAssert ShouldHaveUpdateLink()
{
_articleContent.UpdateLink()
.ShouldBePut()
.EndingWith($"/libraries/{_libraryId}/periodicals/{_articleContent.PeriodicalId}/volumes/{_articleContent.VolumeNumber}/issues/{_articleContent.IssueNumber}/articles/{_articleContent.SequenceNumber}/contents")
.EndingWith($"/libraries/{_libraryId}/articles/{_articleContent.ArticleId}/contents")
.ShouldHaveAcceptLanguage(_articleContent.Language);

return this;
Expand All @@ -87,49 +83,40 @@ internal ArticleContentAssert ShouldHaveDefaultLibraryLanguage()
return this;
}

internal ArticleContentAssert ShouldHaveCorrectLocationHeader()
internal ArticleContentAssert ShouldHaveCorrectLocationHeader(string language)
{
var location = _response.Headers.Location.AbsoluteUri;
location.Should().NotBeNull();
location.Should().EndWith($"/libraries/{_libraryId}/periodicals/{_articleContent.PeriodicalId}/volumes/{_articleContent.VolumeNumber}/issues/{_articleContent.IssueNumber}/articles/{_articleContent.SequenceNumber}/contents");
location.Should().EndWith($"/libraries/{_libraryId}/articles/{_articleContent.ArticleId}/contents?language={language}");
return this;
}

internal ArticleContentAssert ShouldHaveSavedCorrectText(string expected, IDbConnection dbConnection)
{
var content = dbConnection.GetArticleContentById(_issue.PeriodicalId, _issue.VolumeNumber, _issue.IssueNumber, _articleContent.SequenceNumber, _articleContent.Language);
var content = dbConnection.GetArticleContent(_articleContent.ArticleId, _articleContent.Language);
content.Text.Should().NotBeNull().And.Be(expected);
return this;
}

internal ArticleContentAssert ShouldHaveMatechingTextForLanguage(string expected, string language, IDbConnection dbConnection)
internal ArticleContentAssert ShouldHaveMatechingTextForLanguage(string expected, string language, string newLayout, IDbConnection dbConnection)
{
var content = dbConnection.GetArticleContentById(_issue.PeriodicalId, _issue.VolumeNumber, _issue.IssueNumber, _articleContent.SequenceNumber, _articleContent.Language);
var content = dbConnection.GetArticleContent(_articleContent.ArticleId, _articleContent.Language);
content.Text.Should().NotBeNull().Should().NotBe(expected);
content.Language.Should().Be(language);
return this;
}

internal ArticleContentAssert ShouldHaveContentLink()
{
_articleContent.Link("contents")
.ShouldBeGet();

content.Layout.Should().Be(newLayout);
return this;
}

internal ArticleContentAssert ShouldHaveSavedArticleContent(IDbConnection dbConnection)
{
var dbContent = dbConnection.GetArticleContentById(_issue.PeriodicalId, _issue.VolumeNumber, _issue.IssueNumber, _articleContent.SequenceNumber, _articleContent.Language);
var dbContent = dbConnection.GetArticleContent(_articleContent.ArticleId, _articleContent.Language);
dbContent.Should().NotBeNull();
var dbArticle = dbConnection.GetArticleById(dbContent.ArticleId);
dbArticle.Should().NotBeNull();
var dbIssue = dbConnection.GetIssueById(dbArticle.IssueId);
_articleContent.PeriodicalId.Should().Be(dbIssue.PeriodicalId);
_articleContent.VolumeNumber.Should().Be(dbIssue.VolumeNumber);
_articleContent.IssueNumber.Should().Be(dbIssue.IssueNumber);
_articleContent.SequenceNumber.Should().Be(dbArticle.SequenceNumber);
_articleContent.ArticleId.Should().Be(dbContent.ArticleId);
_articleContent.Language.Should().Be(dbContent.Language);
_articleContent.Layout.Should().Be(dbContent.Layout);
_articleContent.Text.Should().Be(dbContent.Text);

return this;
}
Expand All @@ -138,7 +125,7 @@ internal ArticleContentAssert ShouldHaveDeleteLink()
{
_articleContent.DeleteLink()
.ShouldBeDelete()
.EndingWith($"/libraries/{_libraryId}/periodicals/{_articleContent.PeriodicalId}/volumes/{_articleContent.VolumeNumber}/issues/{_articleContent.IssueNumber}/articles/{_articleContent.SequenceNumber}/contents");
.EndingWith($"/libraries/{_libraryId}/articles/{_articleContent.ArticleId}/contents");

return this;
}
Expand All @@ -153,51 +140,38 @@ internal ArticleContentAssert ShouldHaveArticleLink()
{
_articleContent.Link("article")
.ShouldBeGet()
.EndingWith($"/libraries/{_libraryId}/periodicals/{_articleContent.PeriodicalId}/volumes/{_articleContent.VolumeNumber}/issues/{_articleContent.IssueNumber}/articles/{_articleContent.SequenceNumber}");

return this;
}

internal ArticleContentAssert ShouldHaveIssueLink()
{
_articleContent.Link("issue")
.ShouldBeGet()
.EndingWith($"/libraries/{_libraryId}/periodicals/{_articleContent.PeriodicalId}/volumes/{_articleContent.VolumeNumber}/issues/{_articleContent.IssueNumber}");
.EndingWith($"/libraries/{_libraryId}/articles/{_articleContent.ArticleId}");

return this;
}

internal ArticleContentAssert ShouldHavePeriodicalLink()
internal ArticleContentAssert ShouldMatch(ArticleContentDto content, ArticleDto article)
{
_articleContent.Link("periodical")
.ShouldBeGet()
.EndingWith($"/libraries/{_libraryId}/periodicals/{_articleContent.PeriodicalId}");
_articleContent.ArticleId.Should().Be(article.Id);
_articleContent.Language.Should().Be(content.Language);
_articleContent.Layout.Should().Be(content.Layout);
_articleContent.Text.Should().Be(content.Text);

return this;
}

internal ArticleContentAssert ShouldMatch(ArticleContentDto content, IssueDto issue, ArticleDto article)
internal static void ShouldHaveDeletedContent(IDbConnection dbConnection, ArticleContentDto content)
{
_articleContent.PeriodicalId.Should().Be(issue.PeriodicalId);
_articleContent.VolumeNumber.Should().Be(issue.VolumeNumber);
_articleContent.IssueNumber.Should().Be(issue.IssueNumber);
_articleContent.SequenceNumber.Should().Be(article.SequenceNumber);
_articleContent.Language.Should().Be(content.Language);

return this;
var dbContent = dbConnection.GetArticleContent(content.ArticleId, content.Language);
dbContent.Should().BeNull("Article content should be deleted");
}

internal static void ShouldHaveDeletedContent(IDbConnection dbConnection, IssueDto issue, ArticleDto article, ArticleContentDto content)
internal static void ShouldHaveContent(IDbConnection dbConnection, long articleId, string language)
{
var dbContent = dbConnection.GetArticleContentById(issue.PeriodicalId, issue.VolumeNumber, issue.IssueNumber, article.SequenceNumber, content.Language);
dbContent.Should().BeNull("Article content should be deleted");
var dbContent = dbConnection.GetArticleContent(articleId, language);
dbContent.Should().NotBeNull("Article content should exist.");
}

internal static void ShouldHaveLocationHeader(RedirectResult result, int libraryId, int periodicalId, int volumeNumber, int issueNumber, ChapterContentDto content)
internal static void ShouldHaveLocationHeader(RedirectResult result, int libraryId, ArticleContentDto content)
{
var response = result as RedirectResult;
response.Url.Should().NotBeNull();
response.Url.Should().EndWith($"/libraries/{libraryId}/periodicals/{periodicalId}/volumes/{volumeNumber}/issues/{issueNumber}/contents");
response.Url.Should().EndWith($"/libraries/{libraryId}/articles/{content.ArticleId}/contents");
}
}
}
3 changes: 2 additions & 1 deletion src/Inshapardaz.Api.Tests/Asserts/AuthorAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public AuthorAssert ShouldHaveCorrectAuthorRetunred(AuthorDto author, IDbConnect
_author.Id.Should().Be(author.Id);
_author.Name.Should().Be(author.Name);
_author.BookCount.Should().Be(dbConnection.GetBookCountByAuthor(_author.Id));
_author.ArticleCount.Should().Be(dbConnection.GetArticleCountByAuthor(_author.Id));
return this;
}
}
Expand All @@ -269,4 +270,4 @@ public static AuthorAssert ShouldMatch(this AuthorView view, AuthorDto dto)
.ShouldBeSameAs(dto);
}
}
}
}
4 changes: 4 additions & 0 deletions src/Inshapardaz.Api.Tests/Asserts/BookAsserts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ internal BookAssert ShouldBeSameAs(BookDto expected, IDbConnection db)
_book.Status.Should().Be(expected.Status.ToDescription());
_book.YearPublished.Should().Be(expected.YearPublished);
_book.SeriesId.Should().Be(expected.SeriesId);
_book.Source.Should().Be(expected.Source);
_book.Publisher.Should().Be(expected.Publisher);
if (_book.SeriesId.HasValue)
{
_book.SeriesName.Should().Be(db.GetSeriesById(expected.SeriesId.Value).Name);
Expand Down Expand Up @@ -376,6 +378,8 @@ internal BookAssert ShouldBeSameAs(BookView expected, IDbConnection db)
_book.SeriesId.Should().Be(expected.SeriesId);
_book.SeriesName.Should().Be(db.GetSeriesById(expected.SeriesId.Value).Name);
_book.SeriesIndex.Should().Be(expected.SeriesIndex);
_book.Source.Should().Be(expected.Source);
_book.Publisher.Should().Be(expected.Publisher);

var authors = db.GetAuthorsByBook(expected.Id);
_book.Authors.Should().HaveSameCount(authors);
Expand Down
4 changes: 2 additions & 2 deletions src/Inshapardaz.Api.Tests/Asserts/BookPageAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ public BookPageAssert ShouldNotHaveImageDeleteLink()
return this;
}

public void ShouldMatch(BookPageView view)
public void ShouldMatch(BookPageView view, int pageNumber = -1)
{
_bookPage.Text.Should().Be(view.Text);
_bookPage.BookId.Should().Be(view.BookId);
_bookPage.SequenceNumber.Should().Be(view.SequenceNumber);
_bookPage.SequenceNumber.Should().Be(pageNumber >= 0 ? pageNumber : view.SequenceNumber);
}

public BookPageAssert ShouldMatch(BookPageDto dto)
Expand Down
Loading

0 comments on commit d026396

Please sign in to comment.