public void Delete_None_AccountDeleted()
        {
            var testList = new List<Account>();

            var accountDataAccessSetup = new Mock<IDataAccess<Account>>();
            accountDataAccessSetup.Setup(x => x.SaveItem(It.IsAny<Account>()))
                .Callback((Account acc) => testList.Add(acc));

            var account = new Account
            {
                Name = "Sparkonto",
                CurrentBalance = 6034
            };

            accountDataAccessSetup.Setup(x => x.LoadList(null)).Returns(new List<Account>
            {
                account
            });

            var repository = new AccountRepository(accountDataAccessSetup.Object);

            repository.Delete(account);

            testList.Any().ShouldBeFalse();
            repository.Data.Any().ShouldBeFalse();
        }
        public void AccountRepository_Update()
        {
            const string newName = "newName";

            var repository =
                new AccountRepository(
                    new AccountDataAccess(new SqliteConnectionCreator(new WindowsSqliteConnectionFactory())));

            var account = new Account
            {
                Name = "Sparkonto",
                CurrentBalance = 6034
            };

            repository.Save(account);

            repository.Data[0].ShouldBeSameAs(account);

            account.Name = newName;

            repository.Save(account);

            repository.Data.Count().ShouldBe(1);
            repository.Data[0].Name.ShouldBe(newName);
        }
        public void Save_InputName_CorrectNameAssigned(string nameInput, string nameExpected, string culture)
        {
            var testList = new List<Account>();

            // Set test culture
            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(culture);
            Strings.Culture = new CultureInfo(culture);

            var accountDataAccessSetup = new Mock<IDataAccess<Account>>();
            accountDataAccessSetup.Setup(x => x.SaveItem(It.IsAny<Account>()))
                .Callback((Account acc) => testList.Add(acc));

            accountDataAccessSetup.Setup(x => x.LoadList(null)).Returns(new List<Account>());

            var accountRepository = new AccountRepository(accountDataAccessSetup.Object);

            var account = new Account
            {
                Name = nameInput,
                CurrentBalance = 6034
            };

            accountRepository.Save(account);

            testList[0].ShouldBeSameAs(account);
            testList[0].Name.ShouldBe(nameExpected);

            // Reset Culture
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture;
            Strings.Culture = CultureInfo.CurrentCulture;
        }
        public void AccountRepository_SaveWithoutName()
        {
            var accountDataAccessMock = new AccountDataAccessMock();
            var repository = new AccountRepository(accountDataAccessMock);

            var account = new Account
            {
                CurrentBalanceWithoutExchange = 6034,
                CurrentBalance = 6034,
                Currency = "CHF"
            };

            repository.Save(account);

            Assert.AreSame(account, accountDataAccessMock.AccountTestList[0]);
            Assert.IsTrue(accountDataAccessMock.AccountTestList[0].Name == Strings.NoNamePlaceholderLabel);
        }
        public void GoToAddTransaction_Transactiontype_CorrectPreparation(string typestring, TransactionType type)
        {
            Setup();
            // for navigation parsing
            Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());

            var dbHelper = new Mock<ISqliteConnectionCreator>().Object;
            var accountRepository = new AccountRepository(new AccountDataAccess(dbHelper));
            var transactionRepository = new TransactionRepository(new TransactionDataAccess(dbHelper),
                new RecurringTransactionDataAccess(dbHelper));
            var transactionManager = new TransactionManager(transactionRepository, accountRepository,
                new Mock<IDialogService>().Object);

            var defaultManager = new DefaultManager(accountRepository,
                new SettingDataAccess(new Mock<IRoamingSettings>().Object));

            var modifyTransactionViewModel =
                new ModifyTransactionViewModel(transactionRepository,
                    accountRepository,
                    new Mock<IDialogService>().Object,
                    transactionManager,
                    defaultManager);

            var modifyAccountViewModel = new ModifyAccountViewModel(accountRepository,
                new BalanceViewModel(accountRepository, new Mock<ITransactionRepository>().Object));

            var mainViewModel = new MainViewModel(modifyAccountViewModel, modifyTransactionViewModel,
                new BalanceViewModel(accountRepository, transactionRepository));

            mainViewModel.GoToAddTransactionCommand.Execute(typestring);

            Assert.False(modifyTransactionViewModel.IsEdit);
            Assert.True(modifyTransactionViewModel.IsEndless);
            if (type == TransactionType.Transfer)
            {
                Assert.True(modifyTransactionViewModel.IsTransfer);
            }
            else
            {
                Assert.False(modifyTransactionViewModel.IsTransfer);
            }
            Assert.Equal((int) type, modifyTransactionViewModel.SelectedTransaction.Type);
        }
        public void GoToAddPayment_PaymentType_CorrectPreparation(string typestring, PaymentType type)
        {
            Setup();
            // for navigation parsing
            Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());

            var dbHelper = new Mock<ISqliteConnectionCreator>().Object;
            var accountRepository = new AccountRepository(new AccountDataAccess(dbHelper));
            var paymentRepository = new PaymentRepository(new PaymentDataAccess(dbHelper),
                new RecurringPaymentDataAccess(dbHelper),
                accountRepository,
                new CategoryRepository(new CategoryDataAccess(dbHelper)));
            var paymentManager = new PaymentManager(paymentRepository, accountRepository,
                new Mock<IDialogService>().Object);

            var defaultManager = new DefaultManager(accountRepository,
                new SettingDataAccess(new Mock<IRoamingSettings>().Object));

            var modifyPaymentViewModel =
                new ModifyPaymentViewModel(paymentRepository,
                    accountRepository,
                    new Mock<IDialogService>().Object,
                    paymentManager,
                    defaultManager);

            var modifyAccountViewModel = new ModifyAccountViewModel(accountRepository);

            var mainViewModel = new MainViewModel(modifyAccountViewModel);

            mainViewModel.GoToAddPaymentCommand.Execute(typestring);

            Assert.False(modifyPaymentViewModel.IsEdit);
            Assert.True(modifyPaymentViewModel.IsEndless);
            if (type == PaymentType.Transfer)
            {
                Assert.True(modifyPaymentViewModel.IsTransfer);
            }
            else
            {
                Assert.False(modifyPaymentViewModel.IsTransfer);
            }
            Assert.Equal((int) type, modifyPaymentViewModel.SelectedPayment.Type);
        }
        public void GoToAddTransaction_Transfer_CorrectPreparation()
        {
            var dbHelper = new DbHelperStub();
            var accountRepository = new AccountRepository(new AccountDataAccess(dbHelper));
            var settings = new SettingDataAccess();
            var addTransactionViewModel =
                new AddTransactionViewModel(new TransactionRepository(new TransactionDataAccess(dbHelper)),
                    accountRepository,
                    settings,
                    new NavigationServiceStub(),
                    new DialogServiceStub());

            var transactionManager = new TransactionManager(addTransactionViewModel, accountRepository, settings);

            transactionManager.PrepareCreation("Transfer");

            Assert.IsFalse(addTransactionViewModel.IsEdit);
            Assert.IsTrue(addTransactionViewModel.IsEndless);
            Assert.IsTrue(addTransactionViewModel.IsTransfer);
            Assert.AreEqual((int) TransactionType.Transfer, addTransactionViewModel.SelectedTransaction.Type);
            Assert.IsFalse(addTransactionViewModel.SelectedTransaction.IsExchangeModeActive);
        }
        public void AccountRepository_Delete()
        {
            var accountDataAccessMock = new AccountDataAccessMock();
            var repository = new AccountRepository(accountDataAccessMock);

            var account = new Account
            {
                Name = "Sparkonto",
                CurrentBalanceWithoutExchange = 6034,
                CurrentBalance = 6034,
                Currency = "CHF"
            };

            repository.Save(account);

            Assert.IsTrue(account == accountDataAccessMock.AccountTestList[0]);

            repository.Delete(account);

            Assert.IsFalse(accountDataAccessMock.AccountTestList.Any());
            Assert.IsFalse(repository.Data.Any());
        }
        public void AccountRepository_Update()
        {
            var repository = new AccountRepository(new AccountDataAccess(new DbHelper(new SQLitePlatformWinRT(), new TestDatabasePath())));

            var account = new Account
            {
                Name = "Sparkonto",
                CurrentBalanceWithoutExchange = 6034,
                CurrentBalance = 6034,
                Currency = "CHF"
            };

            repository.Save(account);

            Assert.IsTrue(account == repository.Data[0]);

            account.Name = "newName";

            repository.Save(account);

            Assert.AreEqual(1, repository.Data.Count());
            Assert.AreEqual("newName", repository.Data[0].Name);
        }
        public ClearPaymentBackgroundTask()
        {
            var insightKey = "599ff6bfdc79368ff3d5f5629a57c995fe93352e";

#if DEBUG
            insightKey = Insights.DebugModeKey;
#endif
            if (!Insights.IsInitialized)
            {
                Insights.Initialize(insightKey);
            }

            var sqliteConnectionCreator = new SqliteConnectionCreator(new WindowsSqliteConnectionFactory());

            var accountRepository = new AccountRepository(new AccountDataAccess(sqliteConnectionCreator));

            paymentManager = new PaymentManager(
                new PaymentRepository(new PaymentDataAccess(sqliteConnectionCreator),
                    new RecurringPaymentDataAccess(sqliteConnectionCreator),
                    accountRepository,
                    new CategoryRepository(new CategoryDataAccess(sqliteConnectionCreator))), 
                accountRepository,
                null);
        }
        public void Save_EmptyName_CorrectDefault()
        {
            var testList = new List<Account>();
            const string nameInput = "";

            var accountDataAccessSetup = new Mock<IDataAccess<Account>>();
            accountDataAccessSetup.Setup(x => x.SaveItem(It.IsAny<Account>()))
                .Callback((Account acc) => testList.Add(acc));

            accountDataAccessSetup.Setup(x => x.LoadList(null)).Returns(new List<Account>());

            var accountRepository = new AccountRepository(accountDataAccessSetup.Object);

            var account = new Account
            {
                Name = nameInput,
                CurrentBalance = 6034
            };

            accountRepository.Save(account);

            Assert.AreSame(testList[0], account);
            Assert.AreSame(testList[0].Name, account.Name);
        }
        public void Save_InputName_CorrectNameAssigned()
        {
            var testList = new List<Account>();
            const string nameInput = "Sparkonto";

            var accountDataAccessSetup = new Mock<IDataAccess<Account>>();
            accountDataAccessSetup.Setup(x => x.SaveItem(It.IsAny<Account>()))
                .Callback((Account acc) => testList.Add(acc));

            accountDataAccessSetup.Setup(x => x.LoadList(null)).Returns(new List<Account>());

            var accountRepository = new AccountRepository(accountDataAccessSetup.Object);

            var account = new Account
            {
                Name = nameInput,
                CurrentBalance = 6034
            };

            accountRepository.Save(account);

            testList[0].ShouldBeSameAs(account);
            testList[0].Name.ShouldBe(nameInput);
        }
        public void Load_AccountDataAccess_DataInitialized()
        {
            var accountDataAccessSetup = new Mock<IDataAccess<Account>>();
            accountDataAccessSetup.Setup(x => x.LoadList(null)).Returns(new List<Account>
            {
                new Account {Id = 10},
                new Account {Id = 15}
            });

            var accountRepository = new AccountRepository(accountDataAccessSetup.Object);
            accountRepository.Load();

            Assert.IsTrue(accountRepository.Data.Any(x => x.Id == 10));
            Assert.IsTrue(accountRepository.Data.Any(x => x.Id == 15));
        }