public void Should_call_usi_value_mapper_for_the_usi() { A.CallTo( () => _usiValueMapper.GetUsi( A <string> .That.IsEqualTo(Staff), A <string> .That.IsEqualTo(_suppliedUsiValueMap.UniqueId))) .MustHaveHappened(); }
protected override void Arrange() { _edFiOdsInstanceIdentificationProvider = Stub <IEdFiOdsInstanceIdentificationProvider>(); _personIdentifiersProvider = Stub <IPersonIdentifiersProvider>(); A.CallTo(() => _personIdentifiersProvider.GetAllPersonIdentifiers(A <string> ._)) .Returns(Task.Run(() => (IEnumerable <PersonIdentifiersValueMap>) new PersonIdentifiersValueMap[0])); _usiValueMapper = Stub <IUniqueIdToUsiValueMapper>(); A.CallTo(() => _usiValueMapper.GetUsi(A <string> ._, A <string> ._)) .Returns(new PersonIdentifiersValueMap()); _idValueMapper = Stub <IUniqueIdToIdValueMapper>(); A.CallTo(() => _idValueMapper.GetId(A <string> ._, A <string> ._)) .Returns(new PersonIdentifiersValueMap()); SetupCaching(); void SetupCaching() { _memoryCacheProvider = new MemoryCacheProvider { MemoryCache = new MemoryCache(IsolatedForUnitTest) }; _usiCache = new PersonUniqueIdToUsiCache( _memoryCacheProvider, _edFiOdsInstanceIdentificationProvider, _usiValueMapper, _personIdentifiersProvider, TimeSpan.Zero, TimeSpan.Zero, synchronousInitialization: true); } }
protected override void Arrange() { _edFiOdsInstanceIdentificationProvider = Stub <IEdFiOdsInstanceIdentificationProvider>(); _personIdentifiersProvider = Stub <IPersonIdentifiersProvider>(); A.CallTo(() => _personIdentifiersProvider.GetAllPersonIdentifiers(A <string> ._)) .Returns(Task.Run(() => (IEnumerable <PersonIdentifiersValueMap>) new PersonIdentifiersValueMap[0])); _usiValueMapper = Stub <IUniqueIdToUsiValueMapper>(); A.CallTo(() => _usiValueMapper.GetUsi(A <string> ._, A <string> ._)).Returns(new PersonIdentifiersValueMap()); _idValueMapper = Stub <IUniqueIdToIdValueMapper>(); A.CallTo(() => _idValueMapper.GetId(A <string> ._, A <string> ._)) .Returns(new PersonIdentifiersValueMap()); var memorycacheoption = A.Fake <IOptions <MemoryCacheOptions> >(); MemoryCache memoryCache = new MemoryCache(memorycacheoption); _memoryCacheProvider = new MemoryCacheProvider(memoryCache); _usiCache = new PersonUniqueIdToUsiCache( _memoryCacheProvider, _edFiOdsInstanceIdentificationProvider, _usiValueMapper, _personIdentifiersProvider, TimeSpan.Zero, TimeSpan.Zero, synchronousInitialization: true); }
public void Should_have_opportunistically_cached_the_usi_from_the_value_mapper() { // Value was cached opportunistically by initial call, so no call necessary A.CallTo( () => _usiValueMapper.GetUsi( A <string> .That.IsEqualTo(Staff), A <string> .That.IsEqualTo(_suppliedUsiValueMap.UniqueId))) .MustNotHaveHappened(); }
protected override void Arrange() { _edfiOdsInstanceIdentificationProvider = Stub <IEdFiOdsInstanceIdentificationProvider>(); _usiValueMapper = Stub <IUniqueIdToUsiValueMapper>(); _suppliedUsiValueMap = new PersonIdentifiersValueMap { UniqueId = Guid.NewGuid() .ToString(), Usi = 10, Id = Guid.NewGuid() // Id is also provided by the USI value mapper }; A.CallTo(() => _usiValueMapper.GetUsi(A <string> ._, A <string> ._)) .Returns(_suppliedUsiValueMap); _personIdentifiersProvider = Stub <IPersonIdentifiersProvider>(); A.CallTo(() => _personIdentifiersProvider.GetAllPersonIdentifiers(A <string> ._)) .Returns(Task.Run(() => (IEnumerable <PersonIdentifiersValueMap>) new PersonIdentifiersValueMap[0])); SetupCaching(); void SetupCaching() { var memorycacheoption = A.Fake <IOptions <MemoryCacheOptions> >(); MemoryCache memoryCache = new MemoryCache(memorycacheoption); _memoryCacheProvider = new MemoryCacheProvider(memoryCache); _usiCache = new PersonUniqueIdToUsiCache( _memoryCacheProvider, _edfiOdsInstanceIdentificationProvider, _usiValueMapper, _personIdentifiersProvider, TimeSpan.Zero, TimeSpan.Zero, synchronousInitialization: true); PersonUniqueIdToUsiCache.GetCache = () => _usiCache; } }
protected override void Arrange() { _edFiOdsInstanceIdentificationProvider = new FakeEdFiOdsInstanceIdentificationProvider(); _personIdentifiersProvider = Stub <IPersonIdentifiersProvider>(); A.CallTo(() => _personIdentifiersProvider.GetAllPersonIdentifiers(A <string> ._)) .Returns(Task.Run(() => (IEnumerable <PersonIdentifiersValueMap>) new PersonIdentifiersValueMap[0])); _suppliedIdForUniqueIdABC123 = Guid.NewGuid(); // USI value mapper gets call twice during Act step, with first value on ODS instance 1, and second on ODS instance 2 _usiValueMapper = Stub <IUniqueIdToUsiValueMapper>(); A.CallTo(() => _usiValueMapper.GetUsi(A <string> .That.IsEqualTo(Staff), A <string> .That.IsEqualTo("ABC123"))) .Returns( new PersonIdentifiersValueMap { UniqueId = "ABC123", Usi = 11 }).Once(); A.CallTo(() => _usiValueMapper.GetUsi(A <string> .That.IsEqualTo(Staff), A <string> .That.IsEqualTo("ABC123"))) .Returns( new PersonIdentifiersValueMap { UniqueId = "ABC123", Usi = 22 }).Once(); _idValueMapper = Stub <IUniqueIdToIdValueMapper>(); A.CallTo(() => _idValueMapper.GetId(A <string> .That.IsEqualTo(Staff), A <string> .That.IsEqualTo("ABC123"))) .Returns( new PersonIdentifiersValueMap { UniqueId = "ABC123", Id = _suppliedIdForUniqueIdABC123 }).Once(); SetupCaching(); void SetupCaching() { _memoryCacheProvider = new MemoryCacheProvider { MemoryCache = new MemoryCache(IsolatedForUnitTest) }; _idCache = new PersonUniqueIdToIdCache( _memoryCacheProvider, _edFiOdsInstanceIdentificationProvider, _idValueMapper); _usiCache = new PersonUniqueIdToUsiCache( _memoryCacheProvider, _edFiOdsInstanceIdentificationProvider, _usiValueMapper, _personIdentifiersProvider, TimeSpan.Zero, TimeSpan.Zero, synchronousInitialization: true); } }
protected override void Arrange() { _edfiOdsInstanceIdentificationProvider = Stub <IEdFiOdsInstanceIdentificationProvider>(); _idValueMapper = Stub <IUniqueIdToIdValueMapper>(); _usiValueMapper = Stub <IUniqueIdToUsiValueMapper>(); _personIdentifiersProvider = Stub <IPersonIdentifiersProvider>(); _suppliedUsiValueMap = new PersonIdentifiersValueMap { UniqueId = Guid.NewGuid() .ToString(), Usi = 10, Id = Guid.NewGuid() // Id is also provided by the USI value mapper }; _suppliedPersonIdentifiers = new List <PersonIdentifiersValueMap> { new PersonIdentifiersValueMap { UniqueId = Guid.NewGuid() .ToString(), Usi = 100, Id = Guid.NewGuid() }, new PersonIdentifiersValueMap { UniqueId = Guid.NewGuid() .ToString(), Usi = 101, Id = Guid.NewGuid() } }; A.CallTo(() => _idValueMapper.GetId(A <string> ._, A <string> ._)) .Returns(new PersonIdentifiersValueMap()); A.CallTo(() => _usiValueMapper.GetUsi(A <string> ._, A <string> ._)) .Returns(_suppliedUsiValueMap); A.CallTo(() => _personIdentifiersProvider.GetAllPersonIdentifiers(A <string> ._)) .Returns(Task.Run(() => (IEnumerable <PersonIdentifiersValueMap>)_suppliedPersonIdentifiers)); SetupCaching(); void SetupCaching() { _memoryCacheProvider = new MemoryCacheProvider { MemoryCache = new MemoryCache(IsolatedForUnitTest) }; _idCache = new PersonUniqueIdToIdCache( _memoryCacheProvider, _edfiOdsInstanceIdentificationProvider, _idValueMapper); _usiCache = new PersonUniqueIdToUsiCache( _memoryCacheProvider, _edfiOdsInstanceIdentificationProvider, _usiValueMapper, _personIdentifiersProvider, TimeSpan.Zero, TimeSpan.Zero, synchronousInitialization: true); PersonUniqueIdToUsiCache.GetCache = () => _usiCache; } }
protected override void Arrange() { _edfiOdsInstanceIdentificationProvider = Stub <IEdFiOdsInstanceIdentificationProvider>(); _idValueMapper = Stub <IUniqueIdToIdValueMapper>(); _usiValueMapper = Stub <IUniqueIdToUsiValueMapper>(); _personIdentifiersProvider = Stub <IPersonIdentifiersProvider>(); // usi value mapper _suppliedUsiValueMap = new PersonIdentifiersValueMap { UniqueId = Guid.NewGuid() .ToString(), Usi = 10 }; A.CallTo(() => _usiValueMapper.GetUsi(A <string> ._, A <string> ._)) .Returns(_suppliedUsiValueMap); // id value mapper _suppliedIdValueMap = new PersonIdentifiersValueMap { UniqueId = _suppliedUsiValueMap.UniqueId, // Same uniqueId Id = Guid.NewGuid() }; A.CallTo(() => _idValueMapper.GetId(A <string> ._, A <string> ._)) .Returns(_suppliedIdValueMap); _suppliedPersonIdentifiersValueMap = new PersonIdentifiersValueMap { UniqueId = Guid.NewGuid() .ToString(), Usi = 100 }; A.CallTo(() => _personIdentifiersProvider.GetAllPersonIdentifiers(A <string> ._)) .Returns( Task.Run( () => { //Force slight delay during initialization to mimic real behavior. Thread.Sleep(10); return ((IEnumerable <PersonIdentifiersValueMap>) new[] { _suppliedPersonIdentifiersValueMap }); } )); SetupCaching(); void SetupCaching() { _memoryCacheProvider = new MemoryCacheProvider { MemoryCache = new MemoryCache(IsolatedForUnitTest) }; _idCache = new PersonUniqueIdToIdCache( _memoryCacheProvider, _edfiOdsInstanceIdentificationProvider, _idValueMapper); _usiCache = new PersonUniqueIdToUsiCache( _memoryCacheProvider, _edfiOdsInstanceIdentificationProvider, _usiValueMapper, _personIdentifiersProvider, TimeSpan.Zero, TimeSpan.Zero, synchronousInitialization: false); } }