public void Init_SpendingNotEditing_PropertiesSetupCorrectly()
        {
            //Setup
            var dbHelper = new Mock<ISqliteConnectionCreator>().Object;
            var transactionRepositorySetup = new Mock<ITransactionRepository>();
            transactionRepositorySetup.SetupProperty(x => x.Selected);

            var transactionManager = new TransactionManager(transactionRepositorySetup.Object,
                new Mock<IRepository<Account>>().Object,
                new Mock<IDialogService>().Object);

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

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

            var viewmodel = new ModifyTransactionViewModel(transactionRepositorySetup.Object,
                new AccountRepository(new AccountDataAccess(dbHelper)),
                new Mock<IDialogService>().Object,
                transactionManager,
                defaultManager);

            //Execute and Assert
            viewmodel.SelectedTransaction.ShouldBeNull();

            viewmodel.Init(false, "Spending");
            viewmodel.SelectedTransaction.Type.ShouldBe((int) TransactionType.Spending);
            viewmodel.SelectedTransaction.IsTransfer.ShouldBeFalse();
            viewmodel.SelectedTransaction.IsRecurring.ShouldBeFalse();
        }
        public void Init_SpendingNotEditing_PropertiesSetupCorrectly()
        {
            //Setup
            var transactionRepositorySetup = new Mock<ITransactionRepository>();
            transactionRepositorySetup.SetupProperty(x => x.Selected);

            var transactionManager = new TransactionManager(transactionRepositorySetup.Object,
                new Mock<IAccountRepository>().Object,
                new Mock<IDialogService>().Object);

            var accountRepoMock = new Mock<IAccountRepository>();
            accountRepoMock.Setup(x => x.Load(It.IsAny<Expression<Func<Account, bool>>>()));
            accountRepoMock.SetupAllProperties();

            var accountRepo = accountRepoMock.Object;
            accountRepo.Data = new ObservableCollection<Account>();

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

            var viewmodel = new ModifyTransactionViewModel(transactionRepositorySetup.Object,
                accountRepo,
                new Mock<IDialogService>().Object,
                transactionManager,
                defaultManager);

            //Execute and Assert
            viewmodel.SelectedTransaction.ShouldBeNull();

            viewmodel.Init(false, "Spending");
            viewmodel.SelectedTransaction.Type.ShouldBe((int) TransactionType.Spending);
            viewmodel.SelectedTransaction.IsTransfer.ShouldBeFalse();
            viewmodel.SelectedTransaction.IsRecurring.ShouldBeFalse();
        }
Ejemplo n.º 3
0
        public MainViewModel(TransactionManager transactionManager, INavigationService navigationService)
        {
            this.navigationService = navigationService;
            this.transactionManager = transactionManager;

            GoToAddTransactionCommand = new RelayCommand<string>(GoToAddTransaction);
            GoToAddAccountCommand = new RelayCommand(() => navigationService.NavigateTo("AddAccountView"));
        }
        public TransactionListViewModel(ITransactionRepository transactionRepository, IRepository<Account> accountRepository, TransactionManager transactionManager, INavigationService navigationService)
        {
            this.transactionRepository = transactionRepository;
            this.accountRepository = accountRepository;
            this.transactionManager = transactionManager;
            this.navigationService = navigationService;

            GoToAddTransactionCommand = new RelayCommand<string>(GoToAddTransaction);
        }
 public ModifyTransactionViewModel(ITransactionRepository transactionRepository,
     IRepository<Account> accountRepository,
     IDialogService dialogService,
     TransactionManager transactionManager,
     DefaultManager defaultManager)
 {
     this.transactionRepository = transactionRepository;
     this.dialogService = dialogService;
     this.transactionManager = transactionManager;
     this.defaultManager = defaultManager;
     this.accountRepository = accountRepository;
 }
 public TransactionListViewModel(ITransactionRepository transactionRepository,
     IRepository<Account> accountRepository,
     TransactionManager transactionManager,
     BalanceViewModel balanceViewModel,
     ModifyTransactionViewModel modifyTransactionViewModel, IDialogService dialogService)
 {
     this.transactionRepository = transactionRepository;
     this.accountRepository = accountRepository;
     this.transactionManager = transactionManager;
     this.balanceViewModel = balanceViewModel;
     this.modifyTransactionViewModel = modifyTransactionViewModel;
     this.dialogService = dialogService;
 }
