Rename for clarity: AccountsSettings <=> Accounts

This commit is contained in:
Robert McRackan 2020-08-24 22:57:08 -04:00
parent 743644c4e9
commit 6900a68b9d
11 changed files with 265 additions and 277 deletions

View File

@ -59,7 +59,7 @@ namespace FileLiberator
var proposedOutputFile = Path.Combine(AudibleFileStorage.DecryptInProgress, $"[{libraryBook.Book.AudibleProductId}].m4b"); var proposedOutputFile = Path.Combine(AudibleFileStorage.DecryptInProgress, $"[{libraryBook.Book.AudibleProductId}].m4b");
var account = AudibleApiStorage var account = AudibleApiStorage
.GetAccounts() .GetAccountsSettings()
.GetAccount(libraryBook.Account, libraryBook.Book.Locale); .GetAccount(libraryBook.Account, libraryBook.Book.Locale);
var outputAudioFilename = await aaxToM4bConverterDecrypt(proposedOutputFile, aaxFilename, account); var outputAudioFilename = await aaxToM4bConverterDecrypt(proposedOutputFile, aaxFilename, account);

View File

@ -10,49 +10,49 @@ using Newtonsoft.Json;
namespace InternalUtilities namespace InternalUtilities
{ {
public class AccountsPersister : JsonFilePersister<Accounts> public class AccountsSettingsPersister : JsonFilePersister<AccountsSettings>
{ {
/// <summary>Alias for Target </summary> /// <summary>Alias for Target </summary>
public Accounts Accounts => Target; public AccountsSettings AccountsSettings => Target;
/// <summary>uses path. create file if doesn't yet exist</summary> /// <summary>uses path. create file if doesn't yet exist</summary>
public AccountsPersister(Accounts target, string path, string jsonPath = null) public AccountsSettingsPersister(AccountsSettings target, string path, string jsonPath = null)
: base(target, path, jsonPath) { } : base(target, path, jsonPath) { }
/// <summary>load from existing file</summary> /// <summary>load from existing file</summary>
public AccountsPersister(string path, string jsonPath = null) public AccountsSettingsPersister(string path, string jsonPath = null)
: base(path, jsonPath) { } : base(path, jsonPath) { }
protected override JsonSerializerSettings GetSerializerSettings() protected override JsonSerializerSettings GetSerializerSettings()
=> Identity.GetJsonSerializerSettings(); => Identity.GetJsonSerializerSettings();
} }
// 'Accounts' is intentionally not IEnumerable<> so that properties can be added/extended // 'AccountsSettings' is intentionally not IEnumerable<> so that properties can be added/extended
// from newtonsoft (https://www.newtonsoft.com/json/help/html/SerializationGuide.htm): // from newtonsoft (https://www.newtonsoft.com/json/help/html/SerializationGuide.htm):
// .NET : IList, IEnumerable, IList<T>, Array // .NET : IList, IEnumerable, IList<T>, Array
// JSON : Array (properties on the collection will not be serialized) // JSON : Array (properties on the collection will not be serialized)
public class Accounts : IUpdatable public class AccountsSettings : IUpdatable
{ {
public event EventHandler Updated; public event EventHandler Updated;
private void update(object sender = null, EventArgs e = null) private void update(object sender = null, EventArgs e = null)
{ {
foreach (var account in AccountsSettings) foreach (var account in Accounts)
validate(account); validate(account);
update_no_validate(); update_no_validate();
} }
private void update_no_validate() => Updated?.Invoke(this, new EventArgs()); private void update_no_validate() => Updated?.Invoke(this, new EventArgs());
public Accounts() { } public AccountsSettings() { }
// for some reason this will make the json instantiator use _accountsSettings_json.set() // for some reason this will make the json instantiator use _accounts_json.set()
[JsonConstructor] [JsonConstructor]
protected Accounts(List<Account> accounts) { } protected AccountsSettings(List<Account> accountsSettings) { }
#region AccountsSettings #region Accounts
private List<Account> _accountsSettings_backing = new List<Account>(); private List<Account> _accounts_backing = new List<Account>();
[JsonProperty(PropertyName = "AccountsSettings")] [JsonProperty(PropertyName = "Accounts")]
private List<Account> _accountsSettings_json private List<Account> _accounts_json
{ {
get => _accountsSettings_backing; get => _accounts_backing;
// 'set' is only used by json deser // 'set' is only used by json deser
set set
{ {
@ -66,11 +66,11 @@ namespace InternalUtilities
} }
} }
[JsonIgnore] [JsonIgnore]
public IReadOnlyList<Account> AccountsSettings => _accountsSettings_json.AsReadOnly(); public IReadOnlyList<Account> Accounts => _accounts_json.AsReadOnly();
#endregion #endregion
public static Accounts FromJson(string json) public static AccountsSettings FromJson(string json)
=> JsonConvert.DeserializeObject<Accounts>(json, Identity.GetJsonSerializerSettings()); => JsonConvert.DeserializeObject<AccountsSettings>(json, Identity.GetJsonSerializerSettings());
public string ToJson(Formatting formatting = Formatting.Indented) public string ToJson(Formatting formatting = Formatting.Indented)
=> JsonConvert.SerializeObject(this, formatting, Identity.GetJsonSerializerSettings()); => JsonConvert.SerializeObject(this, formatting, Identity.GetJsonSerializerSettings());
@ -85,19 +85,19 @@ namespace InternalUtilities
{ {
validate(account); validate(account);
_accountsSettings_backing.Add(account); _accounts_backing.Add(account);
account.Updated += update; account.Updated += update;
} }
// more common naming convention alias for internal collection // more common naming convention alias for internal collection
public IReadOnlyList<Account> GetAll() => AccountsSettings; public IReadOnlyList<Account> GetAll() => Accounts;
public Account GetAccount(string accountId, string locale) public Account GetAccount(string accountId, string locale)
{ {
if (locale is null) if (locale is null)
return null; return null;
return AccountsSettings.SingleOrDefault(a => a.AccountId == accountId && a.IdentityTokens.Locale.Name == locale); return Accounts.SingleOrDefault(a => a.AccountId == accountId && a.IdentityTokens.Locale.Name == locale);
} }
public Account Upsert(string accountId, string locale) public Account Upsert(string accountId, string locale)
@ -117,11 +117,11 @@ namespace InternalUtilities
public bool Delete(Account account) public bool Delete(Account account)
{ {
if (!_accountsSettings_backing.Contains(account)) if (!_accounts_backing.Contains(account))
return false; return false;
account.Updated -= update; account.Updated -= update;
return _accountsSettings_backing.Remove(account); return _accounts_backing.Remove(account);
} }
public bool Delete(string accountId, string locale) public bool Delete(string accountId, string locale)

View File

@ -16,7 +16,7 @@ namespace InternalUtilities
{ {
// saves. BEWARE: this will overwrite an existing file // saves. BEWARE: this will overwrite an existing file
if (!File.Exists(AccountsSettingsFile)) if (!File.Exists(AccountsSettingsFile))
_ = new AccountsPersister(new Accounts(), AccountsSettingsFile); _ = new AccountsSettingsPersister(new AccountsSettings(), AccountsSettingsFile);
} }
// convenience for for tests and demos. don't use in production Libation // convenience for for tests and demos. don't use in production Libation
@ -24,10 +24,10 @@ namespace InternalUtilities
=> TEST_GetFirstAccount().GetIdentityTokensJsonPath(); => TEST_GetFirstAccount().GetIdentityTokensJsonPath();
// convenience for for tests and demos. don't use in production Libation // convenience for for tests and demos. don't use in production Libation
public static Account TEST_GetFirstAccount() public static Account TEST_GetFirstAccount()
=> GetAccounts().GetAll().FirstOrDefault(); => GetAccountsSettings().GetAll().FirstOrDefault();
public static Accounts GetAccounts() public static AccountsSettings GetAccountsSettings()
=> new AccountsPersister(AccountsSettingsFile).Accounts; => new AccountsSettingsPersister(AccountsSettingsFile).AccountsSettings;
public static string GetIdentityTokensJsonPath(this Account account) public static string GetIdentityTokensJsonPath(this Account account)
=> GetIdentityTokensJsonPath(account.AccountId, account.Locale?.Name); => GetIdentityTokensJsonPath(account.AccountId, account.Locale?.Name);
@ -36,7 +36,7 @@ namespace InternalUtilities
var usernameSanitized = trimSurroundingQuotes(JsonConvert.ToString(username)); var usernameSanitized = trimSurroundingQuotes(JsonConvert.ToString(username));
var localeNameSanitized = trimSurroundingQuotes(JsonConvert.ToString(localeName)); var localeNameSanitized = trimSurroundingQuotes(JsonConvert.ToString(localeName));
return $"$.AccountsSettings[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeNameSanitized}')].IdentityTokens"; return $"$.Accounts[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeNameSanitized}')].IdentityTokens";
} }
// SubString algo is better than .Trim("\"") // SubString algo is better than .Trim("\"")
// orig string " // orig string "

View File

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

View File

@ -162,7 +162,7 @@ namespace LibationLauncher
}; };
// saves to new file // saves to new file
AudibleApiStorage.GetAccounts().Add(account); AudibleApiStorage.GetAccountsSettings().Add(account);
return account; return account;
} }

