forked from Kentico/KInspector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add PageNotFoundSummaryTests Kentico#225
- Loading branch information
1 parent
e1db82e
commit e7c1aea
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
test/KInspector.Modules.Tests/Reports/PageNotFoundSummaryTests.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,75 @@ | ||
using KInspector.Core.Constants; | ||
using KInspector.Reports.PageNotFoundSummary; | ||
using KInspector.Reports.PageNotFoundSummary.Models; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace KInspector.Tests.Common.Reports | ||
{ | ||
[TestFixture(10)] | ||
[TestFixture(11)] | ||
[TestFixture(12)] | ||
[TestFixture(13)] | ||
public class PageNotFoundSummaryTests : AbstractModuleTest<Report, Terms> | ||
{ | ||
private readonly Report _mockReport; | ||
|
||
private IEnumerable<CmsNotFoundEvent> CleanResults => Enumerable.Empty<CmsNotFoundEvent>(); | ||
|
||
private IEnumerable<CmsNotFoundEvent> BadResults => new List<CmsNotFoundEvent>() | ||
{ | ||
new() | ||
{ | ||
Count = 2, | ||
EventUrl = "https://test.com/a", | ||
Referrer = "https://test.com/b", | ||
FirstOccurrence = DateTime.Now | ||
}, | ||
new() | ||
{ | ||
Count = 3, | ||
EventUrl = "https://test.com/c", | ||
Referrer = "https://test.com/d", | ||
FirstOccurrence = DateTime.Now | ||
} | ||
}; | ||
|
||
public PageNotFoundSummaryTests(int majorVersion) : base(majorVersion) | ||
{ | ||
_mockReport = new Report(_mockDatabaseService.Object, _mockModuleMetadataService.Object); | ||
} | ||
|
||
[Test] | ||
public async Task Should_ReturnGoodResult_When_NoEvents() | ||
{ | ||
// Arrange | ||
_mockDatabaseService | ||
.Setup(p => p.ExecuteSqlFromFile<CmsNotFoundEvent>(Scripts.GetPageNotFoundEventLogEntries)) | ||
.Returns(Task.FromResult(CleanResults)); | ||
|
||
// Act | ||
var results = await _mockReport.GetResults(); | ||
|
||
// Assert | ||
Assert.That(results.Status == ResultsStatus.Good); | ||
Assert.That(results.Type == ResultsType.NoResults); | ||
Assert.That(results.TableResults.Count == 0); | ||
} | ||
|
||
public async Task Should_ReturnWarningResult_When_EventsExist() | ||
{ | ||
// Arrange | ||
_mockDatabaseService | ||
.Setup(p => p.ExecuteSqlFromFile<CmsNotFoundEvent>(Scripts.GetPageNotFoundEventLogEntries)) | ||
.Returns(Task.FromResult(BadResults)); | ||
|
||
// Act | ||
var results = await _mockReport.GetResults(); | ||
|
||
// Assert | ||
Assert.That(results.Status == ResultsStatus.Warning); | ||
Assert.That(results.Type == ResultsType.TableList); | ||
Assert.That(results.TableResults.Count == 1); | ||
} | ||
} | ||
} |