Skip to content

Commit

Permalink
Merge pull request #57 from Kentico/feat/after-upgrade-automatic-tests
Browse files Browse the repository at this point in the history
Add automatic tests of results of Kentico.Xperience.UMT.Example.Console
  • Loading branch information
akfakmot authored Oct 3, 2024
2 parents 1d0cf6a + c99f398 commit 44a036c
Show file tree
Hide file tree
Showing 32 changed files with 1,048 additions and 41 deletions.
8 changes: 7 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Kentico.Xperience.Core" Version="29.5.0" />
<PackageVersion Include="Kentico.Xperience.Admin" Version="29.5.0" />
<PackageVersion Include="Kentico.Xperience.ImageProcessing" Version="29.5.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0-rc.1.24431.7" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.0-rc.1.24431.7" />
<PackageVersion Include="Microsoft.Playwright" Version="1.47.0" />
<PackageVersion Include="Microsoft.Playwright.NUnit" Version="1.47.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit.Analyzers" Version="4.3.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.32.0.97167">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -25,7 +31,7 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0-rc.1.24431.7" />
<PackageVersion Include="NJsonSchema" Version="11.0.2" />
<PackageVersion Include="RazorLight" Version="2.3.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0-rc.1.24431.7" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
Expand Down
28 changes: 23 additions & 5 deletions Kentico.Xperience.UMT.sln
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kentico.Xperience.UMT", "src\Kentico.Xperience.UMT\Kentico.Xperience.UMT.csproj", "{F499DE79-C15E-4ABA-9E42-E0A243E0F598}"
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kentico.Xperience.UMT", "src\Kentico.Xperience.UMT\Kentico.Xperience.UMT.csproj", "{F499DE79-C15E-4ABA-9E42-E0A243E0F598}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kentico.Xperience.UMT.Example.Console", "examples\Kentico.Xperience.UMT.Example.Console\Kentico.Xperience.UMT.Example.Console.csproj", "{B34D5B62-F958-48E4-84A3-35343529FCF7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kentico.Xperience.UMT.Example.Console", "examples\Kentico.Xperience.UMT.Example.Console\Kentico.Xperience.UMT.Example.Console.csproj", "{B34D5B62-F958-48E4-84A3-35343529FCF7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{A22B7345-BFCB-4BB2-85DA-A32BE7024061}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kentico.Xperience.UMT.Example.AdminApp", "examples\Kentico.Xperience.UMT.Example.AdminApp\Kentico.Xperience.UMT.Example.AdminApp.csproj", "{4ABF76B5-3ED7-44CF-9FFA-39F299BD947C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kentico.Xperience.UMT.Example.AdminApp", "examples\Kentico.Xperience.UMT.Example.AdminApp\Kentico.Xperience.UMT.Example.AdminApp.csproj", "{4ABF76B5-3ED7-44CF-9FFA-39F299BD947C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kentico.Xperience.UMT.Examples", "examples\Kentico.Xperience.UMT.Examples\Kentico.Xperience.UMT.Examples.csproj", "{85138B06-9F3F-40A6-8465-479F591D2845}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kentico.Xperience.UMT.Examples", "examples\Kentico.Xperience.UMT.Examples\Kentico.Xperience.UMT.Examples.csproj", "{85138B06-9F3F-40A6-8465-479F591D2845}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utils", "Utils", "{66C1E923-BA9C-4674-8534-F456FE27592A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kentico.Xperience.UMT.DocUtils", "utils\Kentico.Xperience.UMT.DocUtils\Kentico.Xperience.UMT.DocUtils.csproj", "{71299533-CB05-4068-B5C3-9BCE76413E26}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kentico.Xperience.UMT.DocUtils", "utils\Kentico.Xperience.UMT.DocUtils\Kentico.Xperience.UMT.DocUtils.csproj", "{71299533-CB05-4068-B5C3-9BCE76413E26}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{41F4E25E-E6DF-4D03-85C9-7428A317F207}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kentico.Xperience.UMT.Tests", "tests\Kentico.Xperience.UMT.Tests\Kentico.Xperience.UMT.Tests.csproj", "{2601A1AE-938B-4C67-A859-655B14DAE69A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -40,11 +47,22 @@ Global
{71299533-CB05-4068-B5C3-9BCE76413E26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71299533-CB05-4068-B5C3-9BCE76413E26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71299533-CB05-4068-B5C3-9BCE76413E26}.Release|Any CPU.Build.0 = Release|Any CPU
{2601A1AE-938B-4C67-A859-655B14DAE69A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2601A1AE-938B-4C67-A859-655B14DAE69A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2601A1AE-938B-4C67-A859-655B14DAE69A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2601A1AE-938B-4C67-A859-655B14DAE69A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B34D5B62-F958-48E4-84A3-35343529FCF7} = {A22B7345-BFCB-4BB2-85DA-A32BE7024061}
{4ABF76B5-3ED7-44CF-9FFA-39F299BD947C} = {A22B7345-BFCB-4BB2-85DA-A32BE7024061}
{85138B06-9F3F-40A6-8465-479F591D2845} = {A22B7345-BFCB-4BB2-85DA-A32BE7024061}
{71299533-CB05-4068-B5C3-9BCE76413E26} = {66C1E923-BA9C-4674-8534-F456FE27592A}
{2601A1AE-938B-4C67-A859-655B14DAE69A} = {41F4E25E-E6DF-4D03-85C9-7428A317F207}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C0A71F59-A92C-4A54-A8AF-735C1DB21149}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ See [`SUPPORT.md`](https://github.com/Kentico/.github/blob/main/SUPPORT.md#full-
## Security

For any security issues see [Kentico's `SECURITY.md`](https://github.com/Kentico/.github/blob/main/SECURITY.md).

## Testing

1. Migrate to blank template Kentico XbK project by Kentico.Xperience.UMT.Example.Console
2. Configure $SolutionDir\test.runsettings per the project's settings
3. Ensure test.runsettings file is used in Visual Studio: Top menu -> Test -> Configure Run Settings -> Select Solution Wide runsettings File
4. Run tests from Test explorer
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ async Task SendConfirmHeader()
if (buffer[0] == 0x2D && buffer.Take(5).All(x => x.Equals(0X2D)))
{
ms.Flush();
await ms.FlushAsync();
break;
}
ms.Write(data.Array!, data.Offset, receiveResult.Count);
ms.Flush();
await ms.WriteAsync(data.Array!, data.Offset, receiveResult.Count);
await ms.FlushAsync();
int count = receiveResult.Count;
totalReceived += count;
Expand Down Expand Up @@ -236,6 +236,7 @@ async Task SendConfirmHeader()
logService.LogException(SOURCE, "CONSUMER", e);
}

#pragma warning disable S2589
if (socketAvailable)
{
await SendStats(stats);
Expand All @@ -259,8 +260,8 @@ private static async Task<JObject> ReceiveHeader(WebSocket webSocket)
{
var data = new ArraySegment<byte>(buffer);

ms.Write(data.Array!, data.Offset, receiveResult.Count);
ms.Flush();
await ms.WriteAsync(data.Array!, data.Offset, receiveResult.Count);
await ms.FlushAsync();
}
else
{
Expand Down
11 changes: 11 additions & 0 deletions test.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<BASE_URL>http://localhost:53798</BASE_URL>
<ADMINISTRATION_USER>administrator</ADMINISTRATION_USER>
<ADMINISTRATION_PASSWORD>administrator</ADMINISTRATION_PASSWORD>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
15 changes: 15 additions & 0 deletions tests/Kentico.Xperience.UMT.Tests/Enums/EventLogSeverity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestAfterMigration.Enums
{
public enum EventLogSeverity
{
Info,
Warning,
Error
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestAfterMigration.Extensions
{
public static class IEnumerableExtensions
{
public static IEnumerable<T> SelectManyRecursive<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> selector)
{
if (source == null) throw new ArgumentNullException("source");
if (selector == null) throw new ArgumentNullException("selector");

return !source.Any() ? source :
source.Concat(
source
.SelectMany(i => selector(i))
.SelectManyRecursive(selector)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestAfterMigration.Helpers;

namespace TestAfterMigration.Extensions
{
public static class PageTreeItemExtensions
{
public static IEnumerable<PageTreeItem> Family(this PageTreeItem item) => [item, ..item.Children.SelectManyRecursive(x => x.Children)];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Playwright;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestAfterMigration.Extensions
{
public static class PlaywrightExtensions
{
public static Task WaitForVisible(this ILocator locator) => locator.Nth(0).WaitForAsync(new LocatorWaitForOptions { State = WaitForSelectorState.Visible });
}
}
21 changes: 21 additions & 0 deletions tests/Kentico.Xperience.UMT.Tests/Helpers/PageTreeItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Playwright;
using TestAfterMigration.Extensions;

namespace TestAfterMigration.Helpers
{
public class PageTreeItem(IPage page, string nodeID)
{
public async Task LoadInfo() => Title = (await TitleElement.TextContentAsync())!;

public string? Title { get; private set; } = null;
public ILocator Locator => page.Locator($"[data-testid-nodeid=\"{nodeID}\"]");
public IEnumerable<PageTreeItem> Children { get; set; } = [];
public ILocator TitleElement => Locator.GetByTestId("tree-item-title").Nth(0);
public Task ClickAsync() => TitleElement.ClickAsync();
public async Task WaitBreadcrumbsLoaded()
{
string pageTitle = (await Locator.GetByTestId("tree-item-title").Nth(0).TextContentAsync())!;
await Locator.Page.GetByTestId("breadcrumbs").GetByText(pageTitle).WaitForVisible();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<None Remove="Resources\kentico_brand.png" />
</ItemGroup>

<ItemGroup>
<Content Include="Resources\kentico_brand.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Playwright.NUnit" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" />
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

</Project>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 44a036c

Please sign in to comment.