Skip to content

Commit

Permalink
refactored getFaq test. add 500 questions, get top 10 questions
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinICATT committed Sep 21, 2023
1 parent 1c07536 commit 330babc
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions Kiss.Bff.Test/GetFaqTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContactmomentDetails>
var testData = new List<ContactmomentDetails>();
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();
Expand All @@ -67,8 +59,16 @@ public void Get_ReturnsTopQuestions()
Assert.IsNotNull(resultList);

// Ensure that the result contains the top questions
var expectedQuestions = new List<string> { "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());
}

}
}

0 comments on commit 330babc

Please sign in to comment.