View File

@ -82,12 +82,8 @@
this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(776, 397); this.dataGridView1.Size = new System.Drawing.Size(776, 397);
this.dataGridView1.TabIndex = 0; this.dataGridView1.TabIndex = 0;
this.dataGridView1.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_CellBeginEdit);
this.dataGridView1.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEndEdit);
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView1_CellContentClick); this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView1_CellContentClick);
this.dataGridView1.DefaultValuesNeeded += new System.Windows.Forms.DataGridViewRowEventHandler(this.dataGridView1_DefaultValuesNeeded); this.dataGridView1.DefaultValuesNeeded += new System.Windows.Forms.DataGridViewRowEventHandler(this.dataGridView1_DefaultValuesNeeded);
this.dataGridView1.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.dataGridView1_RowsAdded);
this.dataGridView1.RowsRemoved += new System.Windows.Forms.DataGridViewRowsRemovedEventHandler(this.dataGridView1_RowsRemoved);
// //
// Original // Original
// //

View File

@ -2,7 +2,6 @@
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using AudibleApi; using AudibleApi;
using FileManager;
using InternalUtilities; using InternalUtilities;
namespace LibationWinForms.Dialogs namespace LibationWinForms.Dialogs
@ -37,7 +36,12 @@ namespace LibationWinForms.Dialogs
private void populateGridValues() private void populateGridValues()
{ {
var accounts = AudibleApiStorage.GetAccounts().AccountsSettings; // WARNING
// behind the scenes this returns a AccountsSettings
// accounts persister will write ANY EDIT to object immediately to file
// here: copy strings
// only persist in 'save' step
var accounts = AudibleApiStorage.GetAccountsSettings().Accounts;
if (!accounts.Any()) if (!accounts.Any())
return; return;
@ -92,42 +96,21 @@ namespace LibationWinForms.Dialogs
private void cancelBtn_Click(object sender, EventArgs e) => this.Close(); private void cancelBtn_Click(object sender, EventArgs e) => this.Close();
#region TEMP
private void saveBtn_Click(object sender, EventArgs e) private void saveBtn_Click(object sender, EventArgs e)
{ {
var accounts = AudibleApiStorage.GetAccountsSettings()
.Accounts;
// find added
// validate
// find deleted
// find edited
// validate
// persist
} }
private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
//if (e.ColumnIndex == dataGridView1.Columns["ItemID"].Index) //if the ItemID-cell is edited
//{
// dataGridView1.Rows[e.RowIndex].ReadOnly = true; // set all row as read-only
// dataGridView1.Rows[e.RowIndex].Cells["ItemID"].ReadOnly = false; //except ItemID-cell
//}
}
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
//if (dataGridView1.Rows[e.RowIndex].Cells["ItemID"].Value != null)
//{
// dataGridView1.Rows[e.RowIndex].ReadOnly = true; // set all row as read-only
// dataGridView1.Rows[e.RowIndex].Cells["ItemID"].ReadOnly = false; //except ItemID-cell
//}
}
private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
{
}
#endregion
} }
} }

