Пример #1
0
        public async Task GetLarsLearningDeliveries_Returns_Valid_Aims()
        {
            var learnAimRef      = "12345678";
            var azureLearningAim = new LearningAimModel
            {
                LearnAimRef = learnAimRef
            };
            var apiLearningAim = new Models.LearningAimModel
            {
                LearnAimRef = learnAimRef
            };

            var searchModel = new LearningAimsSearchModel
            {
                SearchTerm = learnAimRef
            };

            var searchResult = new DocumentSearchResult <LearningAimModel>(
                new List <SearchResult <LearningAimModel> >
            {
                new SearchResult <LearningAimModel>(azureLearningAim)
            },
                1,
                0,
                null,
                SearchContinuationToken.CreateTestToken("foo"));

            var mapperMock = new Mock <IMapper <LearningAimModel, Models.LearningAimModel> >();

            mapperMock.Setup(m => m.Map(azureLearningAim)).Returns(apiLearningAim);

            var indexServiceMock = new Mock <ILearningDeliveryIndexService>();

            var azureServiceMock = new Mock <IAzureService>();

            azureServiceMock
            .Setup(m => m.SearchIndexAsync <LearningAimModel>(indexServiceMock.Object, learnAimRef, It.IsAny <SearchParameters>()))
            .ReturnsAsync(searchResult);

            var queryServiceMock = new Mock <IODataQueryService>();
            var searchTermFormattingServiceMock = new Mock <ISearchTermFormattingService>();

            searchTermFormattingServiceMock
            .Setup(f => f.FormatSearchTerm(learnAimRef))
            .Returns(learnAimRef);

            var service = new AzureLearningAimsService(
                mapperMock.Object,
                indexServiceMock.Object,
                queryServiceMock.Object,
                azureServiceMock.Object,
                searchTermFormattingServiceMock.Object);

            var result = (await service.GetLarsLearningDeliveries(searchModel)).ToList();

            azureServiceMock.Verify(m => m.SearchIndexAsync <LearningAimModel>(indexServiceMock.Object, learnAimRef, It.IsAny <SearchParameters>()), Times.Once);

            result.Should().HaveCount(1);
            result.Single().Should().BeSameAs(apiLearningAim);
        }
        public async Task GetDownloadDetails_Returns_Correct_Data()
        {
            var key = "*";

            var searchResult = new DocumentSearchResult <DownloadDetailsModel>(
                PopulateDownloadsData(),
                1,
                0,
                null,
                SearchContinuationToken.CreateTestToken("foo"));

            var clientMock = new Mock <IDownloadsIndexService>();

            var azureServiceMock = new Mock <IAzureService>();
            var searchTermFormattingServiceMock = new Mock <ISearchTermFormattingService>();

            azureServiceMock
            .Setup(m => m.SearchIndexAsync <DownloadDetailsModel>(clientMock.Object, key, It.IsAny <SearchParameters>()))
            .ReturnsAsync(searchResult);

            var mapper  = new AzureDownloadDataMapper();
            var service = new AzureDownloadsService(azureServiceMock.Object, mapper, clientMock.Object, searchTermFormattingServiceMock.Object);

            var result = (await service.GetDownloadDetails(key)).ToList();

            result.Count.Should().Be(6);
            result[0].Id.Should().Be("4");
            result[1].Id.Should().Be("8");
            result[2].Id.Should().Be("12");
            result[3].Id.Should().Be("2");
            result[4].Id.Should().Be("6");
            result[5].Id.Should().Be("10");
        }