Ejemplo n.º 7
0
        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 ClearTransactionBackgroundTask()
        {
            var insightKey = "599ff6bfdc79368ff3d5f5629a57c995fe93352e";

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

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

            transactionManager = new TransactionManager(
                new TransactionRepository(new TransactionDataAccess(sqliteConnectionCreator),
                    new RecurringTransactionDataAccess(sqliteConnectionCreator)),
                new AccountRepository(new AccountDataAccess(sqliteConnectionCreator)),
                null);
        }
        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 Title_TransactionTypeDifferentModes_CorrectTitle(TransactionType type, bool isEditMode,
            string result, string culture)
        {
            //Setup
            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(culture);
            Strings.Culture = new CultureInfo(culture);

            var dbHelper = new Mock<ISqliteConnectionCreator>().Object;
            var transactionRepository = new TransactionRepository(new TransactionDataAccess(dbHelper),
                new RecurringTransactionDataAccess(dbHelper))
            {
                Selected = new FinancialTransaction {Type = (int) type}
            };

            var transactionManager = new TransactionManager(transactionRepository,
                new Mock<IRepository<Account>>().Object,
                new Mock<IDialogService>().Object);

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

            var viewModel = new ModifyTransactionViewModel(transactionRepository,
                new AccountRepository(new AccountDataAccess(dbHelper)),
                new Mock<IDialogService>().Object,
                transactionManager,
                defaultManager)
            {
                IsEdit = isEditMode,
                IsTransfer = true
            };

            //Execute and assert
            viewModel.Title.ShouldBe(result);

            // Reset culture to current culture
            Strings.Culture = CultureInfo.CurrentCulture;
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture;
        }
        public void Init_IncomeEditing_PropertiesSetupCorrectly()
        {
            //Setup
            var testEndDate = new DateTime(2099, 1, 31);

            var transactionRepositorySetup = new Mock<ITransactionRepository>();
            transactionRepositorySetup.SetupGet(x => x.Selected).Returns(new FinancialTransaction
            {
                Type = (int) TransactionType.Income,
                IsRecurring = true,
                RecurringTransaction = new RecurringTransaction
                {
                    EndDate = testEndDate
                }
            });

            var accountRepoMock = new Mock<IAccountRepository>();
            accountRepoMock.Setup(x => x.Load(It.IsAny<Expression<Func<Account, bool>>>()));
            accountRepoMock.SetupAllProperties();

            var accountRepo = accountRepoMock.Object;
            accountRepo.Data = new ObservableCollection<Account>();

            var transactionManager = new TransactionManager(transactionRepositorySetup.Object,
                accountRepo,
                new Mock<IDialogService>().Object);


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

            var viewmodel = new ModifyTransactionViewModel(transactionRepositorySetup.Object,
                accountRepo,
                new Mock<IDialogService>().Object,
                transactionManager,
                defaultManager);

            //Execute and Assert
            viewmodel.SelectedTransaction.ShouldNotBeNull();

            viewmodel.Init(true, "Income");
            viewmodel.SelectedTransaction.Type.ShouldBe((int) TransactionType.Income);
            viewmodel.SelectedTransaction.IsTransfer.ShouldBeFalse();
            viewmodel.SelectedTransaction.IsRecurring.ShouldBeTrue();
            viewmodel.SelectedTransaction.RecurringTransaction.EndDate.ShouldBe(testEndDate);
            viewmodel.SelectedTransaction.RecurringTransaction.IsEndless.ShouldBeFalse();
        }