Exemplo n.º 1
0
        public void SpecificationToSpecificationIndexMapping()
        {
            Specification specification = NewSpecification(_ => _.WithCurrent(NewSpecificationVersion(curr =>
                                                                                                      curr.WithFundingStreamsIds(NewRandomString(), NewRandomString())
                                                                                                      .WithDataDefinitionRelationshipIds(NewRandomString(), NewRandomString(), NewRandomString()))));

            SpecificationIndex searchIndex = WhenTheSourceItemsAreMapped(specification).Single();

            searchIndex
            .Should()
            .BeEquivalentTo(new SpecificationIndex
            {
                Id                            = specification.Id,
                Name                          = specification.Name,
                FundingPeriodId               = specification.Current.FundingPeriod.Id,
                FundingPeriodName             = specification.Current.FundingPeriod.Name,
                FundingStreamIds              = specification.Current.FundingStreams.Select(_ => _.Id).ToArray(),
                FundingStreamNames            = specification.Current.FundingStreams.Select(_ => _.Name).ToArray(),
                Description                   = specification.Current.Description,
                LastUpdatedDate               = specification.Current.Date,
                IsSelectedForFunding          = specification.IsSelectedForFunding,
                DataDefinitionRelationshipIds = specification.Current.DataDefinitionRelationshipIds.ToArray(),
                Status                        = specification.Current.PublishStatus.ToString()
            }, opt => opt.ComparingByMembers <Reference>());
        }
Exemplo n.º 2
0
        public void SpecificationSearchModelToSpecificationIndexMapping()
        {
            SpecificationSearchModel specificationSearchModel = NewSpecificationSearchModel(_ => _.WithFundingPeriod(NewFundingPeriod())
                                                                                            .WithDataDefinitionRelationshipIds(NewRandomString(), NewRandomString())
                                                                                            .WithFundingStreams(NewFundingStream(), NewFundingStream()));


            SpecificationIndex searchIndex = WhenTheSourceItemsAreMapped(specificationSearchModel).Single();

            searchIndex
            .Should()
            .BeEquivalentTo(new SpecificationIndex
            {
                Id                            = specificationSearchModel.Id,
                Name                          = specificationSearchModel.Name,
                FundingPeriodId               = specificationSearchModel.FundingPeriod.Id,
                FundingPeriodName             = specificationSearchModel.FundingPeriod.Name,
                FundingStreamIds              = specificationSearchModel.FundingStreams.Select(_ => _.Id).ToArray(),
                FundingStreamNames            = specificationSearchModel.FundingStreams.Select(_ => _.Name).ToArray(),
                Description                   = specificationSearchModel.Description,
                LastUpdatedDate               = specificationSearchModel.UpdatedAt,
                DataDefinitionRelationshipIds = specificationSearchModel.DataDefinitionRelationshipIds.ToArray(),
                Status                        = specificationSearchModel.PublishStatus,
                IsSelectedForFunding          = specificationSearchModel.IsSelectedForFunding
            }, opt => opt.ComparingByMembers <Reference>());
        }
        public async Task SearchById_GivenIdDoesNotReturnSearchResult_ReturnsNull()
        {
            SearchRepositorySettings searchRepositorySettings = new SearchRepositorySettings
            {
                SearchKey         = string.Empty,
                SearchServiceName = string.Empty
            };

            ISearchInitializer searchInitializer = Substitute.For <ISearchInitializer>();

            ISearchIndexClient searchIndexClient = Substitute.For <ISearchIndexClient>();

            AzureOperationResponse <DocumentSearchResult <SpecificationIndex> > documentSearchResult =
                new AzureOperationResponse <DocumentSearchResult <SpecificationIndex> >
            {
                Body = new DocumentSearchResult <SpecificationIndex>(null, null, null, null, null)
            };

            IDocumentsOperations documentsOperations = Substitute.For <IDocumentsOperations>();

            documentsOperations.SearchWithHttpMessagesAsync <SpecificationIndex>(Arg.Any <string>(), Arg.Any <SearchParameters>()).Returns(Task.FromResult(documentSearchResult));

            ISearchServiceClient searchServiceClient = Substitute.For <ISearchServiceClient>();

            searchIndexClient.Documents.Returns(documentsOperations);

            SearchRepository <SpecificationIndex> searchRepository = new SearchRepository <SpecificationIndex>(searchRepositorySettings, searchInitializer, searchServiceClient, searchIndexClient);

            string notFoundId = "notFound";

            SpecificationIndex specificationIndex = await searchRepository.SearchById(notFoundId);

            specificationIndex.Should().BeNull();
        }
        public async Task SearchById_GivenIdReturnsSearchResult_ReturnsResults()
        {
            string existingId = "existingId";

            SearchRepositorySettings searchRepositorySettings = new SearchRepositorySettings
            {
                SearchKey         = string.Empty,
                SearchServiceName = string.Empty
            };

            ISearchInitializer searchInitializer = Substitute.For <ISearchInitializer>();

            ISearchIndexClient searchIndexClient = Substitute.For <ISearchIndexClient>();

            Microsoft.Azure.Search.Models.SearchResult <SpecificationIndex> specificationIndexSearchResult = new Microsoft.Azure.Search.Models.SearchResult <SpecificationIndex>(new SpecificationIndex
            {
                Id = existingId
            });

            AzureOperationResponse <DocumentSearchResult <SpecificationIndex> > documentSearchResult =
                new AzureOperationResponse <DocumentSearchResult <SpecificationIndex> >
            {
                Body = new DocumentSearchResult <SpecificationIndex>(new[]
                {
                    specificationIndexSearchResult
                },
                                                                     null,
                                                                     null,
                                                                     null,
                                                                     null)
            };

            IDocumentsOperations documentsOperations = Substitute.For <IDocumentsOperations>();

            documentsOperations
            .SearchWithHttpMessagesAsync <SpecificationIndex>(Arg.Is <string>(_ => _ == $"\"{existingId}\""),
                                                              Arg.Is <SearchParameters>(_ => _.SearchFields.SequenceEqual(new[]
            {
                "id"
            })))
            .Returns(Task.FromResult(documentSearchResult));

            ISearchServiceClient searchServiceClient = Substitute.For <ISearchServiceClient>();

            searchIndexClient.Documents.Returns(documentsOperations);

            SearchRepository <SpecificationIndex> searchRepository = new SearchRepository <SpecificationIndex>(searchRepositorySettings, searchInitializer, searchServiceClient, searchIndexClient);

            SpecificationIndex specificationIndex = await searchRepository.SearchById(existingId);

            specificationIndex.Should().NotBeNull();
            specificationIndex.Id.Should().Be(existingId);
        }