-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'wezz-feature/translate-to-dictionary'
- Loading branch information
Showing
4 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
Tests/DbLocalizationProvider.Tests/DictionaryConvertTests/_Tests.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,74 @@ | ||
using DbLocalizationProvider.Internal; | ||
using DbLocalizationProvider.Queries; | ||
using DbLocalizationProvider.Refactoring; | ||
using DbLocalizationProvider.Sync; | ||
using DbLocalizationProvider.Tests.DataAnnotations; | ||
using Microsoft.Extensions.Options; | ||
using System.Collections.Generic; | ||
using DbLocalizationProvider.Abstractions; | ||
using Xunit; | ||
|
||
namespace DbLocalizationProvider.Tests.DictionaryConvertTests; | ||
|
||
public class _Tests | ||
{ | ||
private readonly LocalizationProvider _provider; | ||
|
||
public _Tests() | ||
{ | ||
var state = new ScanState(); | ||
var ctx = new ConfigurationContext(); | ||
var wrapper = new OptionsWrapper<ConfigurationContext>(ctx); | ||
var keyBuilder = new ResourceKeyBuilder(state, wrapper); | ||
|
||
ctx.TypeFactory | ||
.ForQuery<DetermineDefaultCulture.Query>() | ||
.SetHandler<DetermineDefaultCulture.Handler>() | ||
.ForQuery<GetTranslation.Query>() | ||
.SetHandler<GetTranslationReturnResourceKeyHandler>(); | ||
|
||
var queryExecutor = new QueryExecutor(ctx.TypeFactory); | ||
|
||
var expressHelper = new ExpressionHelper(keyBuilder); | ||
_provider = new LocalizationProvider(keyBuilder, | ||
expressHelper, | ||
wrapper, | ||
queryExecutor, | ||
new ScanState()); | ||
} | ||
|
||
[Fact] | ||
public void ConvertToDictionary() | ||
{ | ||
var result = _provider.ToDictionary(typeof(ResourceToDictionaryModel)); | ||
|
||
Assert.NotNull(result); | ||
Assert.Single(result); | ||
Assert.True(result.ContainsKey("DbLocalizationProvider.Tests.DictionaryConvertTests.ResourceToDictionaryModel.Property1")); | ||
} | ||
|
||
|
||
[Fact] | ||
public void ConvertToDictionary_HiddenResource_ShouldNotInclude() | ||
{ | ||
var result = _provider.ToDictionary<ResourceToDictionaryModelWithHiddenProperty>(); | ||
|
||
Assert.Single(result); | ||
Assert.True(result.ContainsKey("DbLocalizationProvider.Tests.DictionaryConvertTests.ResourceToDictionaryModelWithHiddenProperty.Property1")); | ||
} | ||
} | ||
|
||
[LocalizedResource] | ||
public class ResourceToDictionaryModel | ||
{ | ||
public string Property1 { get; set; } | ||
} | ||
|
||
[LocalizedResource] | ||
public class ResourceToDictionaryModelWithHiddenProperty | ||
{ | ||
public string Property1 { get; set; } | ||
|
||
[Hidden] | ||
public string Property2 { get; set; } | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/DbLocalizationProvider/Internal/PropertyInfoExtensions.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,22 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using DbLocalizationProvider.Abstractions; | ||
|
||
namespace DbLocalizationProvider.Internal; | ||
|
||
/// <summary> | ||
/// Some extensions for properties | ||
/// </summary> | ||
public static class PropertyInfoExtensions | ||
{ | ||
/// <summary> | ||
/// Checks whether property is hidden or not. | ||
/// </summary> | ||
/// <param name="property">Property to check for.</param> | ||
/// <returns><c>true</c> if property is hidden, otherwise <c>false</c>.</returns> | ||
public static bool IsHidden(this PropertyInfo property) | ||
{ | ||
return Attribute.GetCustomAttributes(property).FirstOrDefault(a => a is HiddenAttribute) != null; | ||
} | ||
} |
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