-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix for dependency injeciton in Multilanguage package * Unit tests added (to be continued)
- Loading branch information
Showing
17 changed files
with
147 additions
and
20 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
source/PiotrTrojan.AspNetCore.IdentityErrorLocalization.Test/MultilangTest.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,76 @@ | ||
using HttpContextMoq; | ||
using HttpContextMoq.Extensions; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Primitives; | ||
using Moq; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.de_DE; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.es_ES; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.fa_IR; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.fr_FR; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.pl_PL; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.pt_PT; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.ru_RU; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.sv_SE; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.tr_TR; | ||
using PiotrTrojan.AspNetCore.IdentityErrorLocalization.uk_UA; | ||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace PiotrTrojan.AspNetCore.IdentityErrorLocalization.Test | ||
{ | ||
public class MultilangTest | ||
{ | ||
[Fact] | ||
public void DiTest() | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddMultilangIdentityErrorDescriberFactory(); | ||
var sp = serviceCollection.BuildServiceProvider(); | ||
var factory = sp.GetService<IdentityErrorDescriberFactory>(); | ||
Assert.NotNull(factory); | ||
} | ||
|
||
[Theory] | ||
[InlineData("de", typeof(GermanIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
[InlineData("es", typeof(SpanishIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
[InlineData("fa", typeof(PersianIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
[InlineData("fr", typeof(FrenchIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
[InlineData("pl", typeof(PolishIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
[InlineData("pt", typeof(PortugueseIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
[InlineData("ru", typeof(RussianIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
[InlineData("sv", typeof(SwedishIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
[InlineData("tr", typeof(TurkishIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
[InlineData("uk", typeof(UkrainianIdentityErrorDescriber), typeof(IdentityErrorDescriber))] | ||
public void MultilanguageFactoryTest<T>(string lang, Type validDescriberType, Type invalidDescriberType) | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
var httpContextMock = new HttpContextMock(); | ||
httpContextMock.SetupRequestHeaders(new Dictionary<string, StringValues> | ||
{ | ||
{ "Accept-Language", lang } | ||
}); | ||
var mockHttpContextAccessor = new Mock<IHttpContextAccessor>(); | ||
mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(httpContextMock); | ||
serviceCollection.AddTransient<IHttpContextAccessor>(sp => | ||
{ | ||
return mockHttpContextAccessor.Object; | ||
}); | ||
|
||
var validErrorDescriber = (IdentityErrorDescriber)Activator.CreateInstance(validDescriberType); | ||
var invalidErrorDescriber = (IdentityErrorDescriber)Activator.CreateInstance(invalidDescriberType); | ||
|
||
serviceCollection.AddMultilangIdentityErrorDescriberFactory(); | ||
var factory = serviceCollection.BuildServiceProvider().GetService<IdentityErrorDescriberFactory>(); | ||
|
||
Assert.NotNull(factory); | ||
Assert.Equal(factory.GetDescriber().DefaultError().Description, validErrorDescriber.DefaultError().Description); | ||
Assert.NotEqual(factory.GetDescriber().DefaultError().Description, invalidErrorDescriber.DefaultError().Description); | ||
} | ||
|
||
// TODO: Additional tests of dependency injection should be done here (e.g. AddTurkishIdentityErrorDescriber) | ||
|
||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...entityErrorLocalization.Test/PiotrTrojan.AspNetCore.IdentityErrorLocalization.Test.csproj
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,40 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="HttpContextMoq" Version="1.2.1" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> | ||
<PackageReference Include="Moq" Version="4.16.1" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="1.3.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!--<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.de-DE\PiotrTrojan.AspNetCore.IdentityErrorLocalization.de-DE.csproj" /> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.es-ES\PiotrTrojan.AspNetCore.IdentityErrorLocalization.es-ES.csproj" /> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.fa-IR\PiotrTrojan.AspNetCore.IdentityErrorLocalization.fa-IR.csproj" /> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.fr-FR\PiotrTrojan.AspNetCore.IdentityErrorLocalization.fr-FR.csproj" /> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.pl-PL\PiotrTrojan.AspNetCore.IdentityErrorLocalization.pl-PL.csproj" /> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.pt-PT\PiotrTrojan.AspNetCore.IdentityErrorLocalization.pt-PT.csproj" /> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.ru-RU\PiotrTrojan.AspNetCore.IdentityErrorLocalization.ru-RU.csproj" /> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.sv-SE\PiotrTrojan.AspNetCore.IdentityErrorLocalization.sv-SE.csproj" /> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.tr-TR\PiotrTrojan.AspNetCore.IdentityErrorLocalization.tr-TR.csproj" /> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization.uk-UA\PiotrTrojan.AspNetCore.IdentityErrorLocalization.uk-UA.csproj" />--> | ||
<ProjectReference Include="..\PiotrTrojan.AspNetCore.IdentityErrorLocalization\PiotrTrojan.AspNetCore.IdentityErrorLocalization.Multilang.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
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
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
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
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
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
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
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
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
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
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
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
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
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