public void CategoryDataAccess_CrudCategory()
        {
            var categoryDataAccess = new CategoryDataAccess();

            const string firstName = "category";
            const string secondName = "new category";

            var category = new Category
            {
                Name = firstName
            };

            categoryDataAccess.Save(category);

            categoryDataAccess.LoadList();
            var list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(firstName, list.First().Name);

            category.Name = secondName;
            categoryDataAccess.Save(category);

            list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(secondName, list.First().Name);

            categoryDataAccess.Delete(category);

            list = categoryDataAccess.LoadList();
            Assert.IsFalse(list.Any());
        }
        public void CategoryDataAccess_CrudCategory()
        {
            var categoryDataAccess =
                new CategoryDataAccess(new SqliteConnectionCreator(new WindowsSqliteConnectionFactory()));

            const string firstName = "category";
            const string secondName = "new category";

            var category = new Category
            {
                Name = firstName
            };

            categoryDataAccess.SaveItem(category);

            categoryDataAccess.LoadList();
            var list = categoryDataAccess.LoadList();

            Assert.Equal(1, list.Count);
            Assert.Equal(firstName, list.First().Name);

            category.Name = secondName;
            categoryDataAccess.SaveItem(category);

            list = categoryDataAccess.LoadList();

            Assert.Equal(1, list.Count);
            Assert.Equal(secondName, list.First().Name);

            categoryDataAccess.DeleteItem(category);

            list = categoryDataAccess.LoadList();
            Assert.False(list.Any());
        }
        public void CategoryRepository_Update()
        {
            var dbHelper = new DbHelper(new SQLitePlatformWinRT(), new TestDatabasePath());

            using (var db = dbHelper.GetSqlConnection())
            {
                db.DeleteAll<Category>();
            }

            var repository = new CategoryRepository(new CategoryDataAccess(dbHelper));

            var category = new Category
            {
                Name = "Ausgang"
            };

            repository.Save(category);
            Assert.AreEqual(1, repository.Data.Count);
            Assert.AreSame(category, repository.Data[0]);

            category.Name = "newName";

            repository.Save(category);

            Assert.AreEqual(1, repository.Data.Count);
            Assert.AreEqual("newName", repository.Data[0].Name);
        }
        public void CategoryRepository_Update()
        {
            var dbHelper = new SqliteConnectionCreator(new WindowsSqliteConnectionFactory());

            using (var db = dbHelper.GetConnection())
            {
                db.DeleteAll<Category>();
            }

            var repository = new CategoryRepository(new CategoryDataAccess(dbHelper));

            var category = new Category
            {
                Name = "Ausgang"
            };

            repository.Save(category);

            repository.Data.Count.ShouldBe(1);
            repository.Data[0].ShouldBeSameAs(category);

            category.Name = "newName";

            repository.Save(category);

            repository.Data.Count.ShouldBe(1);
            repository.Data[0].Name.ShouldBe("newName");
        }
        public void CategoryDataAccess_CrudCategory()
        {
            var categoryDataAccess = new CategoryDataAccess(new DbHelper(new SQLitePlatformWinRT(), new TestDatabasePath()));

            const string firstName = "category";
            const string secondName = "new category";

            var category = new Category
            {
                Name = firstName
            };

            categoryDataAccess.Save(category);

            categoryDataAccess.LoadList();
            var list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(firstName, list.First().Name);

            category.Name = secondName;
            categoryDataAccess.Save(category);

            list = categoryDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(secondName, list.First().Name);

            categoryDataAccess.Delete(category);

            list = categoryDataAccess.LoadList();
            Assert.IsFalse(list.Any());
        }
 public static async void DeleteCategory(Category category, bool skipConfirmation = false)
 {
     //TODO Refactor this
     if (skipConfirmation) //|| await Utilities.IsDeletionConfirmed())
     {
         CategoryData.Delete(category);
     }
 }
        public ModifyCategoryDialog(Category category = null)
        {
            InitializeComponent();

            if (category != null)
            {
                ((CategoryDialogViewModel) DataContext).IsEdit = true;
                ((CategoryDialogViewModel) DataContext).Selected = category;
            }
        }
        private void Loaded()
        {
            if (IsEdit) return;

            Selected = new Category();

            if (!string.IsNullOrEmpty(categoryListViewModel.SearchText))
            {
                Selected.Name = categoryListViewModel.SearchText;
            }
        }
        public CategoryDialog(Category category = null)
        {
            InitializeComponent();

            DataContext = Mvx.Resolve<CategoryDialogViewModel>();

            if (category != null)
            {
                ((CategoryDialogViewModel) DataContext).IsEdit = true;
                ((CategoryDialogViewModel) DataContext).Selected = category;
            }
        }
        private async void DeleteCategory(Category categoryToDelete)
        {
            if (await DialogService.ShowConfirmMessage(Strings.DeleteTitle, Strings.DeleteCategoryConfirmationMessage))
            {
                if (Categories.Contains(categoryToDelete))
                {
                    Categories.Remove(categoryToDelete);
                }

                CategoryRepository.Delete(categoryToDelete);
            }
        }
        public void CategoryRepository_Save()
        {
            var repository = new CategoryRepository(_categoryDataAccessMock);

            var category = new Category
            {
                Name = "Ausgang"
            };

            repository.Save(category);

            Assert.IsTrue(category == _categoryDataAccessMock.CategoryTestList[0]);
        }
        public void SaveToDatabase_NewCategory_CorrectId()
        {
            var name = "TestCategory";

            var category = new Category
            {
                Name = name
            };

            new CategoryDataAccess(connectionCreator).SaveItem(category);

            Assert.IsTrue(category.Id >= 1);
            Assert.AreEqual(name, category.Name);
        }
        public void Save_InputName_CorrectNameAssigned(string inputName, string expectedResult)
        {
            var categoryDataAccessMock = new CategoryDataAccessMock();
            var repository = new CategoryRepository(categoryDataAccessMock);

            var category = new Category
            {
                Name = inputName
            };

            repository.Save(category);

            categoryDataAccessMock.CategoryTestList[0].ShouldBeSameAs(category);
            categoryDataAccessMock.CategoryTestList[0].Name.ShouldBe(expectedResult);
        }
        public void CategoryRepository_Delete()
        {
            var repository = new CategoryRepository(_categoryDataAccessMock);

            var category = new Category
            {
                Name = "Ausgang"
            };

            repository.Save(category);
            Assert.AreSame(category, _categoryDataAccessMock.CategoryTestList[0]);

            repository.Delete(category);

            Assert.IsFalse(_categoryDataAccessMock.CategoryTestList.Any());
            Assert.IsFalse(repository.Data.Any());
        }
        public void SaveToDatabase_ExistingCategory_CorrectId()
        {
            var category = new Category();

            var dataAccess = new CategoryDataAccess(connectionCreator);
            dataAccess.SaveItem(category);

            Assert.IsNull(category.Name);

            var id = category.Id;

            var name = "TestCategory";
            category.Name = name;

            Assert.AreEqual(id, category.Id);
            Assert.AreEqual(name, category.Name);
        }
        public void CategoryRepository_Delete()
        {
            var categoryDataAccessMock = new CategoryDataAccessMock();
            var repository = new CategoryRepository(categoryDataAccessMock);

            var category = new Category
            {
                Name = "Ausgang"
            };

            repository.Save(category);

            categoryDataAccessMock.CategoryTestList[0].ShouldBeSameAs(category);

            repository.Delete(category);

            categoryDataAccessMock.CategoryTestList.Any().ShouldBeFalse();
            repository.Data.Any().ShouldBeFalse();
        }
        public void CategoryRepository_AddMultipleToCache()
        {
            var repository = new CategoryRepository(_categoryDataAccessMock);
            var category = new Category
            {
                Name = "Ausgang"
            };

            var secondCategory = new Category
            {
                Name = "Lebensmittel"
            };

            repository.Save(category);
            repository.Save(secondCategory);

            Assert.AreEqual(2, repository.Data.Count);
            Assert.AreSame(category, repository.Data[0]);
            Assert.AreSame(secondCategory, repository.Data[1]);
        }
        public void CategoryRepository_AddMultipleToCache()
        {
            var repository = new CategoryRepository(new CategoryDataAccessMock());
            var category = new Category
            {
                Name = "Ausgang"
            };

            var secondCategory = new Category
            {
                Name = "Lebensmittel"
            };

            repository.Save(category);
            repository.Save(secondCategory);

            repository.Data.Count.ShouldBe(2);
            repository.Data[0].ShouldBeSameAs(category);
            repository.Data[1].ShouldBeSameAs(secondCategory);
        }
        public void SaveToDatabase_MultipleCategories_AllSaved()
        {
            var category1 = new Category
            {
                Name = "Einkaufen",
            };

            var category2 = new Category
            {
                Name = "Beer",
            };

            var dataAccess = new CategoryDataAccess(connectionCreator);
            dataAccess.SaveItem(category1);
            dataAccess.SaveItem(category2);

            var resultList = dataAccess.LoadList();

            Assert.IsTrue(resultList.Any(x => x.Id == category1.Id && x.Name == category1.Name));
            Assert.IsTrue(resultList.Any(x => x.Id == category2.Id && x.Name == category2.Name));
        }
        public void DeleteFromDatabase_CategoryToDelete_CorrectlyDelete()
        {
            var category = new Category
            {
                Name = "categoryToDelete",
            };

            var dataAccess = new CategoryDataAccess(connectionCreator);
            dataAccess.SaveItem(category);

            Assert.IsTrue(dataAccess.LoadList(x => x.Id == category.Id).Any());

            dataAccess.DeleteItem(category);
            Assert.IsFalse(dataAccess.LoadList(x => x.Id == category.Id).Any());
        }
        public void SaveToDatabase_CreateAndUpdateCategory_CorrectlyUpdated()
        {
            var firstName = "old name";
            var secondName = "new name";

            var category = new Category
            {
                Name = firstName
            };

            var dataAccess = new CategoryDataAccess(connectionCreator);
            dataAccess.SaveItem(category);

            Assert.AreEqual(firstName, dataAccess.LoadList().FirstOrDefault(x => x.Id == category.Id).Name);

            category.Name = secondName;
            dataAccess.SaveItem(category);

            var categories = dataAccess.LoadList();
            Assert.IsFalse(categories.Any(x => x.Name == firstName));
            Assert.AreEqual(secondName, categories.First(x => x.Id == category.Id).Name);
        }
 private async void DeleteCategory(Category categoryToDelete)
 {
     if (await dialogService.ShowConfirmMessage(Strings.DeleteTitle, Strings.DeleteCategoryConfirmationMessage))
     {
         categoryRepository.Delete(categoryToDelete);
     }
 }
        public void CategoryRepository_SaveWithouthName()
        {
            var repository = new CategoryRepository(_categoryDataAccessMock);
            var category = new Category();

            repository.Save(category);

            Assert.AreSame(category, repository.Data[0]);
            Assert.IsTrue(Strings.NoNamePlaceholderLabel == repository.Data[0].Name);
        }
 /// <summary>
 ///     Message to notify about a selected category after choosing.
 /// </summary>
 /// <param name="sender">sender</param>
 /// <param name="selectedCategory">Selected Category</param>
 public CategorySelectedMessage(object sender, Category selectedCategory) : base(sender)
 {
     SelectedCategory = selectedCategory;
 }