mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
chore: The very first Blazor test
This commit is contained in:
1 parent
46c4529c79
commit
b4378b643b
4 files changed
+100
No files matched your search
@@ -8,6 +8,7 @@ EXPOSE 443
|
||||
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
|
||||
WORKDIR /src
|
||||
COPY ["WotBlitzStatisticsPro.GraphQl/WotBlitzStatisticsPro.GraphQl.csproj", "WotBlitzStatisticsPro.GraphQl/"]
|
||||
COPY ["WotBlitzStatisticsPro.Blazor/WotBlitzStatisticsPro.Blazor.csproj", "WotBlitzStatisticsPro.Blazor/"]
|
||||
COPY ["WotBlitzStatisticsPro.Logic/WotBlitzStatisticsPro.Logic.csproj", "WotBlitzStatisticsPro.Logic/"]
|
||||
COPY ["WotBlitzStatisticsPro.DataAccess/WotBlitzStatisticsPro.DataAccess.csproj", "WotBlitzStatisticsPro.DataAccess/"]
|
||||
COPY ["WotBlitzStatisticsPro.Common/WotBlitzStatisticsPro.Common.csproj", "WotBlitzStatisticsPro.Common/"]
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using System.Threading;
|
||||
using Bunit;
|
||||
using FluentAssertions;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Radzen;
|
||||
using WotBlitzStatisticsPro.Blazor.Messages;
|
||||
using WotBlitzStatisticsPro.Blazor.Services;
|
||||
using WotBlitzStatisticsPro.Blazor.Shared;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Tests
|
||||
{
|
||||
public class MainLayoutTest: TestContextWrapper
|
||||
{
|
||||
private readonly Mock<IMediator> _mediatorMock = new();
|
||||
private readonly Mock<ISearchDialogService> _searchServiceMock = new();
|
||||
private IRenderedComponent<MainLayout> _component;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
TestContext = new Bunit.TestContext();
|
||||
TestContext.Services.AddSingleton(_mediatorMock.Object);
|
||||
|
||||
TestContext.Services.AddSingleton<DialogService>();
|
||||
TestContext.Services.AddSingleton(_searchServiceMock.Object);
|
||||
TestContext.Services.AddLocalization();
|
||||
|
||||
_component = TestContext.RenderComponent<MainLayout>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldFireMediatorEventEachTimeWhenLanguageChanged()
|
||||
{
|
||||
// =====================================
|
||||
// Hint for css lookup
|
||||
/*
|
||||
By.css('.classname') // get by class name
|
||||
By.css('input[type=radio]') // get input by type radio
|
||||
By.css('.parent .child') // get child who has a parent
|
||||
*/
|
||||
|
||||
// Take a look at the component text
|
||||
// var html = _component.Markup;
|
||||
|
||||
// =====================================
|
||||
|
||||
// All 3 languages in a RadzenSplitButton
|
||||
var elements = _component.FindAll(".rz-menuitem");
|
||||
|
||||
elements.Should().NotBeNull();
|
||||
elements.Count.Should().Be(3);
|
||||
|
||||
string[] expectedLanguages = {"en-US", "ru-RU", "de-DE"};
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
elements[i].Click();
|
||||
_mediatorMock.Verify(m => m.Publish(
|
||||
It.Is<ChangeCurrentCultureMessage>(m => m.CultureName == expectedLanguages[0]),
|
||||
It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() => TestContext?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="bunit.web" Version="1.1.5" />
|
||||
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="Radzen.Blazor" Version="3.2.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WotBlitzStatisticsPro.Blazor\WotBlitzStatisticsPro.Blazor.csproj" />
|
||||
<ProjectReference Include="..\WotBlitzStatisticsPro.Common\WotBlitzStatisticsPro.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.Tests
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.Blazor", "WotBlitzStatisticsPro.Blazor\WotBlitzStatisticsPro.Blazor.csproj", "{3A27736F-B5DD-4310-A013-2BB65C975104}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatisticsPro.Blazor.Tests", "WotBlitzStatisticsPro.Blazor.Tests\WotBlitzStatisticsPro.Blazor.Tests.csproj", "{7969D13E-2148-4608-8500-2DA22947A39C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -53,6 +55,10 @@ Global
|
||||
{3A27736F-B5DD-4310-A013-2BB65C975104}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3A27736F-B5DD-4310-A013-2BB65C975104}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3A27736F-B5DD-4310-A013-2BB65C975104}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7969D13E-2148-4608-8500-2DA22947A39C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7969D13E-2148-4608-8500-2DA22947A39C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7969D13E-2148-4608-8500-2DA22947A39C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7969D13E-2148-4608-8500-2DA22947A39C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in new issue
Block a user