diff --git a/Kiss.Bff.Test/GetFaqTests.cs b/Kiss.Bff.Test/GetFaqTests.cs index 56de3d026..984fee7fc 100644 --- a/Kiss.Bff.Test/GetFaqTests.cs +++ b/Kiss.Bff.Test/GetFaqTests.cs @@ -25,33 +25,25 @@ public void Cleanup() } [TestMethod] - public void Get_ReturnsTopQuestions() + public async Task Get_ReturnsTopQuestions() { using var dbContext = new BeheerDbContext(_dbContextOptions); // Arrange var controller = new GetFaq(dbContext); - var testData = new List + var testData = new List(); + var topQuestionsCount = 10; + + // Add 500 questions + for (int i = 1; i <= 500; i++) { - new ContactmomentDetails - { - Id = "1", - Vraag = "Question 1", - Einddatum = DateTime.UtcNow - }, - new ContactmomentDetails + testData.Add(new ContactmomentDetails { - Id = "2", - Vraag = "Question 2", + Id = i.ToString(), + Vraag = $"Question {i}", Einddatum = DateTime.UtcNow - }, - new ContactmomentDetails - { - Id = "3", - Vraag = "Question 1", - Einddatum = DateTime.UtcNow - }, - }; + }); + } dbContext.ContactMomentDetails.AddRange(testData); dbContext.SaveChanges(); @@ -67,8 +59,16 @@ public void Get_ReturnsTopQuestions() Assert.IsNotNull(resultList); // Ensure that the result contains the top questions - var expectedQuestions = new List { "Question 1", "Question 2" }; - CollectionAssert.AreEqual(expectedQuestions, resultList.ToList()); + var expectedQuestions = testData + .OrderByDescending(x => x.Einddatum) + .Where(x => !string.IsNullOrWhiteSpace(x.Vraag)) + .GroupBy(x => x.Vraag) + .OrderByDescending(x => x.Count()) + .Take(topQuestionsCount) + .Select(x => x.Key); + + CollectionAssert.AreEqual(expectedQuestions.ToList(), resultList.ToList()); } + } }