public async Task <bool> ExistsCategory(Guid categoryId) { using (IBlogCategory blogcategorySvc = new BlogCategoryService()) { return(await blogcategorySvc.GetAll().AnyAsync(m => m.Id == categoryId)); } }
public async Task <int> GetCategoryDataCount(Guid id) { using (IBlogCategory blogCategorySvc = new BlogCategoryService()) { Guid allId = Guid.Parse("00000000-0000-0000-0000-000000000001"); return(await blogCategorySvc.GetAll().CountAsync(m => m.UserId == id || m.Id == allId)); } }
public async Task <List <BlogCategoryDto> > GetCategoriesByCount(Guid userId, int count) { using (IBlogCategory blogCategorySvc = new BlogCategoryService()) { Guid allId = Guid.Parse("00000000-0000-0000-0000-000000000001"); return(await blogCategorySvc.GetAll().Where(m => m.UserId == userId || m.Id == allId).Select(m => new BlogCategoryDto() { Id = m.Id, BlogCategoryName = m.CategoryName }).Take(count).ToListAsync()); } }
public void WhenGetAll_ReturnResult() { var responseMock = new List <BlogCategory>(); responseMock.Add(new BlogCategory { Name = "Category Alpha" }); responseMock.Add(new BlogCategory { Name = "Category Beta" }); responseMock.Add(new BlogCategory { Name = "Category Gamma" }); var persistenceMock = new Mock <IBlogCategoryRepository>(); persistenceMock.Setup(p => p.GetAll()).Returns(responseMock); var service = new BlogCategoryService(persistenceMock.Object); var categories = service.GetAll(); Assert.NotNull(categories); Assert.Equal(3, categories.ToList().Count); }