public async void CreateAsync_GivenNothingCreated_ReturnsERROR_CREATING()
        {
            var categoryToCreate = new CategoryCreateDTO
            {
                Name = "New Category"
            };

            categoryRepositoryMock.Setup(c => c.FindAsync(categoryToCreate.Name)).ReturnsAsync(default(CategoryDTO));
            categoryRepositoryMock.Setup(c => c.CreateAsync(categoryToCreate)).ReturnsAsync(0);

            using (var logic = new CategoryLogic(categoryRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.CreateAsync(categoryToCreate);

                Assert.Equal(ResponseLogic.ERROR_CREATING, response);
                categoryRepositoryMock.Verify(c => c.FindAsync(categoryToCreate.Name));
                categoryRepositoryMock.Verify(c => c.CreateAsync(categoryToCreate));
            }
        }
        public async void CreateAsync_GivenValidCategory_ReturnsSUCCESS()
        {
            var categoryToCreate = new CategoryCreateDTO
            {
                Name = "New Category"
            };

            categoryRepositoryMock.Setup(c => c.FindAsync(categoryToCreate.Name)).ReturnsAsync(default(CategoryDTO));
            categoryRepositoryMock.Setup(c => c.CreateAsync(categoryToCreate)).ReturnsAsync(1);

            using (var logic = new CategoryLogic(categoryRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.CreateAsync(categoryToCreate);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                categoryRepositoryMock.Verify(c => c.FindAsync(categoryToCreate.Name));
                categoryRepositoryMock.Verify(c => c.CreateAsync(categoryToCreate));
            }
        }
        public async void CreateAsync_GivenCategoryExists_ReturnsSUCCESS()
        {
            var categoryToCreate = new CategoryCreateDTO
            {
                Name = "New Category"
            };

            var existingCategory = new CategoryDTO
            {
                Id   = 1,
                Name = "New Category"
            };

            categoryRepositoryMock.Setup(c => c.FindAsync(categoryToCreate.Name)).ReturnsAsync(existingCategory);

            using (var logic = new CategoryLogic(categoryRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.CreateAsync(categoryToCreate);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                categoryRepositoryMock.Verify(c => c.FindAsync(categoryToCreate.Name));
                categoryRepositoryMock.Verify(c => c.CreateAsync(It.IsAny <CategoryCreateDTO>()), Times.Never());
            }
        }
        private async void OnSave(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (IsEditing) //neu dang o che do chinh sua
                {
                    var categoryLogic = new CategoryLogic(_dbContext);
                    // Kiem tra them xoa sua
                    foreach (var category in ListCategoryBindProp)
                    {
                        switch (category.Status)
                        {
                        case Status.New:
                            var newCategory = new Category
                            {
                                Id           = category.Id,
                                CategoryName = category.CategoryName
                            };
                            await categoryLogic.CreateAsync(newCategory, false);

                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            var modCategory = new Category
                            {
                                Id           = category.Id,
                                CategoryName = category.CategoryName
                            };
                            await categoryLogic.UpdateAsync(modCategory, false);

                            break;

                        case Status.Deleted:
                            break;

                        default:
                            break;
                        }
                        MessagingCenter.Send(category, Messages.CATEGORY_MESSAGE);
                    }

                    foreach (var cate in _listDeleted)
                    {
                        cate.Status = Status.Deleted;
                        await categoryLogic.DeleteAsync(cate.Id, false);

                        MessagingCenter.Send(cate, Messages.CATEGORY_MESSAGE);
                    }
                    //neu co nhap category moi thi tao roi quay ve
                    if (!string.IsNullOrWhiteSpace(NewCategoryNameBindProp))
                    {
                        var newCate = new Category
                        {
                            Id           = Guid.NewGuid().ToString(),
                            CategoryName = NewCategoryNameBindProp,
                        };
                        var newVsCate = new VisualCategoryModel
                        {
                            Id           = newCate.Id,
                            CategoryName = newCate.CategoryName,
                            Status       = Status.New
                        };
                        await categoryLogic.CreateAsync(newCate, false);

                        ListCategoryBindProp.Add(newVsCate);
                        MessagingCenter.Send(newCate, Messages.CATEGORY_MESSAGE);
                    }

                    await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                    await NavigationService.GoBackAsync();
                }
                else // neu dang o che do binh thuong
                {
                    var categoryLogic = new CategoryLogic(_dbContext);
                    // Kiem tra them moi
                    foreach (var category in ListCategoryBindProp)
                    {
                        switch (category.Status)
                        {
                        case Status.New:
                            var newCategory = new Category
                            {
                                Id           = category.Id,
                                CategoryName = category.CategoryName,
                            };
                            await categoryLogic.CreateAsync(newCategory, false);

                            MessagingCenter.Send(category, Messages.CATEGORY_MESSAGE);
                            category.Status = Status.Normal;
                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            break;

                        case Status.Deleted:
                            break;
                        }
                    }

                    // neu khong nhap gi
                    if (string.IsNullOrWhiteSpace(NewCategoryNameBindProp))
                    {
                        //neu co chon thi tra ve ten category
                        if (SelectedCategoryBindProp != null)
                        {
                            //truyen ten category ve trang tao item
                            var param = new NavigationParameters();
                            param.Add(Keys.CATEGORY, SelectedCategoryBindProp);

                            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                            await NavigationService.GoBackAsync(param);
                        }
                        else
                        {
                            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                            return;
                        }
                    }
                    else // tao moi
                    {
                        var newCate = new Category
                        {
                            Id           = Guid.NewGuid().ToString(),
                            CategoryName = NewCategoryNameBindProp,
                        };
                        var newVsCate = new VisualCategoryModel
                        {
                            Id           = newCate.Id,
                            CategoryName = newCate.CategoryName,
                            Status       = Status.New
                        };
                        await categoryLogic.CreateAsync(newCate, false);

                        ListCategoryBindProp.Add(newVsCate);
                        MessagingCenter.Send(newCate, Messages.CATEGORY_MESSAGE);

                        await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                        //truyen ten category ve trang tao item
                        var param = new NavigationParameters();
                        param.Add(Keys.CATEGORY, newCate);

                        await NavigationService.GoBackAsync(param);
                    }
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }