/// <summary> /// Gets the entity definition for the supplied name. /// </summary> /// <param name="name">Name of the entity definition to return.</param> /// <returns>Entity definition for the supplied name.</returns> /// <exception cref="CacheNotInitializedException">Throws when cache provider is not initialized through constructor.</exception> public DSEntityType Get(string name) { if (_cache == null) { throw new CacheNotInitializedException("Cache provider is not set."); } var cacheKey = Key(name); if (!_cache.Contains(cacheKey)) { var newEntityType = _resolver.Get(name); _cache.Set(cacheKey, newEntityType); return(newEntityType); } var entityType = _cache.Get(cacheKey) as DSEntityType; return(entityType); }
public void TestGet() { foreach (var entityTypeName in _entityTypeResolver.Types) { Assert.IsFalse(_cache.Contains(GetKey(entityTypeName)), string.Format("Should not exist in cache yet: {0}.", entityTypeName)); } foreach (var entityTypeName in _entityTypeResolver.Types) { var entityType = _entityTypeRepository.Get(entityTypeName); Assert.IsTrue(_cache.Contains(GetKey(entityTypeName)), string.Format("Should have been loaded to cache: {0}.", entityTypeName)); } }