View File

@ -283,6 +283,7 @@
} }
#endregion #endregion
private System.Windows.Forms.Panel gridPanel; private System.Windows.Forms.Panel gridPanel;
private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem;
@ -309,4 +310,3 @@
private System.Windows.Forms.ToolStripMenuItem accountsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem accountsToolStripMenuItem;
} }
} }

View File

@ -1,33 +1,33 @@
namespace WinFormsDesigner namespace WinFormsDesigner
{ {
partial class Form1 partial class Form1
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
{ {
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.gridPanel = new System.Windows.Forms.Panel(); this.gridPanel = new System.Windows.Forms.Panel();
this.filterHelpBtn = new System.Windows.Forms.Button(); this.filterHelpBtn = new System.Windows.Forms.Button();
@ -44,6 +44,7 @@
this.editQuickFiltersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.editQuickFiltersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.accountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.basicSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.basicSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.advancedSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.advancedSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.statusStrip1 = new System.Windows.Forms.StatusStrip();
@ -59,8 +60,8 @@
// gridPanel // gridPanel
// //
this.gridPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.gridPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.gridPanel.Location = new System.Drawing.Point(12, 56); this.gridPanel.Location = new System.Drawing.Point(12, 56);
this.gridPanel.Name = "gridPanel"; this.gridPanel.Name = "gridPanel";
this.gridPanel.Size = new System.Drawing.Size(839, 386); this.gridPanel.Size = new System.Drawing.Size(839, 386);
@ -88,7 +89,7 @@
// filterSearchTb // filterSearchTb
// //
this.filterSearchTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.filterSearchTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.filterSearchTb.Location = new System.Drawing.Point(186, 29); this.filterSearchTb.Location = new System.Drawing.Point(186, 29);
this.filterSearchTb.Name = "filterSearchTb"; this.filterSearchTb.Name = "filterSearchTb";
this.filterSearchTb.Size = new System.Drawing.Size(584, 20); this.filterSearchTb.Size = new System.Drawing.Size(584, 20);
@ -97,10 +98,10 @@
// menuStrip1 // menuStrip1
// //
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.importToolStripMenuItem, this.importToolStripMenuItem,
this.liberateToolStripMenuItem, this.liberateToolStripMenuItem,
this.quickFiltersToolStripMenuItem, this.quickFiltersToolStripMenuItem,
this.settingsToolStripMenuItem}); this.settingsToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(863, 24); this.menuStrip1.Size = new System.Drawing.Size(863, 24);
@ -110,7 +111,7 @@
// importToolStripMenuItem // importToolStripMenuItem
// //
this.importToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.importToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.scanLibraryToolStripMenuItem}); this.scanLibraryToolStripMenuItem});
this.importToolStripMenuItem.Name = "importToolStripMenuItem"; this.importToolStripMenuItem.Name = "importToolStripMenuItem";
this.importToolStripMenuItem.Size = new System.Drawing.Size(55, 20); this.importToolStripMenuItem.Size = new System.Drawing.Size(55, 20);
this.importToolStripMenuItem.Text = "&Import"; this.importToolStripMenuItem.Text = "&Import";
@ -124,8 +125,8 @@
// liberateToolStripMenuItem // liberateToolStripMenuItem
// //
this.liberateToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.liberateToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.beginBookBackupsToolStripMenuItem, this.beginBookBackupsToolStripMenuItem,
this.beginPdfBackupsToolStripMenuItem}); this.beginPdfBackupsToolStripMenuItem});
this.liberateToolStripMenuItem.Name = "liberateToolStripMenuItem"; this.liberateToolStripMenuItem.Name = "liberateToolStripMenuItem";
this.liberateToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.liberateToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
this.liberateToolStripMenuItem.Text = "&Liberate"; this.liberateToolStripMenuItem.Text = "&Liberate";
@ -145,9 +146,9 @@
// quickFiltersToolStripMenuItem // quickFiltersToolStripMenuItem
// //
this.quickFiltersToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.quickFiltersToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.firstFilterIsDefaultToolStripMenuItem, this.firstFilterIsDefaultToolStripMenuItem,
this.editQuickFiltersToolStripMenuItem, this.editQuickFiltersToolStripMenuItem,
this.toolStripSeparator1}); this.toolStripSeparator1});
this.quickFiltersToolStripMenuItem.Name = "quickFiltersToolStripMenuItem"; this.quickFiltersToolStripMenuItem.Name = "quickFiltersToolStripMenuItem";
this.quickFiltersToolStripMenuItem.Size = new System.Drawing.Size(84, 20); this.quickFiltersToolStripMenuItem.Size = new System.Drawing.Size(84, 20);
this.quickFiltersToolStripMenuItem.Text = "Quick &Filters"; this.quickFiltersToolStripMenuItem.Text = "Quick &Filters";
@ -162,7 +163,7 @@
// //
this.editQuickFiltersToolStripMenuItem.Name = "editQuickFiltersToolStripMenuItem"; this.editQuickFiltersToolStripMenuItem.Name = "editQuickFiltersToolStripMenuItem";
this.editQuickFiltersToolStripMenuItem.Size = new System.Drawing.Size(256, 22); this.editQuickFiltersToolStripMenuItem.Size = new System.Drawing.Size(256, 22);
this.editQuickFiltersToolStripMenuItem.Text = "&Edit quick filters"; this.editQuickFiltersToolStripMenuItem.Text = "&Edit quick filters...";
// //
// toolStripSeparator1 // toolStripSeparator1
// //
@ -172,31 +173,38 @@
// settingsToolStripMenuItem // settingsToolStripMenuItem
// //
this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.basicSettingsToolStripMenuItem, this.accountsToolStripMenuItem,
this.advancedSettingsToolStripMenuItem}); this.basicSettingsToolStripMenuItem,
this.advancedSettingsToolStripMenuItem});
this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
this.settingsToolStripMenuItem.Text = "&Settings"; this.settingsToolStripMenuItem.Text = "&Settings";
// //
// accountsToolStripMenuItem
//
this.accountsToolStripMenuItem.Name = "accountsToolStripMenuItem";
this.accountsToolStripMenuItem.Size = new System.Drawing.Size(181, 22);
this.accountsToolStripMenuItem.Text = "&Accounts...";
//
// basicSettingsToolStripMenuItem // basicSettingsToolStripMenuItem
// //
this.basicSettingsToolStripMenuItem.Name = "basicSettingsToolStripMenuItem"; this.basicSettingsToolStripMenuItem.Name = "basicSettingsToolStripMenuItem";
this.basicSettingsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.basicSettingsToolStripMenuItem.Size = new System.Drawing.Size(181, 22);
this.basicSettingsToolStripMenuItem.Text = "&Basic Settings"; this.basicSettingsToolStripMenuItem.Text = "&Basic Settings...";
// //
// advancedSettingsToolStripMenuItem // advancedSettingsToolStripMenuItem
// //
this.advancedSettingsToolStripMenuItem.Name = "advancedSettingsToolStripMenuItem"; this.advancedSettingsToolStripMenuItem.Name = "advancedSettingsToolStripMenuItem";
this.advancedSettingsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.advancedSettingsToolStripMenuItem.Size = new System.Drawing.Size(181, 22);
this.advancedSettingsToolStripMenuItem.Text = "&Advanced Settings"; this.advancedSettingsToolStripMenuItem.Text = "Ad&vanced Settings...";
// //
// statusStrip1 // statusStrip1
// //
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.visibleCountLbl, this.visibleCountLbl,
this.springLbl, this.springLbl,
this.backupsCountsLbl, this.backupsCountsLbl,
this.pdfsCountsLbl}); this.pdfsCountsLbl});
this.statusStrip1.Location = new System.Drawing.Point(0, 445); this.statusStrip1.Location = new System.Drawing.Point(0, 445);
this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(863, 22); this.statusStrip1.Size = new System.Drawing.Size(863, 22);
@ -212,7 +220,7 @@
// springLbl // springLbl
// //
this.springLbl.Name = "springLbl"; this.springLbl.Name = "springLbl";
this.springLbl.Size = new System.Drawing.Size(232, 17); this.springLbl.Size = new System.Drawing.Size(233, 17);
this.springLbl.Spring = true; this.springLbl.Spring = true;
// //
// backupsCountsLbl // backupsCountsLbl
@ -224,7 +232,7 @@
// pdfsCountsLbl // pdfsCountsLbl
// //
this.pdfsCountsLbl.Name = "pdfsCountsLbl"; this.pdfsCountsLbl.Name = "pdfsCountsLbl";
this.pdfsCountsLbl.Size = new System.Drawing.Size(219, 17); this.pdfsCountsLbl.Size = new System.Drawing.Size(218, 17);
this.pdfsCountsLbl.Text = "| PDFs: NOT d/l\'ed: {0} Downloaded: {1}"; this.pdfsCountsLbl.Text = "| PDFs: NOT d/l\'ed: {0} Downloaded: {1}";
// //
// addFilterBtn // addFilterBtn
@ -259,32 +267,33 @@
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.Panel gridPanel;
private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.Panel gridPanel;
private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem; private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem;
private System.Windows.Forms.ToolStripStatusLabel springLbl; private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel visibleCountLbl; private System.Windows.Forms.ToolStripStatusLabel springLbl;
private System.Windows.Forms.ToolStripMenuItem liberateToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel visibleCountLbl;
private System.Windows.Forms.ToolStripStatusLabel backupsCountsLbl; private System.Windows.Forms.ToolStripMenuItem liberateToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem beginBookBackupsToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel backupsCountsLbl;
private System.Windows.Forms.ToolStripStatusLabel pdfsCountsLbl; private System.Windows.Forms.ToolStripMenuItem beginBookBackupsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem beginPdfBackupsToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel pdfsCountsLbl;
private System.Windows.Forms.TextBox filterSearchTb; private System.Windows.Forms.ToolStripMenuItem beginPdfBackupsToolStripMenuItem;
private System.Windows.Forms.Button filterBtn; private System.Windows.Forms.TextBox filterSearchTb;
private System.Windows.Forms.Button filterHelpBtn; private System.Windows.Forms.Button filterBtn;
private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem; private System.Windows.Forms.Button filterHelpBtn;
private System.Windows.Forms.ToolStripMenuItem scanLibraryToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem quickFiltersToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem scanLibraryToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem firstFilterIsDefaultToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem quickFiltersToolStripMenuItem;
private System.Windows.Forms.Button addFilterBtn; private System.Windows.Forms.ToolStripMenuItem firstFilterIsDefaultToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editQuickFiltersToolStripMenuItem; private System.Windows.Forms.Button addFilterBtn;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripMenuItem editQuickFiltersToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem basicSettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem basicSettingsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem advancedSettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem advancedSettingsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem accountsToolStripMenuItem;
} }
} }

