Ejemplo n.º 1
0
        public void AccountId_property_returns_accounts_id()
        {
            var account = new Account(122, "Halifax", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            Assert.AreEqual(122, vm.AccountId);
        }
Ejemplo n.º 2
0
        public void AccountTags_property_is_empty_if_the_Account_has_no_tags()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            ICollection<AccountTagViewModel> tagVMs = vm.AccountTags;

            Assert.AreEqual(0, tagVMs.Count);
        }
        private void AddAccountToInternalCollection(Account account, bool newAccount = false, bool addToEnd = true)
        {
            var accountVM = new AccountViewModel(account, _accountRepository, _accountTagRepository);
            accountVM.RequestDelete += DeleteAccount;

            if (addToEnd)
                _accounts.Add(accountVM);
            else
                _accounts.Insert(0, accountVM);

            if (newAccount) accountVM.AccountName = "New Account";
        }
Ejemplo n.º 4
0
        public void AccountTags_property_returns_a_collection_of_AccountsTagViewModels_belonging_to_the_account()
        {
            var tag1 = new AccountTag(1, "Entertainment");
            var tag2 = new AccountTag(2, "Food");
            var tag3 = new AccountTag(3, "Services");
            var account = new Account(1, "HSBC current", AccountType.Asset);
            account.AddTag(tag1);
            account.AddTag(tag2);
            account.AddTag(tag3);

            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            ObservableCollection<AccountTagViewModel> tagVMs = vm.AccountTags;
            var tagNames = tagVMs.Select(x => x.TagName).ToList();

            Assert.AreEqual(3, tagVMs.Count);
            Assert.IsTrue(tagNames.Contains("Entertainment"));
            Assert.IsTrue(tagNames.Contains("Food"));
            Assert.IsTrue(tagNames.Contains("Services"));
        }
Ejemplo n.º 5
0
        public void passing_an_object_that_is_not_an_AccountTagViewModel_to_RemoveAccountTag_method_causes_an_exception()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            Assert.Throws<ArgumentException>(() => vm.RemoveAccountTag(account, null));
        }
