示例#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));
        }
示例#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));
        }