protected override void Arrange()
            {
                _edFiOdsInstanceIdentificationProvider = Stub <IEdFiOdsInstanceIdentificationProvider>();

                _suppliedId = Guid.NewGuid();

                _idValueMapper = Stub <IUniqueIdToIdValueMapper>();

                A.CallTo(() => _idValueMapper.GetUniqueId(A <string> .That.IsEqualTo(Staff), A <Guid> .That.IsEqualTo(_suppliedId)))
                .Returns(
                    new PersonIdentifiersValueMap
                {
                    Id       = _suppliedId,
                    UniqueId = "ABC123"
                });

                SetupCaching();

                void SetupCaching()
                {
                    _memoryCacheProvider = new MemoryCacheProvider {
                        MemoryCache = new MemoryCache(IsolatedForUnitTest)
                    };

                    _idCache = new PersonUniqueIdToIdCache(
                        _memoryCacheProvider,
                        _edFiOdsInstanceIdentificationProvider,
                        _idValueMapper);
                }
            }
예제 #2
0
        /// <summary>
        /// Gets the externally defined UniqueId for the specified type of person and the GUID-based identifier.
        /// </summary>
        /// <param name="personTypeName">The type of the person (e.g. Staff, Student, Parent).</param>
        /// <param name="id">The GUID-based identifier for the person.</param>
        /// <returns>The UniqueId value assigned to the person if found; otherwise <b>null</b>.</returns>
        public string GetUniqueId(string personTypeName, Guid id)
        {
            if (id == default(Guid))
            {
                return(default(string));
            }

            var    key = string.Format(UniqueIdByIdFormatter, CacheKeyPrefix, personTypeName, id);
            object obj;

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

            var valueMap = _uniqueIdToIdValueMapper.GetUniqueId(personTypeName, id);

            // Save the primary value
            if (valueMap.UniqueId != null)
            {
                _cacheProvider.Insert(key, valueMap.UniqueId, DateTime.MaxValue, _cacheItemPolicy.SlidingExpiration);
            }

            return(valueMap.UniqueId);
        }