Beispiel #1
0
        public async Task GetCoursesAsyncThrownExceptionsWhenRequestd()
        {
            // Arrange
            var findACourseClient = A.Fake <IFindACourseClient>();

            A.CallTo(() => findACourseClient.CourseSearchAsync(A <CourseSearchRequest> .Ignored)).Throws <Exception>();

            var courseSearchService = new CourseSearchApiService(findACourseClient, defaultAuditService, defaultMapper);

            // Act
            Task Result() => courseSearchService.GetCoursesAsync("SomeKeyword", true);

            // Assert
            await Assert.ThrowsAsync <Exception>(Result).ConfigureAwait(false);
        }
Beispiel #2
0
        public async Task GetCoursesAsyncWritesToAuditLogWhenExceptionIsThrown()
        {
            // Arrange
            var findACourseClient = A.Fake <IFindACourseClient>();

            A.CallTo(() => findACourseClient.CourseSearchAsync(A <CourseSearchRequest> .Ignored)).Throws <Exception>();

            var courseSearchService = new CourseSearchApiService(findACourseClient, defaultAuditService, defaultMapper);

            // Act
            var result = await courseSearchService.GetCoursesAsync("SomeKeyword").ConfigureAwait(false);

            // Assert
            A.CallTo(() => defaultAuditService.CreateAudit(null, null, null)).WithAnyArguments().MustHaveHappenedOnceExactly();
            Assert.Empty(result);
        }
Beispiel #3
0
        public async Task GetCoursesAsyncReturnsGroupedCourseList()
        {
            // Arrange
            var dummyApiResponse  = BuildCourseSearchResponse();
            var findACourseClient = A.Fake <IFindACourseClient>();

            A.CallTo(() => findACourseClient.CourseSearchAsync(A <CourseSearchRequest> .Ignored)).Returns(dummyApiResponse);

            var courseSearchService = new CourseSearchApiService(findACourseClient, defaultAuditService, defaultMapper);

            // Act
            var result = await courseSearchService.GetCoursesAsync("SomeKeyword").ConfigureAwait(false);

            var resultList = result.ToList();

            // Assert
            Assert.Equal(dummyApiResponse.Results?.FirstOrDefault()?.CourseId.ToString(), resultList.FirstOrDefault()?.CourseId);
            Assert.True(resultList.Count == 2);
        }