Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }