public void HasAssessor_DeclaringType_And_PropertyName() { var declaringType = typeof(SimpleClass); var propertyName = "Id"; var propertyKey = new PropertyKey(declaringType, propertyName); var assessor = CreatePropertyAssessor(propertyKey); _cache.TryAdd(propertyKey, assessor); var result = PropertyAssessorCache.HasAssessor(typeof(SimpleClass), "Id"); Assert.IsTrue(result); }
public void HasAssessor_PropertyInfo() { var propertyInfo = typeof(SimpleClass).GetProperty("Id"); var propertyKey = new PropertyKey(propertyInfo); var assessor = CreatePropertyAssessor(propertyKey); _cache.TryAdd(propertyKey, assessor); propertyInfo = typeof(SimpleClass).GetProperty("Id"); var result = PropertyAssessorCache.HasAssessor(propertyInfo); Assert.IsTrue(result); }
public void GetOrAdd_DeclaringType_And_PropertyName() { var declaringType = typeof(SimpleClass); var propertyName = "Id"; var created = false; var assessor = PropertyAssessorCache.GetOrAdd(declaringType, propertyName, propertyKey => { created = true; return(CreatePropertyAssessor(propertyKey)); }); Assert.IsTrue(_cache.ContainsKey(new PropertyKey(typeof(SimpleClass), "Id"))); Assert.IsTrue(created); }
public void GetOrAdd_PropertyInfo() { var propertyInfo = typeof(SimpleClass).GetProperty("Id"); var created = false; var assessor = PropertyAssessorCache.GetOrAdd(propertyInfo, propertyKey => { created = true; return(CreatePropertyAssessor(propertyKey)); }); propertyInfo = typeof(SimpleClass).GetProperty("Id"); Assert.IsTrue(_cache.ContainsKey(new PropertyKey(propertyInfo))); Assert.IsTrue(created); }
public void GetOrAdd_DeclaringTypeAndPropertyName_WhenIsAlreadyInCache() { var propertyKey = new PropertyKey(typeof(SimpleClass), "Id"); _cache.TryAdd(propertyKey, CreatePropertyAssessor(propertyKey)); var created = false; var assessor = PropertyAssessorCache.GetOrAdd(typeof(SimpleClass), "Id", propertyKeyForCreation => { created = true; return(CreatePropertyAssessor(propertyKeyForCreation)); }); Assert.IsTrue(_cache.ContainsKey(new PropertyKey(typeof(SimpleClass), "Id"))); Assert.IsFalse(created); }
public void GetOrAdd_PropertyInfo_WhenIsAlreadyInCache() { var propertyInfo = typeof(SimpleClass).GetProperty("Id"); var created = false; var propertyKey = new PropertyKey(propertyInfo); _cache.TryAdd(propertyKey, CreatePropertyAssessor(propertyKey)); propertyInfo = typeof(SimpleClass).GetProperty("Id"); var assessor = PropertyAssessorCache.GetOrAdd(propertyInfo, propertyKeyForCreation => { created = true; return(CreatePropertyAssessor(propertyKeyForCreation)); }); propertyInfo = typeof(SimpleClass).GetProperty("Id"); Assert.IsTrue(_cache.ContainsKey(new PropertyKey(propertyInfo))); Assert.IsFalse(created); }