Skip to content

Commit

Permalink
add PageNotFoundSummaryTests Kentico#225
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-ericd committed Jun 4, 2024
1 parent e1db82e commit e7c1aea
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/KInspector.Modules.Tests/Reports/PageNotFoundSummaryTests.cs
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);
}
}
}

0 comments on commit e7c1aea

Please sign in to comment.