Ejemplo n.º 6
0
        public void OKButton_Command_calls_Save_method_on_repository_and_updates_accountName()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            Expect.Once.On(_mockAccountRepository).Method("Save").With(account);

            vm.AccountName = "New Name";
            Assert.AreEqual("HSBC current", account.Name);

            vm.OKRenameCommand.Execute(null);

            Assert.AreEqual("New Name", account.Name);
            Assert.AreEqual(3, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(5, _changeCounter.TotalChangeCount);
            Assert.AreEqual(1, _changeCounter.ChangeCount("AccountName"));
            Assert.AreEqual(2, _changeCounter.ChangeCount("EditingName"));
            Assert.AreEqual(2, _changeCounter.ChangeCount("NotEditingName"));

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 7
0
        public void can_change_enabled_status_on_account_using_IsEnabled_property(bool isEnabled)
        {
            var account = new Account(1, "HSBC current", AccountType.Asset) {IsEnabled = !isEnabled};
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            Expect.Once.On(_mockAccountRepository).Method("Save").With(account);
            vm.IsEnabled = isEnabled;

            Assert.AreEqual(2, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(2, _changeCounter.TotalChangeCount);
            Assert.AreEqual(1, _changeCounter.ChangeCount("IsEnabled"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("EnableButtonText"));
            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void setting_the_account_to_the_same_value_does_not_trigger_an_update()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.AccountTypeName = "Asset";

            Assert.AreEqual(0, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(0, _changeCounter.TotalChangeCount);
            Assert.AreEqual(0, _changeCounter.ChangeCount("AccountTypeName"));

            Assert.AreEqual(AccountType.Asset, account.Type);
        }
        public void can_change_account()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository, _mockMainWindowViewModel);

            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            Expect.Once.On(_mockAccountRepository).Method("Save").With(account);
            vm.AccountTypeName = "Expense";

            Assert.AreEqual(1, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(1, _changeCounter.TotalChangeCount);
            Assert.AreEqual(1, _changeCounter.ChangeCount("AccountTypeName"));
            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 10
0
        public void EditingName_property_is_hidden_after_OkRenameCommand()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            Expect.Once.On(_mockAccountRepository).Method("CouldSetAccountName").With(account, "New Name").Will(Return.Value(true));
            Expect.Once.On(_mockAccountRepository).Method("Save").With(account);

            vm.AccountName = "New Name";

            vm.OKRenameCommand.Execute(null);

            Assert.AreEqual(Visibility.Collapsed, vm.EditingName);
            Assert.AreEqual(Visibility.Visible, vm.NotEditingName);
        }
Ejemplo n.º 11
0
        public void changing_AccountName_to_same_name_does_not_cause_update()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;
            vm.AccountName = "HSBC current";

            Assert.AreEqual(0, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(0, _changeCounter.TotalChangeCount);
            Assert.AreEqual(0, _changeCounter.ChangeCount("AccountName"));

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 12
0
        public void changing_AccountName_to_invalid_name_causes_OkCommand_to_be_disabled(string invalidName)
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            Expect.Once.On(_mockAccountRepository).Method("CouldSetAccountName").With(account, invalidName).Will(Return.Value(true));
            vm.AccountName = invalidName;
            Assert.IsFalse(vm.OKRenameCommand.CanExecute(null));
            Assert.AreEqual("Account must have a name", ((IDataErrorInfo)vm)["AccountName"]);

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 13
0
        public void changing_AccountName_to_duplicate_name_causes_OkButton_to_be_disabled()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            Expect.Once.On(_mockAccountRepository).Method("CouldSetAccountName").With(account, "Duplicate Name").Will(Return.Value(false));
            vm.AccountName = "Duplicate Name";

            Assert.IsFalse(vm.OKRenameCommand.CanExecute(null));

            Assert.AreEqual("Account has a duplicate name", ((IDataErrorInfo)vm)["AccountName"]);
            Assert.AreEqual(3, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(4, _changeCounter.TotalChangeCount);
            Assert.AreEqual(2, _changeCounter.ChangeCount("AccountName"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("EditingName"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("NotEditingName"));

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 14
0
        public void can_remove_an_AccountTag_from_an_Account_by_calling_RemoveAccountTag_method()
        {
            var tag1 = new AccountTag(1, "Entertainment");
            var tag2 = new AccountTag(2, "Food");
            var tag3 = new AccountTag(3, "Services");
            var account = new Account(1, "HSBC current", AccountType.Asset);
            account.AddTag(tag1);
            account.AddTag(tag2);
            account.AddTag(tag3);

            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            ObservableCollection<AccountTagViewModel> tagVMs = vm.AccountTags;
            var tagVMToRemove = tagVMs.First(x => x.TagName == "Food");

            Expect.Once.On(_mockAccountRepository).Method("Save").With(account);
            vm.RemoveAccountTag(tagVMToRemove, null);

            var tagIdsInViewModel = tagVMs.Select(x => x.TagId).ToList();

            Assert.AreEqual(2, tagVMs.Count);
            Assert.IsFalse(tagIdsInViewModel.Contains(2));
            Assert.IsTrue(tagIdsInViewModel.Contains(1));
            Assert.IsTrue(tagIdsInViewModel.Contains(3));

            Assert.AreEqual(1, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(1, _changeCounter.TotalChangeCount);
            Assert.AreEqual(1, _changeCounter.ChangeCount("AccountTags"));

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 15
0
        public void can_create_new_AccountViewModel()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);

            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            Assert.AreEqual(1, vm.AccountId);
            Assert.AreEqual("HSBC current", vm.AccountName);
            Assert.AreEqual("Asset", vm.AccountTypeName);
            Assert.IsTrue(vm.IsEnabled);
        }
Ejemplo n.º 16
0
        public void setting_the_enabled_status_to_the_same_value_does_not_trigger_an_update(bool isEnabled)
        {
            var account = new Account(1, "HSBC current", AccountType.Asset) {IsEnabled = isEnabled};
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.IsEnabled = isEnabled;
            Assert.AreEqual(0, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(0, _changeCounter.TotalChangeCount);
            Assert.AreEqual(0, _changeCounter.ChangeCount("IsEnabled"));
            Assert.AreEqual(0, _changeCounter.ChangeCount("EnableButtonText"));

            Assert.AreEqual(isEnabled, account.IsEnabled);
        }
Ejemplo n.º 17
0
        public void calling_OkRenameCommand_CanExecute_causes_a_check_to_see_if_that_is_a_valid_name()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            Expect.Once.On(_mockAccountRepository).Method("CouldSetAccountName").With(account, "HSBC Advance").Will(Return.Value(true));
            vm.AccountName = "HSBC Advance";
            vm.OKRenameCommand.CanExecute(null);

            Assert.AreEqual(null, ((IDataErrorInfo)vm)["AccountName"]);
            Assert.AreEqual(3, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(4, _changeCounter.TotalChangeCount);
            Assert.AreEqual(2, _changeCounter.ChangeCount("AccountName"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("EditingName"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("NotEditingName"));

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 18
0
        public void EditingName_property_is_initially_hidden()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            Assert.AreEqual(Visibility.Collapsed, vm.EditingName);
            Assert.AreEqual(Visibility.Visible, vm.NotEditingName);
        }
        public void CancelButton_Command_deletes_viewmodel_if_account_does_not_exist_in_repository()
        {
            var account = new Account(0, "New Account", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            bool deleteEventRaised = false;
            vm.RequestDelete += (o, a) => deleteEventRaised = true;

            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.AccountName = "New Name";

            vm.CancelRenameCommand.Execute(null);

            Assert.IsTrue(deleteEventRaised);
            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 20
0
        public void EditingName_property_is_visible_when_AccountName_has_been_edited()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            Expect.Once.On(_mockAccountRepository).Method("CouldSetAccountName").With(account, "New Name").Will(Return.Value(true));

            vm.AccountName = "New Name";
            Assert.AreEqual(Visibility.Visible, vm.EditingName);
            Assert.AreEqual(Visibility.Collapsed, vm.NotEditingName);
        }
        public void setting_account_to_an_invalid_value_causes_no_change_to_account()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.AccountTypeName = "Invalid";
            Assert.AreEqual(0, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(0, _changeCounter.TotalChangeCount);
            Assert.AreEqual(0, _changeCounter.ChangeCount("AccountTypeName"));
            Assert.AreEqual(AccountType.Asset, account.Type);
        }
Ejemplo n.º 22
0
        public void EnableButtonText_is_Enable_when_account_is_disabled()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);
            account.IsEnabled = false;

            Assert.AreEqual("Enable", vm.EnableButtonText);
        }
Ejemplo n.º 23
0
        private void SetAccount(Account account)
        {
            SelectedAccount = new AccountViewModel(account, _accountRepository, _accountTagRepository, _mainWindow)
            {
                ShowVerified = ShowVerified,
                ShowUnVerified = ShowUnVerified,
                ShowIn = ShowIn,
                ShowOut = ShowOut,
                FromDate = FromDate,
                ToDate = ToDate
            };

            _accounts.Clear();
            _accounts.Add(SelectedAccount);
        }
Ejemplo n.º 24
0
        public void CancelButton_Command_cancels_edit_and_does_not_call_Save_method_on_repository()
        {
            var account = new Account(1, "HSBC current", AccountType.Asset);
            var vm = new AccountViewModel(account, _mockAccountRepository, _mockAccountTagRepository);

            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.AccountName = "New Name";
            Assert.AreEqual("HSBC current", account.Name);
            Assert.AreEqual("New Name", vm.AccountName);

            vm.CancelRenameCommand.Execute(null);

            Assert.AreEqual("HSBC current", account.Name);
            Assert.AreEqual("HSBC current", vm.AccountName);
            Assert.AreEqual(3, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(6, _changeCounter.TotalChangeCount);
            Assert.AreEqual(2, _changeCounter.ChangeCount("AccountName"));
            Assert.AreEqual(2, _changeCounter.ChangeCount("EditingName"));
            Assert.AreEqual(2, _changeCounter.ChangeCount("NotEditingName"));

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }