コード例 #1
0
 protected override void Because_of()
 {
     this.searchResult = new SearchResult(new List <int>(), DateTime.Now, false, null);
     this.Sut.Add("key", this.searchResult);
     Thread.Sleep(200);
     this.searchResultPage = this.Sut.Get("key", 1);
 }
コード例 #2
0
        MdmService <EnergyTrading.MDM.Contracts.Sample.Party, Party, PartyMapping, PartyDetails, EnergyTrading.MDM.Contracts.Sample.PartyDetails> Establish_context()
        {
            this.validatorStub     = new Mock <IValidatorEngine>();
            this.mappingEngineStub = new Mock <IMappingEngine>();
            this.repositoryStub    = new Mock <IRepository>();
            this.cacheStub         = new Mock <ISearchCache>();

            this.resultsKey   = Guid.NewGuid().ToString();
            this.pageNumber   = 1;
            this.cacheResults = new CacheSearchResultPage(new List <int> {
                1
            }, DateTime.Now, null, this.resultsKey);
            this.cacheStub.Setup(cache => cache.Get(this.resultsKey, this.pageNumber)).Returns(this.cacheResults);

            var party = new Party()
            {
                Id = 1,
            };

            party.AddDetails(new PartyDetails()
            {
                Validity = new EnergyTrading.DateRange()
            });

            var entities = new List <Party> {
                party
            }.AsQueryable();

            this.repositoryStub.Setup(x => x.Queryable <Party>()).Returns(entities);
            return(new PartyService(
                       this.validatorStub.Object,
                       this.mappingEngineStub.Object,
                       this.repositoryStub.Object,
                       this.cacheStub.Object));
        }
コード例 #3
0
        protected override void Because_of()
        {
            var bobSmith = new EnergyTrading.Mdm.Contracts.SourceSystem()
            {
                Details = new EnergyTrading.Mdm.Contracts.SourceSystemDetails()
                {
                    Name = "Bob"
                }
            };

            var fredJones = new EnergyTrading.Mdm.Contracts.SourceSystem()
            {
                Details = new EnergyTrading.Mdm.Contracts.SourceSystemDetails()
                {
                    Name = "Fred"
                }
            };

            var personList = new List <EnergyTrading.Mdm.Contracts.SourceSystem>()
            {
                bobSmith, fredJones
            };

            var cacheSearchResultPage = new CacheSearchResultPage(new List <int>()
            {
                1, 2
            }, DateTime.Now, null, this.currentSearch.ToString());
            var searchResultPage = new SearchResultPage <EnergyTrading.Mdm.Contracts.SourceSystem>(cacheSearchResultPage, personList);

            this.response = this.Sut.WithEntityName("SourceSystem").WithItems(searchResultPage.Contracts).Build();
        }
コード例 #4
0
        protected override void Because_of()
        {
            var bobSmith = new EnergyTrading.MDM.Contracts.Sample.Person()
            {
                Details = new EnergyTrading.MDM.Contracts.Sample.PersonDetails()
                {
                    Forename = "Bob", Surname = "Smith"
                }
            };

            var fredJones = new EnergyTrading.MDM.Contracts.Sample.Person()
            {
                Details = new EnergyTrading.MDM.Contracts.Sample.PersonDetails()
                {
                    Forename = "Fred", Surname = "Jones"
                }
            };

            var personList = new List <EnergyTrading.MDM.Contracts.Sample.Person>()
            {
                bobSmith, fredJones
            };

            var cacheSearchResultPage = new CacheSearchResultPage(new List <int>()
            {
                1, 2
            }, DateTime.Now, null, this.currentSearch.ToString());
            var searchResultPage = new SearchResultPage <EnergyTrading.MDM.Contracts.Sample.Person>(cacheSearchResultPage, personList);

            this.response = this.Sut.CreateFeed(searchResultPage, "Person", this.baseUri);
        }
コード例 #5
0
        public void ShouldReturnOrderedSearchResultsFromCache()
        {
            // Given
            var mockValidationEngine = new Mock <IValidatorEngine>();
            var mockMappingEngine    = new Mock <IMappingEngine>();
            var mockRepository       = new Mock <IRepository>();
            var mockSearchCache      = new Mock <ISearchCache>();
            var abcService           = new AbcEntityTestService(mockValidationEngine.Object, mockMappingEngine.Object, mockRepository.Object, mockSearchCache.Object);

            // When

            // ids are stored in a specific order
            var ids = new List <int> {
                1, 100, 50
            };
            var cacheSearchResultsPage = new CacheSearchResultPage(ids, DateTime.Now, 2, "abc");

            mockSearchCache.Setup(x => x.Get("abc", 1)).Returns(cacheSearchResultsPage);

            // entities are returned in a different order
            var entities = new List <AbcEntity>
            {
                new AbcEntity {
                    Id = 100, Validity = new DateRange()
                },
                new AbcEntity {
                    Id = 50, Validity = new DateRange()
                },
                new AbcEntity {
                    Id = 1, Validity = new DateRange()
                }
            };

            var details = new AbcEntityDetails {
                Validity = new DateRange()
            };

            foreach (var abcEntity in entities)
            {
                abcEntity.AddDetails(details);
            }

            mockRepository.Setup(x => x.Queryable <AbcEntity>()).Returns(entities.AsQueryable());

            var searchResultsPage = abcService.GetSearchResults("abc", 1);

            Assert.AreEqual("abc", searchResultsPage.SearchResultsKey);
            Assert.AreEqual(2, searchResultsPage.NextPage);
            Assert.AreEqual(3, searchResultsPage.Contracts.Count);
            Assert.AreEqual(1, searchResultsPage.Contracts[0].ToMdmKey());
            Assert.AreEqual(100, searchResultsPage.Contracts[1].ToMdmKey());
            Assert.AreEqual(50, searchResultsPage.Contracts[2].ToMdmKey());
        }
コード例 #6
0
 protected static string AggregateIds(CacheSearchResultPage searchResultPage)
 {
     return(searchResultPage.EntityIds.Aggregate(string.Empty, (x, y) => string.Concat(x, y.ToString(CultureInfo.InvariantCulture))));
 }