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);
                }
            }
 public void Should_call_the_id_value_mapper_for_the_id()
 {
     A.CallTo(
         () => _idValueMapper.GetId(
             A <string> .That.IsEqualTo(Staff), A <string> .That.IsEqualTo(_suppliedIdValueMap.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());

                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);
            }
Пример #4
0
        /// <summary>
        /// Gets the GUID-based identifier for the specified type of person and their UniqueId value.
        /// </summary>
        /// <param name="personTypeName">The type of the person (e.g. Staff, Student, Parent).</param>
        /// <param name="uniqueId">The UniqueId value associated with the person.</param>
        /// <returns>The GUID-based identifier for the person; otherwise the default GUID value.</returns>
        public Guid GetId(string personTypeName, string uniqueId)
        {
            if (string.IsNullOrWhiteSpace(uniqueId))
            {
                return(default(Guid));
            }

            var    key = string.Format(IdByUniqueIdFormatter, CacheKeyPrefix, personTypeName, uniqueId);
            object obj;

            if (_cacheProvider.TryGetCachedObject(key, out obj))
            {
                return((Guid)obj);
            }

            var valueMap = _uniqueIdToIdValueMapper.GetId(personTypeName, uniqueId);

            // Save the primary value
            if (valueMap.Id != default(Guid))
            {
                _cacheProvider.Insert(key, valueMap.Id, DateTime.MaxValue, _cacheItemPolicy.SlidingExpiration);

                var idToUniqueIdKey = string.Format(UniqueIdByIdFormatter, CacheKeyPrefix, personTypeName, valueMap.Id);

                if (!_cacheProvider.TryGetCachedObject(idToUniqueIdKey, out obj))
                {
                    _cacheProvider.Insert(idToUniqueIdKey, uniqueId, DateTime.MaxValue, _cacheItemPolicy.SlidingExpiration);
                }
            }

            return(valueMap.Id);
        }
            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);
                }
            }