Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }