public void Match_ShouldRemoveSingleUseRulesThatWereUsed()
        {
            IEnumerable <Transaction> testTransactions = StatementModelTestData.TestData1().Transactions;
            var testMatchingRules = new List <MatchingRule>
            {
                new SingleUseMatchingRule(this.mockBucketRepo)
                {
                    Amount     = -95.15M,
                    And        = true,
                    BucketCode = StatementModelTestData.PhoneBucket.Code,
                    Reference1 = "skjghjkh",
                    MatchCount = 1 // Artificially set to simulate a match
                },
                new MatchingRule(this.mockBucketRepo)
                {
                    Amount     = -11.11M,
                    BucketCode = StatementModelTestData.CarMtcBucket.Code
                }
            };

            this.mockMatchMaker.Setup(m => m.Match(testTransactions, testMatchingRules)).Returns(true);
            this.mockBucketRepo.GetOrCreateNew(TestDataConstants.PowerBucketCode, () => new SpentMonthlyExpenseBucket(TestDataConstants.PowerBucketCode, "Foo"));
            this.mockBucketRepo.GetOrCreateNew(TestDataConstants.PhoneBucketCode, () => new SpentMonthlyExpenseBucket(TestDataConstants.PhoneBucketCode, "Foo"));
            PrivateAccessor.InvokeMethod(this.subject, "InitialiseTheRulesCollections", testMatchingRules);
            PrivateAccessor.SetField <TransactionRuleService>(this.subject, "rulesStorageKey", "lksjgjklshgjkls");

            var success = this.subject.Match(testTransactions);

            Assert.IsTrue(success);
            Assert.IsFalse(this.subject.MatchingRules.Any(r => r is SingleUseMatchingRule));
        }
        /// <summary>
        ///     Makes sure that the IsNew property on LedgerBook EntryLines is not set to true, as it will be when they are newly
        ///     created.
        ///     Also ensures the StoredInAccount property for each ledger is set.
        /// </summary>
        internal static void Finalise(LedgerBook book, bool unlock = false)
        {
            if (book.Reconciliations.None())
            {
                return;
            }
            var ledgers = new Dictionary <BudgetBucket, LedgerBucket>();

            foreach (LedgerEntryLine line in book.Reconciliations)
            {
                if (!unlock)
                {
                    PrivateAccessor.SetProperty(line, "IsNew", false);
                }
                foreach (LedgerEntry entry in line.Entries)
                {
                    if (!unlock)
                    {
                        PrivateAccessor.SetField(entry, "isNew", false);
                    }
                    if (entry.LedgerBucket.StoredInAccount == null)
                    {
                        entry.LedgerBucket.StoredInAccount = StatementModelTestData.ChequeAccount;
                    }
                    if (!ledgers.ContainsKey(entry.LedgerBucket.BudgetBucket))
                    {
                        ledgers.Add(entry.LedgerBucket.BudgetBucket, entry.LedgerBucket);
                    }
                }
            }

            book.Ledgers = ledgers.Values;
        }
        internal static LedgerEntry SetTransactionsForTesting(this LedgerEntry entry, List <LedgerTransaction> transactions)
        {
            PrivateAccessor.SetField(entry, "transactions", transactions);
            decimal newBalance = entry.Balance + entry.NetAmount;

            entry.Balance = newBalance < 0 ? 0 : newBalance;
            return(entry);
        }
Exemplo n.º 4
0
        private void SaveSetup()
        {
            PrivateAccessor.SetField(this.subject, "budgetAnalyserDatabase", new Mock <ApplicationDatabase>().Object);
            this.mockService1.Setup(m => m.ValidateModel(It.IsAny <StringBuilder>())).Returns(true);
            this.mockService2.Setup(m => m.ValidateModel(It.IsAny <StringBuilder>())).Returns(true);

            this.subject.NotifyOfChange(ApplicationDataType.Budget);
        }
Exemplo n.º 5
0
 public static StatementModel WithNullBudgetBuckets(this StatementModel instance)
 {
     foreach (var txn in instance.AllTransactions)
     {
         PrivateAccessor.SetField(txn, "budgetBucket", null);
     }
     return(instance);
 }
Exemplo n.º 6
0
        public void Reconcile_ShouldNotThrow_GivenTestData1AndUnclassifiedTransactionsOutsideReconPeriod()
        {
            Transaction aTransaction = this.testDataStatement.AllTransactions.First();

            PrivateAccessor.SetField(aTransaction, "budgetBucket", null);

            Act(new DateTime(2013, 9, 15));
        }
Exemplo n.º 7
0
        public void Close_ShouldCloseAllServices()
        {
            PrivateAccessor.SetField(this.subject, "budgetAnalyserDatabase", new Mock <ApplicationDatabase>().Object);

            this.subject.Close();

            this.mockService1.Verify(m => m.Close());
            this.mockService2.Verify(m => m.Close());
        }
        private void ArrangeForCreateNewRule()
        {
            this.mockRuleFactory
            .Setup(m => m.CreateNewSingleUseRule(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string[]>(), It.IsAny <string>(), It.IsAny <decimal?>(), It.IsAny <bool>()))
            .Returns(new SingleUseMatchingRule(this.mockBucketRepo)
            {
                BucketCode = "Foo"
            });

            // This is to bypass validating that Initialise has happened when adding a new rule
            PrivateAccessor.SetField <TransactionRuleService>(this.subject, "rulesStorageKey", "Anything");
        }
        public void TestInitialise()
        {
            this.mockRuleRepo    = new Mock <IMatchingRuleRepository>();
            this.mockMatchMaker  = new Mock <IMatchmaker>();
            this.mockRuleFactory = new Mock <IMatchingRuleFactory>();
            this.mockBucketRepo  = new BucketBucketRepoAlwaysFind();

            this.subject = new TransactionRuleService(
                this.mockRuleRepo.Object,
                new FakeLogger(),
                this.mockMatchMaker.Object,
                this.mockRuleFactory.Object,
                new FakeEnvironmentFolders(),
                new FakeMonitorableDependencies(),
                this.mockBucketRepo);

            PrivateAccessor.SetField(this.subject, "rulesStorageKey", "Any storage key value");
        }
Exemplo n.º 10
0
 private static void SetPrivateBudgetCollection(XamlOnDiskBudgetRepository subject)
 {
     PrivateAccessor.SetField <XamlOnDiskBudgetRepository>(subject, "currentBudgetCollection", BudgetModelTestData.CreateCollectionWith1And2());
 }