public void AccountName_is_blank_if_Account_property_is_not_set_on_transaction()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            Assert.AreEqual("", vm.AccountName);
        }
        public void AccountBackgroundColour_is_pink_when_AccountName_is_invalid()
        {
            var transaction = new Transaction(_journal, TransactionDirection.Out, null, 123.45M);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            var pink = new SolidColorBrush(Colors.Pink);
            Assert.AreEqual(pink.ToString(), vm.AccountBackgroundColour.ToString());
        }
        public void AccountBackgroundColour_is_white_when_AccountName_is_valid()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In, _account);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            var white = new SolidColorBrush(Colors.White);
            Assert.AreEqual(white.ToString(), vm.AccountBackgroundColour.ToString());
        }
        public void AccountNames_retrurns_all_names_from_account_repository()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In, _account);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            var account1 = new Account(0, "Account Name 1", AccountType.Asset);
            var account2 = new Account(0, "Account Name 2", AccountType.Liability);

            var accounts = new Account[2];
            accounts[0] = account1;
            accounts[1] = account2;

            Expect.Once.On(_mockAccountRepository).Method("GetAll").Will(Return.Value(accounts));

            var accountNames = vm.AccountNames;

            Assert.AreEqual(2, accountNames.Count());
            Assert.AreEqual(account1.Name, accountNames[0]);
            Assert.AreEqual(account2.Name, accountNames[1]);

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
 public void ToggleDirectionText_is_lt_when_TransactionDirection_is_In()
 {
     var transaction = new Transaction(_journal, TransactionDirection.In);
     var vm = new TransactionViewModel(transaction, _mockAccountRepository);
     Assert.AreEqual("In", vm.ToggleDirectionText);
 }
        public void ToggleDirectionCommand_toggles_transaction_direction(TransactionDirection initialDirection, TransactionDirection toggledDirection)
        {
            var transaction = new Transaction(_journal, initialDirection);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            bool hasTransactionModifiedBeenCalled = false;
            vm.TransactionModified += (o, e) => { hasTransactionModifiedBeenCalled = true; };

            vm.ToggleDirectionCommand.Execute(null);
            Assert.AreEqual(toggledDirection, transaction.Direction);

            Assert.AreEqual(7, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(7, _changeCounter.TotalChangeCount);
            Assert.AreEqual(1, _changeCounter.ChangeCount("ToggleDirectionText"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("AmountIn"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("AmountOut"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("IsAmountInEnabled"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("IsAmountOutEnabled"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("AmountInBackgroundColour"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("AmountOutBackgroundColour"));

            Assert.IsTrue(hasTransactionModifiedBeenCalled);
        }
        public void setting_note_to_the_same_value_does_not_cause_update()
        {
            var transaction = new Transaction(_journal, TransactionDirection.Out, amount: 1234.56M, note: "George Foreman Grill");
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.TransactionNote = "George Foreman Grill";

            Assert.AreEqual("George Foreman Grill", vm.TransactionNote);
            Assert.AreEqual("George Foreman Grill", transaction.Note);

            Assert.AreEqual(0, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(0, _changeCounter.TotalChangeCount);
        }
        public void AmountInBackgroundColour_is_pink_when_AmountIn_is_invalid()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In, _account);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            var white = new SolidColorBrush(Colors.White);
            var pink = new SolidColorBrush(Colors.Pink);
            Assert.AreEqual(pink.ToString(), vm.AmountInBackgroundColour.ToString());
            Assert.AreEqual(white.ToString(), vm.AmountOutBackgroundColour.ToString());
        }
Ejemplo n.º 9
0
        private void RefreshAccountViewModels()
        {
            var allTransactions = new Collection<TransactionViewModel>();
            foreach (var transaction in _account.Transactions.OrderBy(x => x.Journal.Date))
            {
                Transaction transaction1 = transaction;
                var tranViewModel = _allTransactions.SingleOrDefault(x => x.Transaction == transaction1);

                if (tranViewModel == null)
                {
                    tranViewModel = new TransactionViewModel(transaction, _accountRepository, _mainWindow);
                    tranViewModel.TransactionModified += RefreshTransactionVisibility;
                }

                allTransactions.Add(tranViewModel);
            }
            _allTransactions.Clear();
            _allTransactions = allTransactions.OrderBy(x => x.JournalDate).ToList();

            RebuildVisibleTransactionList();
        }
        public void Amount_properties_format_values_just_the_way_I_want_them_to()
        {
            var transaction1 = new Transaction(_journal, TransactionDirection.Out, _account, 12345.67899M, "100EUR");
            var transaction2 = new Transaction(_journal, TransactionDirection.In, _account, 0.095M, "100EUR");
            var vm1 = new TransactionViewModel(transaction1, _mockAccountRepository);
            var vm2 = new TransactionViewModel(transaction2, _mockAccountRepository);

            Assert.AreEqual("12,345.67899", vm1.AmountOut);
            Assert.AreEqual("0.095", vm2.AmountIn);
        }
        public void TransactionModified_is_called_if_AmountOut_is_changed()
        {
            var transaction = new Transaction(_journal, TransactionDirection.Out);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            bool hasTransactionModifiedBeenCalled = false;
            vm.TransactionModified += (o, e) => { hasTransactionModifiedBeenCalled = true; };

            vm.AmountOut = "1234.56";
            Assert.IsTrue(hasTransactionModifiedBeenCalled);
        }
        public void IsAmountOutEnabled_is_true_and_IsAmountInEnabled_is_false_when_transaction_is_Out_direction()
        {
            var transaction = new Transaction(_journal, TransactionDirection.Out, amount: 1234.56M);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            Assert.IsTrue(vm.IsAmountOutEnabled);
            Assert.IsFalse(vm.IsAmountInEnabled);
        }
        public void can_set_note_on_the_transation()
        {
            var transaction = new Transaction(_journal, TransactionDirection.Out, amount: 1234.56M, note:"George Foreman Grill");
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.TransactionNote = "George Foreman Deluxe Grille";

            Assert.AreEqual("George Foreman Deluxe Grille", vm.TransactionNote);
            Assert.AreEqual("George Foreman Deluxe Grille", transaction.Note);

            Assert.AreEqual(1, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(1, _changeCounter.TotalChangeCount);
            Assert.AreEqual(1, _changeCounter.ChangeCount("TransactionNote"));
        }
        public void can_set_amountIn()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.AmountIn = "1,234.56";
            Assert.AreEqual("1,234.56", vm.AmountIn);
            Assert.AreEqual(1234.56M, transaction.Amount);
            Assert.AreEqual(2, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(2, _changeCounter.TotalChangeCount);
            Assert.AreEqual(1, _changeCounter.ChangeCount("AmountIn"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("AmountInBackgroundColour"));
        }
        public void can_create_new_TransactionViewModel()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In, _account, 123.45M, "100EUR");
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            Assert.AreEqual("HSBC Current", vm.AccountName);
            Assert.AreEqual("100EUR", vm.TransactionNote);
            Assert.AreEqual("", vm.AmountOut);
            Assert.AreEqual("123.45", vm.AmountIn);

            Assert.IsTrue(vm.TransactionValid);
        }
        public void cannot_set_amountOut_on_transaction_with_in_TransactionDirection()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In, amount: 0.99M);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.AmountOut = "1234.56";
            Assert.AreEqual(0.99M, transaction.Amount);
            Assert.AreEqual(2, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(2, _changeCounter.TotalChangeCount);
        }
        public void TransactionModified_is_called_if_Account_is_changed()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            bool hasTransactionModifiedBeenCalled = false;
            vm.TransactionModified += (o, e) => { hasTransactionModifiedBeenCalled = true; };

            Expect.Once.On(_mockAccountRepository).Method("GetByName").With("HSBC Current").Will(Return.Value(_account));

            vm.AccountName = "HSBC Current";
            Assert.IsTrue(hasTransactionModifiedBeenCalled);
        }
        public void when_AccountName_is_set_to_the_same_name_nothing_happens()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In, _account);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            bool hasTransactionModifiedBeenCalled = false;
            vm.TransactionModified += (o, e) => { hasTransactionModifiedBeenCalled = true; };

            vm.AccountName = "HSBC Current";
            Assert.IsFalse(hasTransactionModifiedBeenCalled);

            Assert.AreEqual(0, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(0, _changeCounter.TotalChangeCount);

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void AmountOutBackgroundColour_is_white_when_AmountOut_is_valid()
        {
            var transaction = new Transaction(_journal, TransactionDirection.Out, null, 123.45M);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);

            var white = new SolidColorBrush(Colors.White);
            Assert.AreEqual(white.ToString(), vm.AmountOutBackgroundColour.ToString());
            Assert.AreEqual(white.ToString(), vm.AmountInBackgroundColour.ToString());
        }
        public void when_AccountName_is_set_to_an_nonexistent_account_name_no_change_is_made()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In, _account);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            bool hasTransactionModifiedBeenCalled = false;
            vm.TransactionModified += (o, e) => { hasTransactionModifiedBeenCalled = true; };

            Expect.Once.On(_mockAccountRepository).Method("GetByName").With("Nonexistent Account").Will(Return.Value(null));

            vm.AccountName = "Nonexistent Account";
            Assert.AreEqual("", vm.AccountName);
            Assert.AreEqual(null, transaction.Account);
            Assert.IsTrue(hasTransactionModifiedBeenCalled);

            Assert.AreEqual(2, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(2, _changeCounter.TotalChangeCount);
            Assert.AreEqual(1, _changeCounter.ChangeCount("AccountName"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("AccountBackgroundColour"));

            _mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void setting_amountOut_on_transaction_with_in_TransactionDirection_has_no_affect()
        {
            var transaction = new Transaction(_journal, TransactionDirection.In);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.AmountOut = "1234.56";
            vm.AmountIn = "543.21";

            Assert.AreEqual("", vm.AmountOut);
            Assert.AreEqual("543.21", vm.AmountIn);
            Assert.AreEqual(4, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(4, _changeCounter.TotalChangeCount);
        }
        public void setting_amountOut_to_the_same_value_does_not_cause_update()
        {
            var transaction = new Transaction(_journal, TransactionDirection.Out, amount: 1234.56M);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.AmountOut = "1,234.56";
            Assert.AreEqual("1,234.56", vm.AmountOut);
            Assert.AreEqual(1234.56M, transaction.Amount);
            Assert.AreEqual(0, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(0, _changeCounter.TotalChangeCount);
        }
        public void setting_an_invalid_AmountOut_makes_amount_zero()
        {
            var transaction = new Transaction(_journal, TransactionDirection.Out, amount:1234.56M);
            var vm = new TransactionViewModel(transaction, _mockAccountRepository);
            vm.PropertyChanged += _changeCounter.HandlePropertyChange;

            vm.AmountOut = "invalid";
            Assert.AreEqual("1,234.56", vm.AmountOut);
            Assert.AreEqual(1234.56M, transaction.Amount);
            Assert.AreEqual(2, _changeCounter.NoOfPropertiesChanged);
            Assert.AreEqual(2, _changeCounter.TotalChangeCount);
            Assert.AreEqual(1, _changeCounter.ChangeCount("AmountOut"));
            Assert.AreEqual(1, _changeCounter.ChangeCount("AmountOutBackgroundColour"));
        }
Ejemplo n.º 24
0
        private bool TransactionShouldBeVisisble(TransactionViewModel transaction)
        {
            if (transaction.JournalDate < FromDate) return false;
            if (transaction.JournalDate > ToDate) return false;
            if (transaction.Transaction.IsVerified && !_showVerified) return false;
            if (!transaction.Transaction.IsVerified && !_showUnVerified) return false;
            if (transaction.Transaction.Direction == TransactionDirection.In && !_showIn) return false;
            if (transaction.Transaction.Direction == TransactionDirection.Out && !_showOut) return false;

            return true;
        }
Ejemplo n.º 25
0
        private void AddTransactionToInternalCollection(Transaction transaction)
        {
            var tranViewModel = new TransactionViewModel(transaction, _accountRepository);

            tranViewModel.RequestDelete += DeleteTransaction;
            tranViewModel.TransactionModified += RefreshJournalValidity;
            _transactions.Add(tranViewModel);
            base.OnPropertyChanged("DeleteJournalVisibility");
        }