示例#1
0
        public void TestDeleteTransaction()
        {
            // Transaction to delete
            var transaction = new Transaction
            {
                Amount = 100,
                CategoryName = "TestCat",
                Description = "TestDesc",
                FiTransactionId = "TRN1"
            };

            // Mock for Entity() call on context
            var mockEntityEntry = new Mock<DbEntityEntry<Transaction>>();
            mockEntityEntry.SetupAllProperties();

            // Mock setup for DataService
            var mockTransactionSet = new Mock<DbSet<Transaction>>();
            var mockContext = new Mock<SoCashDbContext>();
            mockContext.Setup(m => m.Set<Transaction>()).Returns(mockTransactionSet.Object);

            // Delete the transaction
            using (var service = new DataService(mockContext.Object))
                service.DeleteTransaction(transaction);

            // Verify that the service removed the transaction on the mock db exactly once
            mockTransactionSet.Verify(m => m.Remove(transaction), Times.Once());

            // Verify that the transaction ended properly
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
示例#2
0
        /// <summary>
        /// Deletes the transaction currently selected in the datagrid
        /// </summary>
        public void DeleteTransaction()
        {
            using (var dataService = new DataService())
            {
                // Delete the transaction
                dataService.DeleteTransaction(SelectedTransaction);
            }

            // Need to re-sort the data and recalculate balances
            RaisePropertyChanged(() => Transactions);
            RaisePropertyChanged(() => SelectedAccountDailyBalances);
        }