public async Task GetAllByCategoryId_ShouldReturnCorrectly() { var categoryName = "test"; var category = new Category { Name = categoryName, }; await context.Categories.AddAsync(category); await context.SaveChangesAsync(); var subCategoryOne = new SubCategory { Name = "test", CategoryId = category.Id, }; var subCategoryTwo = new SubCategory { Name = "test2", CategoryId = category.Id, }; var subCategoryThree = new SubCategory { Name = "test3", CategoryId = "anotherId", }; await context.SubCategories.AddAsync(subCategoryOne); await context.SubCategories.AddAsync(subCategoryTwo); await context.SubCategories.AddAsync(subCategoryThree); await context.SaveChangesAsync(); var subCategories = service.GetAllByCategoryId(category.Id).ToList(); var expectedSubCategoryOne = new SubCategoryServiceModel() { Name = subCategoryOne.Name, CategoryId = subCategoryOne.CategoryId, Id = subCategoryOne.Id, }; var expectedSubCategoryTwo = new SubCategoryServiceModel { Name = subCategoryTwo.Name, CategoryId = subCategoryTwo.CategoryId, Id = subCategoryTwo.Id, }; var expectedCategoriesCount = 2; var actualCategoriesCount = subCategories.Count; Assert.AreEqual(expectedCategoriesCount, actualCategoriesCount); AssertEx.PropertyValuesAreEquals(subCategories[0], expectedSubCategoryOne); AssertEx.PropertyValuesAreEquals(subCategories[1], expectedSubCategoryTwo); }