コード例 #1
0
ファイル: AccountTests.cs プロジェクト: tanitall/Libation
        public void upsert_exists()
        {
            var accountsSettings = new AccountsSettings();
            var orig             = accountsSettings.Upsert("cng", "us");

            orig.AccountName = "foo";

            var exists = accountsSettings.Upsert("cng", "us");

            exists.AccountName.Should().Be("foo");

            orig.Should().IsSameOrEqualTo(exists);
        }
コード例 #2
0
ファイル: AccountsDialog.cs プロジェクト: rmcrackan/Libation
        private void persist(AccountsSettings accountsSettings)
        {
            var existingAccounts = accountsSettings.Accounts;
            var dtos             = getRowDtos();

            // editing account id is a special case. an account is defined by its account id, therefore this is really a different account. the user won't care about this distinction though.
            // these will be caught below by normal means and re-created minus the convenience of persisting identity tokens

            // delete
            for (var i = existingAccounts.Count - 1; i >= 0; i--)
            {
                var existing = existingAccounts[i];
                if (!dtos.Any(dto =>
                              dto.AccountId?.ToLower().Trim() == existing.AccountId.ToLower() &&
                              dto.LocaleName == existing.Locale?.Name))
                {
                    accountsSettings.Delete(existing);
                }
            }

            // upsert each. validation occurs through Account and AccountsSettings
            foreach (var dto in dtos)
            {
                var acct = accountsSettings.Upsert(dto.AccountId, dto.LocaleName);
                acct.LibraryScan = dto.LibraryScan;
                acct.AccountName
                    = string.IsNullOrWhiteSpace(dto.AccountName)
                                        ? $"{dto.AccountId} - {dto.LocaleName}"
                                        : dto.AccountName.Trim();
            }
        }
コード例 #3
0
ファイル: AccountTests.cs プロジェクト: tanitall/Libation
        public void delete_updates()
        {
            var i = 0;

            void update(object sender, EventArgs e) => i++;

            var accountsSettings = new AccountsSettings();

            accountsSettings.Updated += update;

            accountsSettings.Accounts.Count.Should().Be(0);
            i.Should().Be(0);

            _ = accountsSettings.Upsert("cng", "us");
            accountsSettings.Accounts.Count.Should().Be(1);
            i.Should().Be(1);

            accountsSettings.Delete("baz", "baz").Should().BeFalse();
            accountsSettings.Accounts.Count.Should().Be(1);
            i.Should().Be(1);

            accountsSettings.Delete("cng", "us").Should().BeTrue();
            accountsSettings.Accounts.Count.Should().Be(0);
            i.Should().Be(2); // <== this is the one being tested
        }
コード例 #4
0
ファイル: AccountTests.cs プロジェクト: tanitall/Libation
        public void upsert_new()
        {
            var accountsSettings = new AccountsSettings();

            accountsSettings.Accounts.Count.Should().Be(0);

            accountsSettings.Upsert("cng", "us");

            accountsSettings.Accounts.Count.Should().Be(1);
            accountsSettings.GetAccount("cng", "us").AccountId.Should().Be("cng");
        }
コード例 #5
0
ファイル: AccountTests.cs プロジェクト: tanitall/Libation
        public void delete_where()
        {
            var accountsSettings = new AccountsSettings();

            _ = accountsSettings.Upsert("cng", "us");
            accountsSettings.Accounts.Count.Should().Be(1);

            accountsSettings.Delete("baz", "baz").Should().BeFalse();
            accountsSettings.Accounts.Count.Should().Be(1);

            accountsSettings.Delete("cng", "us").Should().BeTrue();
            accountsSettings.Accounts.Count.Should().Be(0);
        }
コード例 #6
0
ファイル: AccountTests.cs プロジェクト: tanitall/Libation
        public void delete_account()
        {
            var accountsSettings = new AccountsSettings();
            var acct             = accountsSettings.Upsert("cng", "us");

            accountsSettings.Accounts.Count.Should().Be(1);

            var removed = accountsSettings.Delete(acct);

            removed.Should().BeTrue();

            accountsSettings.Accounts.Count.Should().Be(0);
        }