public void CheckRecurringPayments_Daily_CorrectPaymentsCreated()
        {
            //Setup
            var sqliteConnector = new SqliteConnectionCreator(new WindowsSqliteConnectionFactory(), 
                new MvxWindowsCommonFileStore());

            var accountRepo = new AccountRepository(new AccountDataAccess(sqliteConnector));

            var paymentRepo = new PaymentRepository(new PaymentDataAccess(sqliteConnector),
                new RecurringPaymentDataAccess(sqliteConnector),
                accountRepo,
                new CategoryRepository(new CategoryDataAccess(sqliteConnector)));

            var account = new Account
            {
                Name = "test1",
                CurrentBalance = 100
            };

            accountRepo.Save(account);

            var payment = new Payment
            {
                ChargedAccount = account,
                Amount = 10,
                Date = DateTime.Today.AddDays(-1),
                IsRecurring = true
            };

            payment.RecurringPayment =
                RecurringPaymentHelper.
                    GetRecurringFromPayment(payment,
                        true,
                        (int) PaymentRecurrence.Daily,
                        DateTime.Now.AddYears(1));

            paymentRepo.Save(payment);

            //Execution
            new RecurringPaymentManager(paymentRepo, accountRepo).CheckRecurringPayments();

            //Assert
            Assert.AreEqual(90, account.CurrentBalance);
            Assert.AreEqual(90, accountRepo.Data[0].CurrentBalance);

            Assert.AreEqual(2, paymentRepo.Data.Count);

            Assert.IsTrue(paymentRepo.Data[0].IsCleared);
            Assert.IsTrue(paymentRepo.Data[1].IsCleared);

            Assert.IsTrue(paymentRepo.Data[0].IsRecurring);
            Assert.IsTrue(paymentRepo.Data[1].IsRecurring);

            Assert.AreNotEqual(0, paymentRepo.Data[0].RecurringPaymentId);
            Assert.AreNotEqual(0, paymentRepo.Data[1].RecurringPaymentId);

            Assert.IsNotNull(paymentRepo.Data[0].RecurringPayment);
            Assert.IsNotNull(paymentRepo.Data[1].RecurringPayment);
        }
        public void SaveWithouthAccount_NoAccount_InvalidDataException()
        {
            var accountRepositorySetup = new Mock<IAccountRepository>();
            accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account>());

            var categoryDataAccessSetup = new Mock<IRepository<Category>>();
            categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>());

            var repository = new PaymentRepository(new PaymentDataAccessMock(),
                new RecurringPaymentDataAccessMock(),
                accountRepositorySetup.Object,
                categoryDataAccessSetup.Object,
                new Mock<INotificationService>().Object);

            var payment = new Payment
            {
                Amount = 20
            };

            repository.Save(payment);
        }
        public void Save_DifferentPaymentTypes_CorrectlySaved()
        {
            var accountRepositorySetup = new Mock<IAccountRepository>();
            accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account>());

            var categoryDataAccessSetup = new Mock<IRepository<Category>>();
            categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>());

            var paymentDataAccessMock = new PaymentDataAccessMock();
            var repository = new PaymentRepository(paymentDataAccessMock,
                new RecurringPaymentDataAccessMock(),
                accountRepositorySetup.Object,
                categoryDataAccessSetup.Object,
                new Mock<INotificationService>().Object);

            var account = new Account
            {
                Id = 2,
                Name = "TestAccount"
            };

            var payment = new Payment
            {
                ChargedAccount = account,
                TargetAccount = null,
                Amount = 20,
                Type = (int) PaymentType.Income
            };

            repository.Save(payment);

            Assert.AreSame(payment, paymentDataAccessMock.PaymentTestList[0]);
            Assert.AreEqual((int) PaymentType.Income, paymentDataAccessMock.PaymentTestList[0].Type);
        }
        public void GetUnclearedPayments_FutureDate_PastPayments()
        {
            var accountRepositorySetup = new Mock<IAccountRepository>();
            accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account>());

            var categoryDataAccessSetup = new Mock<IRepository<Category>>();
            categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>());

            var repository = new PaymentRepository(new PaymentDataAccessMock(),
                new RecurringPaymentDataAccessMock(),
                accountRepositorySetup.Object,
                categoryDataAccessSetup.Object,
                new Mock<INotificationService>().Object);

            var account = new Account
            {
                Id = 2,
                Name = "TestAccount"
            };

            repository.Save(new Payment
            {
                ChargedAccount = account,
                Amount = 55,
                Date = Utilities.GetEndOfMonth().AddDays(-1),
                Note = "this is a note!!!",
                IsCleared = false
            }
                );

            var payments = repository.GetUnclearedPayments();
            Assert.AreEqual(0, payments.Count());

            payments = repository.GetUnclearedPayments(Utilities.GetEndOfMonth());
            Assert.AreEqual(1, payments.Count());
        }
        public void AddItemToDataList_SaveAccount_IsAddedToData()
        {
            var accountRepositorySetup = new Mock<IAccountRepository>();
            accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account>());

            var categoryDataAccessSetup = new Mock<IRepository<Category>>();
            categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>());

            var repository = new PaymentRepository(new PaymentDataAccessMock(),
                new RecurringPaymentDataAccessMock(),
                accountRepositorySetup.Object,
                categoryDataAccessSetup.Object,
                new Mock<INotificationService>().Object);

            var account = new Account
            {
                Id = 2,
                Name = "TestAccount"
            };

            var payment = new Payment
            {
                ChargedAccount = account,
                Amount = 20,
                Type = (int) PaymentType.Transfer
            };

            repository.Save(payment);
            Assert.IsTrue(repository.Data.Contains(payment));
        }
        public void PaymentRepository_Delete()
        {
            var accountRepositorySetup = new Mock<IAccountRepository>();
            accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account>());

            var categoryDataAccessSetup = new Mock<IRepository<Category>>();
            categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>());

            var paymentDataAccessMock = new PaymentDataAccessMock();
            var repository = new PaymentRepository(new PaymentDataAccessMock(),
                new RecurringPaymentDataAccessMock(),
                accountRepositorySetup.Object,
                categoryDataAccessSetup.Object,
                new Mock<INotificationService>().Object);

            var account = new Account
            {
                Id = 2,
                Name = "TestAccount"
            };

            var payment = new Payment
            {
                ChargedAccount = account,
                ChargedAccountId = 2,
                Amount = 20
            };

            repository.Save(payment);
            Assert.AreSame(payment, repository.Data[0]);

            repository.Delete(payment);

            Assert.IsFalse(repository.Data.Any());
        }
        public void Save_TransferPayment_CorrectlySaved()
        {
            var accountRepositorySetup = new Mock<IAccountRepository>();
            accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account>());

            var categoryDataAccessSetup = new Mock<IRepository<Category>>();
            categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>());

            var paymentDataAccessMock = new PaymentDataAccessMock();
            var repository = new PaymentRepository(new PaymentDataAccessMock(),
                new RecurringPaymentDataAccessMock(),
                accountRepositorySetup.Object,
                categoryDataAccessSetup.Object,
                new Mock<INotificationService>().Object);

            var account = new Account
            {
                Id = 2,
                Name = "TestAccount"
            };

            var targetAccount = new Account
            {
                Id = 3,
                Name = "targetAccount"
            };

            var payment = new Payment
            {
                ChargedAccount = account,
                ChargedAccountId = 2,
                TargetAccount = targetAccount,
                TargetAccountId = 3,
                Amount = 20,
                Type = (int) PaymentType.Transfer
            };

            repository.Save(payment);

            Assert.AreSame(payment, repository.Data[0]);
            Assert.AreEqual((int) PaymentType.Transfer, repository.Data[0].Type);
        }