public async Task GetFundingByFundingResultId_GivenResultFound_ReturnsContentResult()
        {
            //Arrange
            string resultId        = "12345";
            string documentPath    = "Round the ragged rocks the ragged rascal ran";
            string fundingDocument = "Now is the time for all good men to come to the aid of the party.";

            PublishedFundingIndex publishedFundingIndex = CreatePublishedFundingResult();

            publishedFundingIndex.DocumentPath = documentPath;

            ISearchRepository <PublishedFundingIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .SearchById(Arg.Is(resultId))
            .Returns(publishedFundingIndex);

            IPublishedFundingRetrievalService publishedFundingRetrievalService = Substitute.For <IPublishedFundingRetrievalService>();

            publishedFundingRetrievalService
            .GetFundingFeedDocument(documentPath)
            .Returns(fundingDocument);

            FundingFeedItemByIdService service = CreateService(searchRepository: searchRepository,
                                                               publishedFundingRetrievalService: publishedFundingRetrievalService);

            //Act
            IActionResult result = await service.GetFundingByFundingResultId(resultId);

            //Assert
            result
            .Should().BeOfType <ContentResult>()
            .Which
            .StatusCode
            .Should().Be((int)HttpStatusCode.OK);

            await searchRepository
            .Received(1)
            .SearchById(resultId);

            await publishedFundingRetrievalService
            .Received(1)
            .GetFundingFeedDocument(documentPath);

            ContentResult contentResult = result as ContentResult;

            contentResult.Content
            .Should().Be(fundingDocument);
            contentResult.ContentType
            .Should().Be("application/json");
        }
        public async Task GetFundingByFundingResultId_GivenRepoReturnsNothing_ReturnsNotFoundResult()
        {
            //Arrange
            string resultId = "12345";

            ISearchRepository <PublishedFundingIndex> searchRepository = CreateSearchRepository();

            FundingFeedItemByIdService service = CreateService(
                searchRepository: searchRepository);

            //Act
            IActionResult result = await service.GetFundingByFundingResultId(resultId);

            //Assert
            result
            .Should().BeOfType <NotFoundResult>();

            await searchRepository
            .Received(1)
            .SearchById(resultId);
        }
        public async Task GetFundingByFundingResultId_GivenNullResultFound_ReturnsNotFound()
        {
            //Arrange
            string fundingResultId = "12345";

            ISearchRepository <PublishedFundingIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .SearchById(Arg.Is(fundingResultId))
            .Returns(CreatePublishedFundingResult());

            FundingFeedItemByIdService service = CreateService(searchRepository: searchRepository);

            //Act
            IActionResult result = await service.GetFundingByFundingResultId(fundingResultId);

            //Assert
            result
            .Should()
            .BeOfType <NotFoundResult>();
        }
        public async Task GetFundingByFundingResultId_GivenEmptyResultFound_ReturnsNotFoundResult(string document)
        {
            //Arrange
            string resultId     = "12345";
            string documentPath = "Round the ragged rocks the ragged rascal ran";

            PublishedFundingIndex publishedFundingIndex = CreatePublishedFundingResult();

            publishedFundingIndex.DocumentPath = documentPath;

            ISearchRepository <PublishedFundingIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .SearchById(Arg.Is(resultId))
            .Returns(publishedFundingIndex);

            IPublishedFundingRetrievalService publishedFundingRetrievalService = Substitute.For <IPublishedFundingRetrievalService>();

            publishedFundingRetrievalService
            .GetFundingFeedDocument(documentPath)
            .Returns(document);

            FundingFeedItemByIdService service = CreateService(searchRepository: searchRepository,
                                                               publishedFundingRetrievalService: publishedFundingRetrievalService);

            //Act
            IActionResult result = await service.GetFundingByFundingResultId(resultId);

            //Assert
            result
            .Should().BeOfType <NotFoundResult>();

            await searchRepository
            .Received(1)
            .SearchById(resultId);
        }