Example #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);
        }
Example #2
0
        public async Task GetLarsLearningAim_Returns_Valid_Aim()
        {
            var learnAimRef = "12345678";

            var azureLearningAim = new LearningAimModel();
            var apiLearningAim   = new Models.LearningAimModel();

            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.GetAsync <LearningAimModel>(indexServiceMock.Object, learnAimRef))
            .ReturnsAsync(azureLearningAim);

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

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

            var result = await service.GetLarsLearningAim(learnAimRef);

            mapperMock.Verify(m => m.Map(azureLearningAim), Times.Once);
            azureServiceMock.Verify(m => m.GetAsync <LearningAimModel>(indexServiceMock.Object, learnAimRef), Times.Once);

            result.Should().BeSameAs(apiLearningAim);
        }