https://discord.umbraco.com logo
Does anyone have any examples of unit testing Exam...
# umbraco-chat
i
Does anyone have any examples of unit testing Examine. I've got something setup, and the tests pass (I've got a bunch of mocked ISearchResults) but it feels like I'm doing the actual filtering in the setup of the unit test, and the underlying ExamineService thats being tested isn't actually doing anything? ``[Fact] public async Task GetGaitSessions_FiltersOnDocumentType_WhenProvided() { // Arrange SetupExamineIndex(); SetupHttpContext(nameof(MemberType.Clinician)); // Override search results to only include GaitSession results // (simulating what Examine would actually return after filtering) var mockResults = CreateMockSearchResults(); var gaitSessionResults = mockResults .Where(m => m.Object.Values[Constants.Examine.Index.NodeTypeAlias] == nameof(GaitSession)) .Select(m => m.Object) .ToList(); _searchResultsMock.Setup(x => x.GetEnumerator()).Returns(() => gaitSessionResults.GetEnumerator()); _searchResultsMock.Setup(x => x.TotalItemCount).Returns(gaitSessionResults.Count); var filter = new PaginationFilter { PageNumber = 1, PageSize = 10 }; // Act var result = await _examineService.GetGaitSessionsAsync("test-id", filter, CancellationToken.None); // Assert Assert.NotNull(result); Assert.Equal(5, result.TotalItemCount); _queryMock.Verify(x => x.GroupedOr( It.IsAny<IEnumerable>(), It.Is(values => values.Contains(GaitSession.ModelTypeAlias))), Times.Once); }``