-
Notifications
You must be signed in to change notification settings - Fork 27
Localization extension - complex entity class hierarchies and projection to custom types #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alex-kulakov
merged 6 commits into
DataObjects-NET:master
from
beercsaba:test-localization-projectiontocustomtypes
Jan 12, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3ca8122
model and test for 'Localization extension - complex entity class hie…
beercsaba 6f91a83
one solution for the issue
beercsaba e43b362
Simplification
beercsaba cbfee91
format fixes
beercsaba 9ed7753
required changes
beercsaba 4efec2b
Merge branch 'master' into test-localization-projectiontocustomtypes
beercsaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
Extensions/Xtensive.Orm.Localization.Tests/Model/DictionaryModel.cs
This file contains hidden or 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,58 @@ | ||
// Copyright (C) 2020 Xtensive LLC. | ||
// This code is distributed under MIT license terms. | ||
// See the License.txt file in the project root for more information. | ||
|
||
using System.Globalization; | ||
using Xtensive.Orm.Model; | ||
|
||
namespace Xtensive.Orm.Localization.Tests.Model | ||
{ | ||
[HierarchyRoot(InheritanceSchema = InheritanceSchema.ConcreteTable)] | ||
public abstract class AbstractDictionary : Entity | ||
{ | ||
[Key, Field] | ||
public int Id { get; private set; } | ||
|
||
[Field(Nullable = false, Length = 64)] | ||
public string Identifier { get; set; } | ||
|
||
// abstract property | ||
public abstract string Name { get; set; } | ||
|
||
protected AbstractDictionary(Session session) : base(session) { } | ||
} | ||
|
||
public abstract class AbstractLocalizableDictionary<T, TT> : AbstractDictionary, ILocalizable<TT> | ||
where T : AbstractLocalizableDictionary<T, TT> | ||
where TT : AbstractDictionaryLocalization<T, TT> | ||
{ | ||
public override string Name { get => Localizations.Current.Name; set => Localizations.Current.Name = value; } | ||
|
||
[Field] | ||
public LocalizationSet<TT> Localizations { get; private set; } | ||
|
||
protected AbstractLocalizableDictionary(Session session) : base(session) { } | ||
} | ||
|
||
public abstract class AbstractDictionaryLocalization<T, TT> : Localization<T> | ||
where TT : AbstractDictionaryLocalization<T, TT> | ||
where T : AbstractLocalizableDictionary<T, TT> | ||
{ | ||
[Field(Nullable = false, Length = 512)] | ||
public string Name { get; set; } | ||
|
||
protected AbstractDictionaryLocalization(Session session, CultureInfo culture, T target) : base(session, culture, target) { } | ||
} | ||
|
||
public class Country : AbstractLocalizableDictionary<Country, CountryLocalization>, ILocalizable<CountryLocalization> | ||
{ | ||
public Country(Session session) : base(session) { } | ||
} | ||
|
||
[HierarchyRoot] | ||
public class CountryLocalization : AbstractDictionaryLocalization<Country, CountryLocalization> | ||
{ | ||
public CountryLocalization(Session session, CultureInfo culture, Country target) : base(session, culture, target) { } | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
Extensions/Xtensive.Orm.Localization.Tests/ProjectionToCustomTypesTests.cs
This file contains hidden or 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,56 @@ | ||
// Copyright (C) 2020 Xtensive LLC. | ||
// This code is distributed under MIT license terms. | ||
// See the License.txt file in the project root for more information. | ||
|
||
using System.Linq; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
using Xtensive.Orm.Localization.Tests.Model; | ||
|
||
namespace Xtensive.Orm.Localization.Tests | ||
{ | ||
[TestFixture] | ||
public class ProjectionToCustomTypesTests : AutoBuildTest | ||
{ | ||
protected override void PopulateDatabase() | ||
{ | ||
using (var session = Domain.OpenSession()) | ||
using (var ts = session.OpenTransaction()) { | ||
// populating database | ||
var m1 = new Country(session) { | ||
Identifier = "HUN", | ||
Name = "Magyarország" | ||
}; | ||
var m2 = new Country(session) { | ||
Identifier = "RUS", | ||
Name = "Oroszország" | ||
}; | ||
using (new LocalizationScope(EnglishCulture)) { | ||
m2.Name = "Russia"; | ||
} | ||
using (new LocalizationScope(SpanishCulture)) { | ||
m2.Name = "Rusia"; | ||
} | ||
ts.Complete(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void EntityHierarchyWithAbstractPropertyTest() | ||
{ | ||
Thread.CurrentThread.CurrentCulture = EnglishCulture; | ||
using (var session = Domain.OpenSession()) | ||
using (var ts = session.OpenTransaction()) { | ||
var q = session.Query.All<Country>().OrderBy(e => e.Identifier).Select(e => new { e.Name }); | ||
var l = q.ToList(); | ||
// assertions | ||
Assert.AreEqual(2, l.Count); | ||
var propertyInfos = l.First().GetType().GetProperties(); | ||
Assert.AreEqual(propertyInfos.Length, 1); | ||
Assert.AreEqual(propertyInfos.First().Name, nameof(Country.Name)); | ||
Assert.AreEqual(l.First().Name, "Magyarország"); | ||
Assert.AreEqual(l.Last().Name, "Russia"); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.