public void Save_ExistingEntryUpdated()
        {
            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));
            var testCategory = new Fixture().Create<CategoryViewModel>();
            testCategory.Id = 0;

            try
            {
                categoryRepository.Save(testCategory);
                categoryRepository.FindById(testCategory.Id).ShouldNotBeNull();

                const string updatedName = "FOOOOOOOOOO";
                testCategory.Name = updatedName;

                categoryRepository.Save(testCategory);
                categoryRepository.FindById(testCategory.Id).Name.ShouldBe(updatedName);
            }
            finally
            {
                categoryRepository.Delete(testCategory);
            }
        }
        public void Save_IdSet()
        {
            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));
            var testCategory = new Fixture().Create<CategoryViewModel>();
            testCategory.Id = 0;

            try
            {
                categoryRepository.Save(testCategory);
                testCategory.Id.ShouldBeGreaterThan(0);
            }
            finally
            {
                categoryRepository.Delete(testCategory);
            }
        }
        public void GetList_WithoutFilter()
        {
            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));
            var testCategory = new Fixture().Create<CategoryViewModel>();
            testCategory.Id = 0;

            try
            {
                categoryRepository.Save(testCategory);

                var selectedAccount = categoryRepository.GetList().First();

                selectedAccount.Id.ShouldBe(testCategory.Id);
                selectedAccount.Name.ShouldBe(testCategory.Name);
            }
            finally
            {
                categoryRepository.Delete(testCategory);
            }
        }
        public void GetList_WithFilter()
        {
            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));
            var testCategory = new Fixture().Create<CategoryViewModel>();
            testCategory.Id = 0;

            try
            {
                categoryRepository.Save(testCategory);

                categoryRepository.GetList(x => x.Id == testCategory.Id).First().Id.ShouldBe(testCategory.Id);
                categoryRepository.GetList(x => x.Id == 99).FirstOrDefault().ShouldBeNull();
            }
            finally
            {
                categoryRepository.Delete(testCategory);
            }
        }
        public void FindById_AccountDeleted()
        {
            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var testCategory = new Fixture().Create<CategoryViewModel>();
            testCategory.Id = 0;

            categoryRepository.Save(testCategory);
            var selected = categoryRepository.FindById(testCategory.Id);

            selected.ShouldNotBeNull();
            selected.ShouldBeInstanceOf<CategoryViewModel>();

            categoryRepository.Delete(testCategory);
            categoryRepository.FindById(testCategory.Id).ShouldBeNull();
        }
        public void GetList_WithChildren()
        {
            var paymentRepository =
                new PaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var fixture = new Fixture();

            var category = fixture.Create<CategoryViewModel>();
            category.Id = 0;
            categoryRepository.Save(category);

            var payment = fixture.Create<PaymentViewModel>();
            payment.Id = 0;
            payment.Category = category;

            paymentRepository.Save(payment);
            paymentRepository.ReloadCache();

            var selected = paymentRepository.GetList(x => x.Id == payment.Id).First();
            selected.ShouldNotBeNull();
            selected.Category.ShouldNotBeNull();
        }
        public void Save_WithCategory_FkSet()
        {
            var paymentRepository =
                new PaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var fixture = new Fixture();

            var category = fixture.Create<CategoryViewModel>();

            categoryRepository.Save(category);
            category.Id.ShouldBeGreaterThan(0);

            var testPayment = new Fixture().Create<PaymentViewModel>();
            testPayment.Id = 0;
            testPayment.Category = category;

            paymentRepository.Save(testPayment);
            paymentRepository.ReloadCache();
            paymentRepository.FindById(testPayment.Id).CategoryId.Value.ShouldBeGreaterThan(0);
        }
        public void SaveAndUpdate_WithCategory_NoDuplicates()
        {
            var paymentRepository =
                new PaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var category = new Fixture().Create<CategoryViewModel>();
            category.Id = 0;

            categoryRepository.Save(category);

            var testPayment = new Fixture().Create<PaymentViewModel>();
            testPayment.Id = 0;

            testPayment.Category = category;

            paymentRepository.Save(testPayment);
            paymentRepository.Save(testPayment);
            paymentRepository.ReloadCache();
            var selected = paymentRepository.FindById(testPayment.Id);

            categoryRepository.GetList(x => x.Name == testPayment.Category.Name).Count().ShouldBe(1);
        }
        public void Save_WithCategory()
        {
            var paymentRepository =
                new PaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var testCategory = new Fixture().Create<CategoryViewModel>();
            testCategory.Id = 0;

            categoryRepository.Save(testCategory);

            var testPayment = new Fixture().Create<PaymentViewModel>();
            testPayment.Id = 0;
            testPayment.Category = testCategory;

            paymentRepository.Save(testPayment);
            paymentRepository.ReloadCache();
            var selected = paymentRepository.FindById(testPayment.Id);

            selected.ShouldNotBeNull();
            selected.ShouldBeInstanceOf<PaymentViewModel>();

            selected.Category.ShouldNotBeNull();
            selected.Category.Id.ShouldBe(selected.CategoryId.Value);
            selected.Category.Id.ShouldBe(testPayment.Category.Id);

            paymentRepository.Delete(testPayment);
            paymentRepository.FindById(testPayment.Id).ShouldBeNull();
        }
        public void Delete_WithChildren_PaymentDeleted()
        {
            var paymentRepository =
                new PaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var categoryRepository =
                new CategoryRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                    new MvxWpfFileStore(FILE_ROOT)));

            var category = new Fixture().Create<CategoryViewModel>();
            category.Id = 0;
            categoryRepository.Save(category);

            var testPayment = new Fixture().Create<PaymentViewModel>();
            testPayment.Id = 0;
            testPayment.Category = category;

            paymentRepository.Save(testPayment);
            paymentRepository.ReloadCache();
            var payment = paymentRepository.FindById(testPayment.Id);

            payment.ShouldNotBeNull();
            payment.Category.ShouldNotBeNull();

            paymentRepository.Delete(testPayment);
            paymentRepository.FindById(testPayment.Id).ShouldBeNull();

            categoryRepository.FindById(testPayment.Category.Id).ShouldNotBeNull();
        }