intermediate steps toward purging static current locale

This commit is contained in:
Robert McRackan 2020-08-20 22:53:44 -04:00
parent cfa938360a
commit 901572e7bb
3 changed files with 19 additions and 33 deletions

View File

@ -102,7 +102,7 @@ namespace InternalUtilities
if (acct != null) if (acct != null)
return acct; return acct;
var l = Localization.Locales.Single(l => l.Name == locale); var l = Localization.Get(locale);
var id = new Identity(l); var id = new Identity(l);
var account = new Account(accountId) { IdentityTokens = id }; var account = new Account(accountId) { IdentityTokens = id };

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> --> <!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>3.1.12.142</Version> <Version>3.1.12.152</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -137,6 +137,8 @@ namespace AccountsTests
public class AccountsTestBase public class AccountsTestBase
{ {
protected string TestFile; protected string TestFile;
protected Locale usLocale => Localization.Get("us");
protected Locale ukLocale => Localization.Get("uk");
protected void WriteToTestFile(string contents) protected void WriteToTestFile(string contents)
=> File.WriteAllText(TestFile, contents); => File.WriteAllText(TestFile, contents);
@ -205,7 +207,6 @@ namespace AccountsTests
[TestMethod] [TestMethod]
public void save_with_identity() public void save_with_identity()
{ {
var usLocale = Localization.Locales.Single(l => l.Name == "us");
var id = new Identity(usLocale); var id = new Identity(usLocale);
var idJson = JsonConvert.SerializeObject(id, Identity.GetJsonSerializerSettings()); var idJson = JsonConvert.SerializeObject(id, Identity.GetJsonSerializerSettings());
@ -235,8 +236,7 @@ namespace AccountsTests
// load file. create account // load file. create account
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsPersister(TestFile))
{ {
var localeIn = Localization.Locales.Single(l => l.Name == "us"); var idIn = new Identity(usLocale);
var idIn = new Identity(localeIn);
var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn }; var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn };
p.Accounts.Add(acctIn); p.Accounts.Add(acctIn);
@ -263,8 +263,7 @@ namespace AccountsTests
// load file. create account 0 // load file. create account 0
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsPersister(TestFile))
{ {
var localeIn = Localization.Locales.Single(l => l.Name == "us"); var idIn = new Identity(usLocale);
var idIn = new Identity(localeIn);
var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn }; var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn };
p.Accounts.Add(acctIn); p.Accounts.Add(acctIn);
@ -283,8 +282,7 @@ namespace AccountsTests
// load file. create account 1 // load file. create account 1
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsPersister(TestFile))
{ {
var localeIn = Localization.Locales.Single(l => l.Name == "uk"); var idIn = new Identity(ukLocale);
var idIn = new Identity(localeIn);
var acctIn = new Account("a1") { AccountName = "n1", IdentityTokens = idIn }; var acctIn = new Account("a1") { AccountName = "n1", IdentityTokens = idIn };
p.Accounts.Add(acctIn); p.Accounts.Add(acctIn);
@ -314,8 +312,7 @@ namespace AccountsTests
// load file. create 2 accounts // load file. create 2 accounts
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsPersister(TestFile))
{ {
var locale1 = Localization.Locales.Single(l => l.Name == "us"); var id1 = new Identity(usLocale);
var id1 = new Identity(locale1);
var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 };
p.Accounts.Add(acct1); p.Accounts.Add(acct1);
@ -341,13 +338,11 @@ namespace AccountsTests
// load file. create 2 accounts // load file. create 2 accounts
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsPersister(TestFile))
{ {
var locale1 = Localization.Locales.Single(l => l.Name == "us"); var id1 = new Identity(usLocale);
var id1 = new Identity(locale1);
var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 };
p.Accounts.Add(acct1); p.Accounts.Add(acct1);
var locale2 = Localization.Locales.Single(l => l.Name == "uk"); var id2 = new Identity(ukLocale);
var id2 = new Identity(locale2);
var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 }; var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 };
p.Accounts.Add(acct2); p.Accounts.Add(acct2);
@ -387,13 +382,11 @@ namespace AccountsTests
// load file. create 2 accounts // load file. create 2 accounts
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsPersister(TestFile))
{ {
var locale1 = Localization.Locales.Single(l => l.Name == "us"); var id1 = new Identity(usLocale);
var id1 = new Identity(locale1);
var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 };
p.Accounts.Add(acct1); p.Accounts.Add(acct1);
var locale2 = Localization.Locales.Single(l => l.Name == "uk"); var id2 = new Identity(ukLocale);
var id2 = new Identity(locale2);
var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 }; var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 };
p.Accounts.Add(acct2); p.Accounts.Add(acct2);
@ -402,8 +395,7 @@ namespace AccountsTests
// update identity on existing file // update identity on existing file
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsPersister(TestFile))
{ {
var locale = Localization.Locales.Single(l => l.Name == "uk"); var id = new Identity(ukLocale);
var id = new Identity(locale);
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.Accounts.AccountsSettings[0];
acct0.IdentityTokens = id; acct0.IdentityTokens = id;
@ -437,13 +429,11 @@ namespace AccountsTests
// load file. create 2 accounts // load file. create 2 accounts
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsPersister(TestFile))
{ {
var locale1 = Localization.Locales.Single(l => l.Name == "us"); var id1 = new Identity(usLocale);
var id1 = new Identity(locale1);
var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 };
p.Accounts.Add(acct1); p.Accounts.Add(acct1);
var locale2 = Localization.Locales.Single(l => l.Name == "uk"); var id2 = new Identity(ukLocale);
var id2 = new Identity(locale2);
var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 }; var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 };
p.Accounts.Add(acct2); p.Accounts.Add(acct2);
@ -482,12 +472,10 @@ namespace AccountsTests
[TestMethod] [TestMethod]
public void get_where() public void get_where()
{ {
var us = Localization.Locales.Single(l => l.Name == "us"); var idUs = new Identity(usLocale);
var idUs = new Identity(us);
var acct1 = new Account("cng") { IdentityTokens = idUs, AccountName = "foo" }; var acct1 = new Account("cng") { IdentityTokens = idUs, AccountName = "foo" };
var uk = Localization.Locales.Single(l => l.Name == "uk"); var idUk = new Identity(ukLocale);
var idUk = new Identity(uk);
var acct2 = new Account("cng") { IdentityTokens = idUk, AccountName = "bar" }; var acct2 = new Account("cng") { IdentityTokens = idUk, AccountName = "bar" };
var accounts = new Accounts(); var accounts = new Accounts();
@ -595,8 +583,7 @@ namespace AccountsTests
{ {
var accounts = new Accounts(); var accounts = new Accounts();
var localeIn = Localization.Locales.Single(l => l.Name == "us"); var idIn = new Identity(usLocale);
var idIn = new Identity(localeIn);
var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn }; var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn };
accounts.Add(a1); accounts.Add(a1);
@ -612,8 +599,7 @@ namespace AccountsTests
{ {
var accounts = new Accounts(); var accounts = new Accounts();
var localeIn = Localization.Locales.Single(l => l.Name == "us"); var idIn = new Identity(usLocale);
var idIn = new Identity(localeIn);
var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn }; var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn };
accounts.Add(a1); accounts.Add(a1);