-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from Ashampoo/develop
fix: get correct format provider
- Loading branch information
Showing
6 changed files
with
123 additions
and
4 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
30 changes: 30 additions & 0 deletions
30
Ashampoo.Translation.Systems.Formats.Tests/Ashampoo.Translation.Systems.Formats.Tests.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,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/> | ||
<PackageReference Include="xunit" Version="2.4.2"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\Ashampoo.Translation.Systems.Formats\src\Ashampoo.Translation.Systems.Formats.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
69 changes: 69 additions & 0 deletions
69
Ashampoo.Translation.Systems.Formats.Tests/DefaultFormatFactoryTests.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,69 @@ | ||
using Ashampoo.Translation.Systems.Formats.Abstractions; | ||
using Ashampoo.Translation.Systems.Formats.AshLang; | ||
using Ashampoo.Translation.Systems.Formats.Gengo; | ||
using Ashampoo.Translation.Systems.Formats.JavaProperties; | ||
using Ashampoo.Translation.Systems.Formats.Json; | ||
using Ashampoo.Translation.Systems.Formats.NLang; | ||
using Ashampoo.Translation.Systems.Formats.PO; | ||
using Ashampoo.Translation.Systems.Formats.ResX; | ||
using Ashampoo.Translation.Systems.Formats.TsProj; | ||
using FluentAssertions; | ||
|
||
namespace Ashampoo.Translation.Systems.Formats.Tests; | ||
|
||
public sealed class DefaultFormatFactoryTests | ||
{ | ||
public static IEnumerable<object[]> GetTestData() | ||
{ | ||
yield return [new AshLangFormat(), typeof(AshLangFormatProvider)]; | ||
yield return [new GengoFormat(), typeof(GengoFormatProvider)]; | ||
yield return [new JavaPropertiesFormat(), typeof(JavaPropertiesFormatProvider)]; | ||
yield return [new JsonFormat(), typeof(JsonFormatProvider)]; | ||
yield return [new NLangFormat(), typeof(NLangFormatProvider)]; | ||
yield return [new POFormat(), typeof(POFormatProvider)]; | ||
yield return [new ResXFormat(), typeof(ResXFormatProvider)]; | ||
yield return [new TsProjFormat(), typeof(TsProjFormatProvider)]; | ||
} | ||
|
||
|
||
[Theory] | ||
[MemberData(nameof(GetTestData))] | ||
public void GetFormatProvider_FromFormat(IFormat format, Type providerType) | ||
{ | ||
IEnumerable<IFormatProvider<IFormat>> providers = | ||
[ | ||
new AshLangFormatProvider(), new GengoFormatProvider(), new JavaPropertiesFormatProvider(), | ||
new JsonFormatProvider(), new NLangFormatProvider(), new POFormatProvider(), new ResXFormatProvider(), | ||
new TsProjFormatProvider() | ||
]; | ||
|
||
var formatFactory = new DefaultFormatFactory(providers); | ||
var formatProvider = formatFactory.GetFormatProvider(format); | ||
formatProvider.Should().BeOfType(providerType); | ||
} | ||
|
||
|
||
[Theory] | ||
[InlineData("ashlang", typeof(AshLangFormatProvider))] | ||
[InlineData("gengo", typeof(GengoFormatProvider))] | ||
[InlineData("javaProperties", typeof(JavaPropertiesFormatProvider))] | ||
[InlineData("json", typeof(JsonFormatProvider))] | ||
[InlineData("nlang", typeof(NLangFormatProvider))] | ||
[InlineData("po", typeof(POFormatProvider))] | ||
[InlineData("resx", typeof(ResXFormatProvider))] | ||
[InlineData("tsproj", typeof(TsProjFormatProvider))] | ||
public void GetFormatProvider_FromId(string formatId, Type providerType) | ||
{ | ||
IEnumerable<IFormatProvider<IFormat>> providers = | ||
[ | ||
new AshLangFormatProvider(), new GengoFormatProvider(), new JavaPropertiesFormatProvider(), | ||
new JsonFormatProvider(), new NLangFormatProvider(), new POFormatProvider(), new ResXFormatProvider(), | ||
new TsProjFormatProvider() | ||
]; | ||
|
||
var formatFactory = new DefaultFormatFactory(providers); | ||
var formatProvider = formatFactory.GetFormatProvider(formatId); | ||
formatProvider.Should().BeOfType(providerType); | ||
} | ||
|
||
} |
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 @@ | ||
global using Xunit; |
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