View File

@ -34,11 +34,11 @@ namespace AccountsTests
{ {
var json = @" var json = @"
{ {
""AccountsSettings"": [] ""Accounts"": []
} }
".Trim(); ".Trim();
var accounts = Accounts.FromJson(json); var accountsSettings = AccountsSettings.FromJson(json);
accounts.AccountsSettings.Count.Should().Be(0); accountsSettings.Accounts.Count.Should().Be(0);
} }
[TestMethod] [TestMethod]
@ -46,7 +46,7 @@ namespace AccountsTests
{ {
var json = @" var json = @"
{ {
""AccountsSettings"": [ ""Accounts"": [
{ {
""AccountId"": ""cng"", ""AccountId"": ""cng"",
""AccountName"": ""my main login"", ""AccountName"": ""my main login"",
@ -56,10 +56,10 @@ namespace AccountsTests
] ]
} }
".Trim(); ".Trim();
var accounts = Accounts.FromJson(json); var accountsSettings = AccountsSettings.FromJson(json);
accounts.AccountsSettings.Count.Should().Be(1); accountsSettings.Accounts.Count.Should().Be(1);
accounts.AccountsSettings[0].AccountId.Should().Be("cng"); accountsSettings.Accounts[0].AccountId.Should().Be("cng");
accounts.AccountsSettings[0].IdentityTokens.Should().BeNull(); accountsSettings.Accounts[0].IdentityTokens.Should().BeNull();
} }
[TestMethod] [TestMethod]
@ -69,7 +69,7 @@ namespace AccountsTests
var json = $@" var json = $@"
{{ {{
""AccountsSettings"": [ ""Accounts"": [
{{ {{
""AccountId"": ""cng"", ""AccountId"": ""cng"",
""AccountName"": ""my main login"", ""AccountName"": ""my main login"",
@ -79,11 +79,11 @@ namespace AccountsTests
] ]
}} }}
".Trim(); ".Trim();
var accounts = Accounts.FromJson(json); var accountsSettings = AccountsSettings.FromJson(json);
accounts.AccountsSettings.Count.Should().Be(1); accountsSettings.Accounts.Count.Should().Be(1);
accounts.AccountsSettings[0].AccountId.Should().Be("cng"); accountsSettings.Accounts[0].AccountId.Should().Be("cng");
accounts.AccountsSettings[0].IdentityTokens.Should().NotBeNull(); accountsSettings.Accounts[0].IdentityTokens.Should().NotBeNull();
accounts.AccountsSettings[0].IdentityTokens.ExistingAccessToken.TokenValue.Should().Be(AccessTokenValue); accountsSettings.Accounts[0].IdentityTokens.ExistingAccessToken.TokenValue.Should().Be(AccessTokenValue);
} }
} }
@ -96,7 +96,7 @@ namespace AccountsTests
var id = JsonConvert.SerializeObject(Identity.Empty, Identity.GetJsonSerializerSettings()); var id = JsonConvert.SerializeObject(Identity.Empty, Identity.GetJsonSerializerSettings());
var jsonIn = $@" var jsonIn = $@"
{{ {{
""AccountsSettings"": [ ""Accounts"": [
{{ {{
""AccountId"": ""cng"", ""AccountId"": ""cng"",
""AccountName"": ""my main login"", ""AccountName"": ""my main login"",
@ -106,12 +106,12 @@ namespace AccountsTests
] ]
}} }}
".Trim(); ".Trim();
var accounts = Accounts.FromJson(jsonIn); var accountsSettings = AccountsSettings.FromJson(jsonIn);
var jsonOut = accounts.ToJson(); var jsonOut = accountsSettings.ToJson();
jsonOut.Should().Be(@" jsonOut.Should().Be(@"
{ {
""AccountsSettings"": [ ""Accounts"": [
{ {
""AccountId"": ""cng"", ""AccountId"": ""cng"",
""AccountName"": ""my main login"", ""AccountName"": ""my main login"",
@ -162,12 +162,12 @@ namespace AccountsTests
public void create_file() public void create_file()
{ {
File.Exists(TestFile).Should().BeFalse(); File.Exists(TestFile).Should().BeFalse();
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
_ = new AccountsPersister(accounts, TestFile); _ = new AccountsSettingsPersister(accountsSettings, TestFile);
File.Exists(TestFile).Should().BeTrue(); File.Exists(TestFile).Should().BeTrue();
File.ReadAllText(TestFile).Should().Be(@" File.ReadAllText(TestFile).Should().Be(@"
{ {
""AccountsSettings"": [] ""Accounts"": []
} }
".Trim()); ".Trim());
} }
@ -179,12 +179,12 @@ namespace AccountsTests
WriteToTestFile("foo"); WriteToTestFile("foo");
File.Exists(TestFile).Should().BeTrue(); File.Exists(TestFile).Should().BeTrue();
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
_ = new AccountsPersister(accounts, TestFile); _ = new AccountsSettingsPersister(accountsSettings, TestFile);
File.Exists(TestFile).Should().BeTrue(); File.Exists(TestFile).Should().BeTrue();
File.ReadAllText(TestFile).Should().Be(@" File.ReadAllText(TestFile).Should().Be(@"
{ {
""AccountsSettings"": [] ""Accounts"": []
} }
".Trim()); ".Trim());
} }
@ -192,16 +192,16 @@ namespace AccountsTests
[TestMethod] [TestMethod]
public void save_multiple_children() public void save_multiple_children()
{ {
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
accounts.Add(new Account("a0") { AccountName = "n0" }); accountsSettings.Add(new Account("a0") { AccountName = "n0" });
accounts.Add(new Account("a1") { AccountName = "n1" }); accountsSettings.Add(new Account("a1") { AccountName = "n1" });
// dispose to cease auto-updates // dispose to cease auto-updates
using (var p = new AccountsPersister(accounts, TestFile)) { } using (var p = new AccountsSettingsPersister(accountsSettings, TestFile)) { }
var persister = new AccountsPersister(TestFile); var persister = new AccountsSettingsPersister(TestFile);
persister.Accounts.AccountsSettings.Count.Should().Be(2); persister.AccountsSettings.Accounts.Count.Should().Be(2);
persister.Accounts.AccountsSettings[1].AccountName.Should().Be("n1"); persister.AccountsSettings.Accounts[1].AccountName.Should().Be("n1");
} }
[TestMethod] [TestMethod]
@ -210,14 +210,14 @@ namespace AccountsTests
var id = new Identity(usLocale); var id = new Identity(usLocale);
var idJson = JsonConvert.SerializeObject(id, Identity.GetJsonSerializerSettings()); var idJson = JsonConvert.SerializeObject(id, Identity.GetJsonSerializerSettings());
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
accounts.Add(new Account("a0") { AccountName = "n0", IdentityTokens = id }); accountsSettings.Add(new Account("a0") { AccountName = "n0", IdentityTokens = id });
// dispose to cease auto-updates // dispose to cease auto-updates
using (var p = new AccountsPersister(accounts, TestFile)) { } using (var p = new AccountsSettingsPersister(accountsSettings, TestFile)) { }
var persister = new AccountsPersister(TestFile); var persister = new AccountsSettingsPersister(TestFile);
var acct = persister.Accounts.AccountsSettings[0]; var acct = persister.AccountsSettings.Accounts[0];
acct.AccountName.Should().Be("n0"); acct.AccountName.Should().Be("n0");
acct.Locale.CountryCode.Should().Be("us"); acct.Locale.CountryCode.Should().Be("us");
} }
@ -231,22 +231,22 @@ namespace AccountsTests
public void save_1_account() public void save_1_account()
{ {
// create initial file // create initial file
using (var p = new AccountsPersister(new Accounts(), TestFile)) { } using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { }
// load file. create account // load file. create account
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var idIn = new Identity(usLocale); var idIn = new Identity(usLocale);
var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn }; var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn };
p.Accounts.Add(acctIn); p.AccountsSettings.Add(acctIn);
} }
// re-load file. ensure account still exists // re-load file. ensure account still exists
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
p.Accounts.AccountsSettings.Count.Should().Be(1); p.AccountsSettings.Accounts.Count.Should().Be(1);
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.AccountsSettings.Accounts[0];
acct0.AccountName.Should().Be("n0"); acct0.AccountName.Should().Be("n0");
acct0.Locale.CountryCode.Should().Be("us"); acct0.Locale.CountryCode.Should().Be("us");
} }
@ -258,46 +258,46 @@ namespace AccountsTests
public void save_2_accounts() public void save_2_accounts()
{ {
// create initial file // create initial file
using (var p = new AccountsPersister(new Accounts(), TestFile)) { } using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { }
// load file. create account 0 // load file. create account 0
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var idIn = new Identity(usLocale); var idIn = new Identity(usLocale);
var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn }; var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn };
p.Accounts.Add(acctIn); p.AccountsSettings.Add(acctIn);
} }
// re-load file. ensure account still exists // re-load file. ensure account still exists
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
p.Accounts.AccountsSettings.Count.Should().Be(1); p.AccountsSettings.Accounts.Count.Should().Be(1);
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.AccountsSettings.Accounts[0];
acct0.AccountName.Should().Be("n0"); acct0.AccountName.Should().Be("n0");
acct0.Locale.CountryCode.Should().Be("us"); acct0.Locale.CountryCode.Should().Be("us");
} }
// load file. create account 1 // load file. create account 1
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var idIn = new Identity(ukLocale); var idIn = new Identity(ukLocale);
var acctIn = new Account("a1") { AccountName = "n1", IdentityTokens = idIn }; var acctIn = new Account("a1") { AccountName = "n1", IdentityTokens = idIn };
p.Accounts.Add(acctIn); p.AccountsSettings.Add(acctIn);
} }
// re-load file. ensure both accounts still exist // re-load file. ensure both accounts still exist
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
p.Accounts.AccountsSettings.Count.Should().Be(2); p.AccountsSettings.Accounts.Count.Should().Be(2);
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.AccountsSettings.Accounts[0];
acct0.AccountName.Should().Be("n0"); acct0.AccountName.Should().Be("n0");
acct0.Locale.CountryCode.Should().Be("us"); acct0.Locale.CountryCode.Should().Be("us");
var acct1 = p.Accounts.AccountsSettings[1]; var acct1 = p.AccountsSettings.Accounts[1];
acct1.AccountName.Should().Be("n1"); acct1.AccountName.Should().Be("n1");
acct1.Locale.CountryCode.Should().Be("uk"); acct1.Locale.CountryCode.Should().Be("uk");
} }
@ -307,23 +307,23 @@ namespace AccountsTests
public void update_Account_field_just_added() public void update_Account_field_just_added()
{ {
// create initial file // create initial file
using (var p = new AccountsPersister(new Accounts(), TestFile)) { } using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { }
// load file. create 2 accounts // load file. create 2 accounts
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var id1 = new Identity(usLocale); var id1 = new Identity(usLocale);
var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 };
p.Accounts.Add(acct1); p.AccountsSettings.Add(acct1);
// update just-added item. note: this is different than the subscription which happens on initial collection load. ensure this works also // update just-added item. note: this is different than the subscription which happens on initial collection load. ensure this works also
acct1.AccountName = "new"; acct1.AccountName = "new";
} }
// verify save property // verify save property
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.AccountsSettings.Accounts[0];
acct0.AccountName.Should().Be("new"); acct0.AccountName.Should().Be("new");
} }
} }
@ -333,40 +333,40 @@ namespace AccountsTests
public void update_Account_field() public void update_Account_field()
{ {
// create initial file // create initial file
using (var p = new AccountsPersister(new Accounts(), TestFile)) { } using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { }
// load file. create 2 accounts // load file. create 2 accounts
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var id1 = new Identity(usLocale); var id1 = new Identity(usLocale);
var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 };
p.Accounts.Add(acct1); p.AccountsSettings.Add(acct1);
var id2 = new Identity(ukLocale); var id2 = new Identity(ukLocale);
var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 }; var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 };
p.Accounts.Add(acct2); p.AccountsSettings.Add(acct2);
} }
// update AccountName on existing file // update AccountName on existing file
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.AccountsSettings.Accounts[0];
acct0.AccountName = "new"; acct0.AccountName = "new";
} }
// re-load file. ensure both accounts still exist // re-load file. ensure both accounts still exist
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
p.Accounts.AccountsSettings.Count.Should().Be(2); p.AccountsSettings.Accounts.Count.Should().Be(2);
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.AccountsSettings.Accounts[0];
// new // new
acct0.AccountName.Should().Be("new"); acct0.AccountName.Should().Be("new");
// still here // still here
acct0.Locale.CountryCode.Should().Be("us"); acct0.Locale.CountryCode.Should().Be("us");
var acct1 = p.Accounts.AccountsSettings[1]; var acct1 = p.AccountsSettings.Accounts[1];
acct1.AccountName.Should().Be("n1"); acct1.AccountName.Should().Be("n1");
acct1.Locale.CountryCode.Should().Be("uk"); acct1.Locale.CountryCode.Should().Be("uk");
} }
@ -377,42 +377,42 @@ namespace AccountsTests
public void replace_identity() public void replace_identity()
{ {
// create initial file // create initial file
using (var p = new AccountsPersister(new Accounts(), TestFile)) { } using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { }
// load file. create 2 accounts // load file. create 2 accounts
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var id1 = new Identity(usLocale); var id1 = new Identity(usLocale);
var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 };
p.Accounts.Add(acct1); p.AccountsSettings.Add(acct1);
var id2 = new Identity(ukLocale); var id2 = new Identity(ukLocale);
var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 }; var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 };
p.Accounts.Add(acct2); p.AccountsSettings.Add(acct2);
} }
// update identity on existing file // update identity on existing file
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var id = new Identity(ukLocale); var id = new Identity(ukLocale);
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.AccountsSettings.Accounts[0];
acct0.IdentityTokens = id; acct0.IdentityTokens = id;
} }
// re-load file. ensure both accounts still exist // re-load file. ensure both accounts still exist
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
p.Accounts.AccountsSettings.Count.Should().Be(2); p.AccountsSettings.Accounts.Count.Should().Be(2);
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.AccountsSettings.Accounts[0];
// new // new
acct0.Locale.CountryCode.Should().Be("uk"); acct0.Locale.CountryCode.Should().Be("uk");
// still here // still here
acct0.AccountName.Should().Be("n0"); acct0.AccountName.Should().Be("n0");
var acct1 = p.Accounts.AccountsSettings[1]; var acct1 = p.AccountsSettings.Accounts[1];
acct1.AccountName.Should().Be("n1"); acct1.AccountName.Should().Be("n1");
acct1.Locale.CountryCode.Should().Be("uk"); acct1.Locale.CountryCode.Should().Be("uk");
} }
@ -424,42 +424,42 @@ namespace AccountsTests
public void update_identity_field() public void update_identity_field()
{ {
// create initial file // create initial file
using (var p = new AccountsPersister(new Accounts(), TestFile)) { } using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { }
// load file. create 2 accounts // load file. create 2 accounts
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
var id1 = new Identity(usLocale); var id1 = new Identity(usLocale);
var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 };
p.Accounts.Add(acct1); p.AccountsSettings.Add(acct1);
var id2 = new Identity(ukLocale); var id2 = new Identity(ukLocale);
var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 }; var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 };
p.Accounts.Add(acct2); p.AccountsSettings.Add(acct2);
} }
// update identity on existing file // update identity on existing file
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
p.Accounts.AccountsSettings[0] p.AccountsSettings.Accounts[0]
.IdentityTokens .IdentityTokens
.Update(new AccessToken("Atna|_NEW_", DateTime.Now.AddDays(1))); .Update(new AccessToken("Atna|_NEW_", DateTime.Now.AddDays(1)));
} }
// re-load file. ensure both accounts still exist // re-load file. ensure both accounts still exist
using (var p = new AccountsPersister(TestFile)) using (var p = new AccountsSettingsPersister(TestFile))
{ {
p.Accounts.AccountsSettings.Count.Should().Be(2); p.AccountsSettings.Accounts.Count.Should().Be(2);
var acct0 = p.Accounts.AccountsSettings[0]; var acct0 = p.AccountsSettings.Accounts[0];
// new // new
acct0.IdentityTokens.ExistingAccessToken.TokenValue.Should().Be("Atna|_NEW_"); acct0.IdentityTokens.ExistingAccessToken.TokenValue.Should().Be("Atna|_NEW_");
// still here // still here
acct0.AccountName.Should().Be("n0"); acct0.AccountName.Should().Be("n0");
acct0.Locale.CountryCode.Should().Be("us"); acct0.Locale.CountryCode.Should().Be("us");
var acct1 = p.Accounts.AccountsSettings[1]; var acct1 = p.AccountsSettings.Accounts[1];
acct1.AccountName.Should().Be("n1"); acct1.AccountName.Should().Be("n1");
acct1.Locale.CountryCode.Should().Be("uk"); acct1.Locale.CountryCode.Should().Be("uk");
} }
@ -478,11 +478,11 @@ namespace AccountsTests
var idUk = new Identity(ukLocale); var idUk = new Identity(ukLocale);
var acct2 = new Account("cng") { IdentityTokens = idUk, AccountName = "bar" }; var acct2 = new Account("cng") { IdentityTokens = idUk, AccountName = "bar" };
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
accounts.Add(acct1); accountsSettings.Add(acct1);
accounts.Add(acct2); accountsSettings.Add(acct2);
accounts.GetAccount("cng", "uk").AccountName.Should().Be("bar"); accountsSettings.GetAccount("cng", "uk").AccountName.Should().Be("bar");
} }
} }
@ -492,23 +492,23 @@ namespace AccountsTests
[TestMethod] [TestMethod]
public void upsert_new() public void upsert_new()
{ {
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
accounts.AccountsSettings.Count.Should().Be(0); accountsSettings.Accounts.Count.Should().Be(0);
accounts.Upsert("cng", "us"); accountsSettings.Upsert("cng", "us");
accounts.AccountsSettings.Count.Should().Be(1); accountsSettings.Accounts.Count.Should().Be(1);
accounts.GetAccount("cng", "us").AccountId.Should().Be("cng"); accountsSettings.GetAccount("cng", "us").AccountId.Should().Be("cng");
} }
[TestMethod] [TestMethod]
public void upsert_exists() public void upsert_exists()
{ {
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
var orig = accounts.Upsert("cng", "us"); var orig = accountsSettings.Upsert("cng", "us");
orig.AccountName = "foo"; orig.AccountName = "foo";
var exists = accounts.Upsert("cng", "us"); var exists = accountsSettings.Upsert("cng", "us");
exists.AccountName.Should().Be("foo"); exists.AccountName.Should().Be("foo");
orig.Should().IsSameOrEqualTo(exists); orig.Should().IsSameOrEqualTo(exists);
@ -521,28 +521,28 @@ namespace AccountsTests
[TestMethod] [TestMethod]
public void delete_account() public void delete_account()
{ {
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
var acct = accounts.Upsert("cng", "us"); var acct = accountsSettings.Upsert("cng", "us");
accounts.AccountsSettings.Count.Should().Be(1); accountsSettings.Accounts.Count.Should().Be(1);
var removed = accounts.Delete(acct); var removed = accountsSettings.Delete(acct);
removed.Should().BeTrue(); removed.Should().BeTrue();
accounts.AccountsSettings.Count.Should().Be(0); accountsSettings.Accounts.Count.Should().Be(0);
} }
[TestMethod] [TestMethod]
public void delete_where() public void delete_where()
{ {
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
var acct = accounts.Upsert("cng", "us"); _ = accountsSettings.Upsert("cng", "us");
accounts.AccountsSettings.Count.Should().Be(1); accountsSettings.Accounts.Count.Should().Be(1);
accounts.Delete("baz", "baz").Should().BeFalse(); accountsSettings.Delete("baz", "baz").Should().BeFalse();
accounts.AccountsSettings.Count.Should().Be(1); accountsSettings.Accounts.Count.Should().Be(1);
accounts.Delete("cng", "us").Should().BeTrue(); accountsSettings.Delete("cng", "us").Should().BeTrue();
accounts.AccountsSettings.Count.Should().Be(0); accountsSettings.Accounts.Count.Should().Be(0);
} }
[TestMethod] [TestMethod]
@ -550,26 +550,26 @@ namespace AccountsTests
{ {
Account acct; Account acct;
using (var p = new AccountsPersister(new Accounts(), TestFile)) using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile))
{ {
acct = p.Accounts.Upsert("foo", "us"); acct = p.AccountsSettings.Upsert("foo", "us");
p.Accounts.AccountsSettings.Count.Should().Be(1); p.AccountsSettings.Accounts.Count.Should().Be(1);
acct.AccountName = "old"; acct.AccountName = "old";
} }
using (var p = new AccountsPersister(new Accounts(), TestFile)) using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile))
{ {
p.Accounts.Delete(acct); p.AccountsSettings.Delete(acct);
p.Accounts.AccountsSettings.Count.Should().Be(0); p.AccountsSettings.Accounts.Count.Should().Be(0);
} }
using (var p = new AccountsPersister(new Accounts(), TestFile)) using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile))
{ {
File.ReadAllText(TestFile).Should().Be("{\r\n \"AccountsSettings\": []\r\n}".Trim()); File.ReadAllText(TestFile).Should().Be("{\r\n \"Accounts\": []\r\n}".Trim());
acct.AccountName = "new"; acct.AccountName = "new";
File.ReadAllText(TestFile).Should().Be("{\r\n \"AccountsSettings\": []\r\n}".Trim()); File.ReadAllText(TestFile).Should().Be("{\r\n \"Accounts\": []\r\n}".Trim());
} }
} }
} }
@ -581,31 +581,31 @@ namespace AccountsTests
[TestMethod] [TestMethod]
public void violate_validation() public void violate_validation()
{ {
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
var idIn = new Identity(usLocale); var idIn = new Identity(usLocale);
var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn }; var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn };
accounts.Add(a1); accountsSettings.Add(a1);
var a2 = new Account("a") { AccountName = "two", IdentityTokens = idIn }; var a2 = new Account("a") { AccountName = "two", IdentityTokens = idIn };
// violation: validate() // violation: validate()
Assert.ThrowsException<InvalidOperationException>(() => accounts.Add(a2)); Assert.ThrowsException<InvalidOperationException>(() => accountsSettings.Add(a2));
} }
[TestMethod] [TestMethod]
public void identity_violate_validation() public void identity_violate_validation()
{ {
var accounts = new Accounts(); var accountsSettings = new AccountsSettings();
var idIn = new Identity(usLocale); var idIn = new Identity(usLocale);
var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn }; var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn };
accounts.Add(a1); accountsSettings.Add(a1);
var a2 = new Account("a") { AccountName = "two" }; var a2 = new Account("a") { AccountName = "two" };
accounts.Add(a2); accountsSettings.Add(a2);
// violation: GetAccount.SingleOrDefault // violation: GetAccount.SingleOrDefault
Assert.ThrowsException<InvalidOperationException>(() => a2.IdentityTokens = idIn); Assert.ThrowsException<InvalidOperationException>(() => a2.IdentityTokens = idIn);