Exemplo n.º 1
0
        public async Task SearchCoursesAsyncReturnsCorrectNumberOfPages()
        {
            const int totalResults          = 501;
            const int pageSize              = 50;
            const int startItem             = 201;
            const int expectedNumberOfPages = 11;
            const int expectedPageNumber    = 6;

            var request          = BuildCourseSearchProperties();
            var dummyApiResponse = BuildCourseSearchResponse(startItem, totalResults, pageSize);

            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.SearchCoursesAsync(request).ConfigureAwait(false);

            // Assert
            Assert.Equal(totalResults, result.ResultProperties.TotalResultCount);
            Assert.Equal(expectedNumberOfPages, result.ResultProperties.TotalPages);
            Assert.Equal(expectedPageNumber, result.ResultProperties.Page);
        }
        public async Task CompositeTLevelSDetails()
        {
            var courseSearchService = new CourseSearchApiService(findACourseClient, auditService, mapper);
            var tLevelResponse      = await courseSearchService.GetTLevelDetailsAsync("01baf1e4-6ee0-497a-86c4-04bb1c11a6b9").ConfigureAwait(false);

            tLevelResponse.Should().NotBeNull();
        }
        public async Task CourseGet()
        {
            var courseGetRequest = new CourseGetRequest
            {
                CourseId = Guid.Parse("2ed8b2f9-da49-4432-963b-5842746aef5c"),
                RunId    = Guid.Parse("f6f0036f-5cdf-486c-8b3e-1bb102940cd1"),
            };
            var courseSearchService = new CourseSearchApiService(findACourseClient, auditService, mapper);
            var detailResponse      = await courseSearchService.GetCourseDetailsAsync(courseGetRequest.CourseId.ToString(), courseGetRequest.RunId.ToString()).ConfigureAwait(false);

            detailResponse.CourseId.Should().Be(courseGetRequest.CourseId.ToString());
        }
        public async Task CourseSearch()
        {
            var courseSearchRequest = new CourseSearchProperties()
            {
                Filters = new CourseSearchFilters {
                    SearchTerm = "maths", StartDate = StartDate.FromToday, StartDateFrom = DateTime.Today
                },
            };

            var courseSearchService = new CourseSearchApiService(this.findACourseClient, this.auditService, this.mapper);
            var searchResponse      = await courseSearchService.SearchCoursesAsync(courseSearchRequest).ConfigureAwait(false);
        }
        public async Task CompositeCourseSearch()
        {
            var courseSearchRequest = new CUIModels.CourseSearchProperties
            {
                Filters = new CUIModels.CourseSearchFilters {
                    SearchTerm = "T Level"
                },
                OrderedBy = CUIModels.CourseSearchOrderBy.RecentlyAdded,
            };

            var courseSearchService = new CourseSearchApiService(findACourseClient, auditService, mapper);
            var searchResponse      = await courseSearchService.SearchCoursesAsync(courseSearchRequest).ConfigureAwait(false);

            searchResponse.Should().NotBeNull();
        }
        public async Task CourseSearch()
        {
            var courseSearchRequest = new CourseSearchProperties
            {
                Filters = new CourseSearchFilters {
                    SearchTerm = "Surveying"
                },
                OrderedBy = CourseSearchOrderBy.Relevance,
            };

            var courseSearchService = new CourseSearchApiService(findACourseClient, auditService, mapper);
            var searchResponse      = await courseSearchService.SearchCoursesAsync(courseSearchRequest).ConfigureAwait(false);

            searchResponse.Should().NotBeNull();
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public async Task GetCourseDetailsAsyncReturnsGroupedCourseList()
        {
            // Arrange
            var dummyApiResponse  = BuildCourseRunDetailResponse();
            var findACourseClient = A.Fake <IFindACourseClient>();

            A.CallTo(() => findACourseClient.CourseGetAsync(A <CourseGetRequest> .Ignored)).Returns(dummyApiResponse);

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

            // Act
            var result = await courseSearchService.GetCourseDetailsAsync(courseId.ToString(), courseRunId.ToString()).ConfigureAwait(false);

            // Assert
            Assert.Equal(courseId.ToString(), result.CourseId);
        }
Exemplo n.º 9
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);
        }
        public async Task GetCourseDetailsAsyncReturnsTLevelDetailsList()
        {
            // Arrange
            var dummyApiResponse  = BuildTLevelResponse();
            var findACourseClient = A.Fake <IFindACourseClient>();

            A.CallTo(() => findACourseClient.TLevelGetAsync(A <string> .Ignored)).Returns(dummyApiResponse);

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

            // Act
            var result = await courseSearchService.GetTLevelDetailsAsync(tLevelId.ToString()).ConfigureAwait(false);

            // Assert
            Assert.Equal(tLevelId.ToString(), result.TLevelId.ToString());
            Assert.Equal(nameof(TLevelProvider.ProviderName), result.ProviderDetails.Name);
        }
Exemplo n.º 11
0
        public async Task SearchCoursesAsyncReturnsGroupedCourseList()
        {
            // Arrange
            var request           = BuildCourseSearchProperties();
            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.SearchCoursesAsync(request).ConfigureAwait(false);

            // Assert
            Assert.True(result.Courses.Count() == 4);
        }
        public async Task CompositeCourseTownSearch()
        {
            var courseSearchRequest = new CUIModels.CourseSearchProperties
            {
                Filters = new CUIModels.CourseSearchFilters {
                    Town = "Derby", Distance = 5, DistanceSpecified = true
                },
            };

            courseSearchRequest.Filters.CourseType.Add(CUIModels.CourseType.ClassroomBased);

            var courseSearchService = new CourseSearchApiService(findACourseClient, auditService, mapper);
            var searchResponse      = await courseSearchService.SearchCoursesAsync(courseSearchRequest).ConfigureAwait(false);

            searchResponse.Should().NotBeNull();
            searchResponse.Courses.OrderByDescending(c => c.LocationDetails.Distance).FirstOrDefault().Location.Should().Contain("Derby");
        }
Exemplo n.º 13
0
        public async Task SearchCoursesAsyncReturnsCorrectStartDateLabel()
        {
            var request          = BuildCourseSearchProperties();
            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.SearchCoursesAsync(request).ConfigureAwait(false);

            // Assert
            Assert.Equal(DateTime.UtcNow.ToString("dd MMMM yyyy", CultureInfo.InvariantCulture), result.Courses.ElementAt(0).StartDateLabel);
            Assert.Equal("Flexible", result.Courses.ElementAt(1).StartDateLabel);
            Assert.Null(result.Courses.ElementAt(2).StartDateLabel);
        }
Exemplo n.º 14
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);
        }