Skip to content

Commit

Permalink
Merge pull request #305 from kentico-timothyf/PageTypeAssignedToSite
Browse files Browse the repository at this point in the history
Added new Page Type Not Assigned to site report
  • Loading branch information
ChristopherJennings authored Aug 6, 2019
2 parents 40d331e + d0d4b11 commit 6f3eea9
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 22 deletions.
11 changes: 6 additions & 5 deletions KenticoInspector.Core/KenticoInspector.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.1</LangVersion>
<Version/>
<PackageVersion/>
<AssemblyVersion/>
<FileVersion/>
<InformationalVersion/>
<Version />
<PackageVersion />
<AssemblyVersion />
<FileVersion />
<InformationalVersion />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.1</LangVersion>
<Version/>
<PackageVersion/>
<AssemblyVersion/>
<FileVersion/>
<InformationalVersion/>
<Version />
<PackageVersion />
<AssemblyVersion />
<FileVersion />
<InformationalVersion />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.2" />
<PackageReference Include="Dapper" Version="1.60.1" />
<PackageReference Include="Dapper.FluentMap" Version="1.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="YamlDotNet" Version="6.1.1" />
</ItemGroup>

Expand Down
98 changes: 98 additions & 0 deletions KenticoInspector.Reports.Tests/PageTypeAssignmentAnalysisTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using KenticoInspector.Core.Constants;
using KenticoInspector.Reports.PageTypeAssignmentAnalysis;
using KenticoInspector.Reports.PageTypeAssignmentAnalysis.Models;
using NUnit.Framework;
using System.Collections.Generic;

