Пример #1
0
        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
        }
Пример #2
0
        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);
        }
Пример #3
0
        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();
            }
        }
Пример #4
0
        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);
        }