public BudgetModel CreateNewBudget(string budgetPath)
        {
            var deviceSettings = _settingsProvider.Get <Device>();

            Guid deviceId = deviceSettings.DeviceID;

            if (File.Exists(budgetPath))
            {
                File.Delete(budgetPath);
            }
            IBudgetStore budgetStore = new SQLiteBudgetStore(deviceId, budgetPath);
            var          budgetModel = BudgetModel.CreateNew(deviceId, budgetStore);

            return(budgetModel);
        }
Exemple #2
0
        public static TestBudget CreateBudget(BudgetBackends budgetBackend, Budget initialBudget = null)
        {
            TestBudget testBudget = null;

            if (budgetBackend == BudgetBackends.Memory)
            {
                testBudget          = new TestBudget();
                testBudget.DeviceID = Guid.NewGuid();

                testBudget.EventStore  = new TestEventStore(new MemoryEventStore());
                testBudget.BudgetStore = new MemoryBudgetStore(testBudget.EventStore);
            }
            else if (budgetBackend == BudgetBackends.SQLite)
            {
                testBudget          = new TestBudget();
                testBudget.DeviceID = Guid.NewGuid();

                SqliteConnectionStringBuilder builder = new SqliteConnectionStringBuilder();
                builder.Mode       = SqliteOpenMode.Memory;
                builder.Cache      = SqliteCacheMode.Shared;
                builder.DataSource = "BudgetTests";

                testBudget.BudgetStore = new SQLiteBudgetStore(testBudget.DeviceID, builder.ToString(), (es) => new TestEventStore(es));
                testBudget.EventStore  = testBudget.BudgetStore.EventStore as TestEventStore;
            }

            if (initialBudget == null)
            {
                initialBudget = InitializeBudget();
            }

            testBudget.BudgetModel = BudgetModel.CreateNew(testBudget.DeviceID, testBudget.BudgetStore, initialBudget);
            testBudget.BudgetModel.SaveChanges();

            testBudget.EventStore.TestEvents.Clear();
            testBudget.TestEvents = testBudget.EventStore.TestEvents;
            testBudget.Budget     = initialBudget;

            return(testBudget);
        }