Beispiel #1
0
        [RunAsDefaultTenant] // required because cache uses metadatacache, which uses PerUserRuleSet
        public void Test_GetMemberOfType_SingleCall(bool clear, int expect)
        {
            Mock <IScriptNameResolver> mock    = new Mock <IScriptNameResolver>(MockBehavior.Strict);
            CachingScriptNameResolver  caching = new CachingScriptNameResolver(mock.Object);
            long       typeId     = 123;
            MemberType filter     = MemberType.Field;
            string     name       = "abc";
            MemberInfo mockResult = new MemberInfo {
                MemberId = 456, MemberType = MemberType.Field
            };

            mock.Setup(r => r.GetMemberOfType(name, typeId, filter)).Returns(mockResult);

            MemberInfo result;

            result = caching.GetMemberOfType(name, typeId, filter);
            Assert.That(result, Is.EqualTo(mockResult));
            if (clear)
            {
                caching.Clear();
            }

            result = caching.GetMemberOfType(name, typeId, filter);
            Assert.That(result, Is.EqualTo(mockResult));

            mock.Verify(r => r.GetMemberOfType(name, typeId, filter), Times.Exactly(expect));
        }
Beispiel #2
0
        [RunAsDefaultTenant] // required because cache uses metadatacache, which uses PerUserRuleSet
        public void Test_GetTypeByName_SingleCall(bool clear, int expect)
        {
            Mock <IScriptNameResolver> mock    = new Mock <IScriptNameResolver>(MockBehavior.Strict);
            CachingScriptNameResolver  caching = new CachingScriptNameResolver(mock.Object);

            mock.Setup(r => r.GetTypeByName("Name1")).Returns(123);


            long result;

            result = caching.GetTypeByName("Name1");
            Assert.That(result, Is.EqualTo(123));
            if (clear)
            {
                caching.Clear();
            }

            result = caching.GetTypeByName("Name1");
            Assert.That(result, Is.EqualTo(123));

            mock.Verify(r => r.GetTypeByName("Name1"), Times.Exactly(expect));
        }
Beispiel #3
0
        public void ScriptNameResolver_Instance()
        {
            // Check caching resolver
            IScriptNameResolver instance = Factory.ScriptNameResolver;

            Assert.That(instance, Is.InstanceOf <CachingScriptNameResolver>());

            // Check inner resolver
            CachingScriptNameResolver cachingResolver = instance as CachingScriptNameResolver;
            IScriptNameResolver       innerProvider   = cachingResolver.InnerProvider;

            Assert.That(innerProvider, Is.InstanceOf <ScriptNameResolver>());

            // Check inner has graph entity repository
            ScriptNameResolver resolver = innerProvider as ScriptNameResolver;
            Type graphRepositoryType    = Factory.GraphEntityRepository.GetType();

            Assert.That(resolver.EntityRepository, Is.InstanceOf(graphRepositoryType));

            // Check inner has query runner (and not the caching one)
            Type nonCachingQueryRunnerType = Factory.Current.ResolveKeyed <IQueryRunner>(Factory.NonCachedKey).GetType();

            Assert.That(resolver.QueryRunner, Is.InstanceOf(nonCachingQueryRunnerType));
        }