namespace KenticoInspector.Reports.Tests
{
[TestFixture(10)]
[TestFixture(11)]
[TestFixture(12)]
public class PageTypeAssignmentAnalysisTests : AbstractReportTest<Report, Terms>
{
private Report _mockReport;

public PageTypeAssignmentAnalysisTests(int majorVersion) : base(majorVersion)
{
_mockReport = new Report(_mockDatabaseService.Object, _mockReportMetadataService.Object);
}

[Test]
public void Should_ReturnListOfUnassignedPageTypes_When_SomeAreFound()
{
// Arrange
var unassignedPageTypes = GetListOfUnassignedPageTypes();
ArrangeDatabaseCalls(unassignedPageTypes);

// Act
var results = _mockReport.GetResults();

// Assert
Assert.That(results.Data.Rows.Count > 0, "Expected more than 0 page types to be returned");
Assert.That(results.Status == ReportResultsStatus.Warning,$"Expected Warning status, got {results.Status} status");
}

[Test]
public void Should_ReturnEmptyListOfIdenticalLayouts_When_NoneFound()
{
// Arrange
ArrangeDatabaseCalls();

// Act
var results = _mockReport.GetResults();
// Assert
Assert.That(results.Data.Rows.Count == 0, $"Expected 0 page types to be returned, got {results.Data.Rows.Count}");
Assert.That(results.Status == ReportResultsStatus.Good, $"Expected Good status, got {results.Status} status");
}

private void ArrangeDatabaseCalls(IEnumerable<PageType> unassignedPageTypes = null) {
unassignedPageTypes = unassignedPageTypes ?? new List<PageType>();
_mockDatabaseService
.Setup(p => p.ExecuteSqlFromFile<PageType>(Scripts.GetPageTypesNotAssignedToSite))
.Returns(unassignedPageTypes);
}

private IEnumerable<PageType> GetListOfUnassignedPageTypes()
{
return new List<PageType>
{
new PageType
{
ClassName = "DancingGoatMvc.Article",
ClassDisplayName = "Article (MVC)",
NodeSiteID = 1,
NodeClassID = 5494
},
new PageType
{
ClassName = "DancingGoatMvc.Brewer",
ClassDisplayName = "Brewer (MVC)",
NodeSiteID = 1,
NodeClassID = 5477
},
new PageType
{
ClassName = "CMS.News",
ClassDisplayName = "News",
NodeSiteID = 2,
NodeClassID = 5502
},
new PageType
{
ClassName = "CMS.Office",
ClassDisplayName = "Office",
NodeSiteID = 2,
NodeClassID = 5514
},
new PageType
{
ClassName = "globaltypes.customtype",
ClassDisplayName = "Custom Type",
NodeSiteID = 2,
NodeClassID = 5497
},
};
}
}
}
16 changes: 11 additions & 5 deletions KenticoInspector.Reports/KenticoInspector.Reports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.1</LangVersion>
<Version/>
<PackageVersion/>
<AssemblyVersion/>
<FileVersion/>
<InformationalVersion/>
<Version />
<PackageVersion />
<AssemblyVersion />
<FileVersion />
<InformationalVersion />
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -121,6 +121,12 @@
<None Update="TaskProcessingAnalysis\Scripts\GetCountOfUnprocessedWebFarmTasks.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="PageTypeAssignmentAnalysis\Metadata\en-US.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="PageTypeAssignmentAnalysis\Scripts\GetPageTypesNotAssignedToSite.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TemplateLayoutAnalysis\Scripts\GetIdenticalLayouts.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
details:
name: Page Type Assignment Analysis
shortDescription: Displays page types used by a certain site without being assigned to this site.
longDescription: |
If the page type is not assigned to the site and is used by this site, you will encounter problems while using import/export feature.
terms:
warningSummary: <unassignedPageTypeCount> page <unassignedPageTypeCount:type|types> found that <unassignedPageTypeCount:is|are> not assigned to the site <unassignedPageTypeCount:it|they> <unassignedPageTypeCount:is|are> used on.
unassignedPageTypesTableHeader: Page types not assigned to site
noIssuesFound: All page types are assigned to sites.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace KenticoInspector.Reports.PageTypeAssignmentAnalysis.Models
{
public class PageType
{
public string ClassDisplayName { get; set; }
public string ClassName { get; set; }
public int NodeClassID { get; set; }
public int NodeSiteID { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using KenticoInspector.Core.Models;

namespace KenticoInspector.Reports.PageTypeAssignmentAnalysis.Models
{
public class Terms
{
public Term WarningSummary { get; set; }
public Term UnassignedPageTypesTableHeader { get; set; }
public Term NoIssuesFound { get; set; }
}
}
61 changes: 61 additions & 0 deletions KenticoInspector.Reports/PageTypeAssignmentAnalysis/Report.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using KenticoInspector.Core;
using KenticoInspector.Core.Constants;
using KenticoInspector.Core.Helpers;
using KenticoInspector.Core.Models;
using KenticoInspector.Core.Services.Interfaces;
using KenticoInspector.Reports.PageTypeAssignmentAnalysis.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace KenticoInspector.Reports.PageTypeAssignmentAnalysis
{
public class Report : AbstractReport<Terms>
{
private readonly IDatabaseService databaseService;

public Report(IDatabaseService databaseService, IReportMetadataService reportMetadataService) : base(reportMetadataService)
{
this.databaseService = databaseService;
}

public override IList<Version> CompatibleVersions => VersionHelper.GetVersionList("10", "11", "12");

public override IList<string> Tags => new List<string>
{
ReportTags.Health,
ReportTags.Consistency
};

public override ReportResults GetResults()
{
var unassignedPageTypes = databaseService.ExecuteSqlFromFile<PageType>(Scripts.GetPageTypesNotAssignedToSite);

return CompileResults(unassignedPageTypes);
}

private ReportResults CompileResults(IEnumerable<PageType> unassignedPageTypes)
{
var results = new ReportResults
{
Status = ReportResultsStatus.Good,
Summary = Metadata.Terms.NoIssuesFound,
Type = ReportResultsType.Table,
Data = new TableResult<PageType>()
{
Name = Metadata.Terms.UnassignedPageTypesTableHeader,
Rows = unassignedPageTypes
}
};

var unassignedPageTypeCount = unassignedPageTypes.Count();
if (unassignedPageTypeCount > 0)
{
results.Status = ReportResultsStatus.Warning;
results.Summary = Metadata.Terms.WarningSummary.With(new { unassignedPageTypeCount });
}

return results;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace KenticoInspector.Reports.PageTypeAssignmentAnalysis
{
public class Scripts
{
public static string BaseDirectory = $"{nameof(PageTypeAssignmentAnalysis)}/Scripts";

public static string GetPageTypesNotAssignedToSite = $"{BaseDirectory}/{nameof(GetPageTypesNotAssignedToSite)}.sql";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT DISTINCT NodeSiteID, NodeClassID, ClassName, ClassDisplayName
FROM View_CMS_Tree_Joined
LEFT JOIN CMS_ClassSite on
ClassID = NodeClassID AND
SiteID = NodeSiteID
WHERE SiteID is null
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<StartupObject></StartupObject>
<LangVersion>7.1</LangVersion>
<Version/>
<PackageVersion/>
<AssemblyVersion/>
<FileVersion/>
<InformationalVersion/>
<Version />
<PackageVersion />
<AssemblyVersion />
<FileVersion />
<InformationalVersion />
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,6 +18,7 @@
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="VueCliMiddleware" Version="2.2.0" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions appveyor-before_package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ dotnet publish KenticoInspector.WebApplication.csproj /p:PublishDir=..\publish -

# Copy compiled front-end to publish folder
Set-Location .\ClientApp
mkdir "..\..\publish\dist"
Copy-Item ".\dist\*" -Recurse -Destination "..\..\publish\dist\"
mkdir "..\..\publish\ClientApp\dist"
Copy-Item ".\dist\*" -Recurse -Destination "..\..\publish\ClientApp\dist\"

# Go back to root
Set-Location ..\..\
Expand Down

0 comments on commit 6f3eea9

Please sign in to comment.