示例#1
0
        public void InitialiseProfanities_ValidDB_ReturnsFilledObject()
        {
            var modclassId = new Queue<int>();
            modclassId.Enqueue(1);
            modclassId.Enqueue(2);
            modclassId.Enqueue(2);
            var profanity = new Queue<string>();
            profanity.Enqueue("hello");
            profanity.Enqueue("hello1");
            profanity.Enqueue("hello");
            var refer = new Queue<byte>();
            refer.Enqueue(1);
            refer.Enqueue(0);
            refer.Enqueue(1);

            var cache = _mocks.DynamicMock<ICacheManager>();
            cache.Stub(x => x.Contains("")).Constraints(Is.Anything()).Return(false);

            var reader = _mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.Read()).Return(true).Repeat.Times(3);
            reader.Stub(x => x.GetInt32("ModClassID")).Return(0).WhenCalled(x => x.ReturnValue = modclassId.Dequeue());
            reader.Stub(x => x.GetStringNullAsEmpty("Profanity")).Return("").WhenCalled(x => x.ReturnValue = profanity.Dequeue());
            reader.Stub(x => x.GetByte("Refer")).Return(1).WhenCalled(x => x.ReturnValue = refer.Dequeue());


            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getallprofanities")).Return(reader);

            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var profanityObj = new ProfanityFilter(creator, diag, cache, null, null);

            Assert.AreEqual(2, profanityObj.GetObjectFromCache().ProfanityClasses.ModClassProfanities.Keys.Count);
            creator.AssertWasCalled(x => x.CreateDnaDataReader("getallprofanities"));
        }
示例#2
0
        public void GetTermsStats_GetsValidStats_ReturnsValidObject()
        {
            var cacheObj = GetProfanityCacheObject();

            var cache = _mocks.DynamicMock<ICacheManager>();
            cache.Stub(x => x.Contains(ProfanityFilter.GetCacheKey("LASTUPDATE"))).Return(false);
            cache.Stub(x => x.Contains(ProfanityFilter.GetCacheKey())).Return(true);
            cache.Stub(x => x.GetData(ProfanityFilter.GetCacheKey())).Return(cacheObj);

            var reader = _mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.Read()).Return(false);


            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getallprofanities")).Return(reader);

            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var profanityObj = new ProfanityFilter(creator, diag, cache, null, null);

            var stats = profanityObj.GetStats(typeof(ProfanityFilter));
            Assert.IsNotNull(stats);
            Assert.AreEqual(typeof(ProfanityFilter).AssemblyQualifiedName, stats.Name);
            foreach (var modclass in profanityObj.GetObjectFromCache().ProfanityClasses.ModClassProfanities)
            {
                Assert.AreEqual(modclass.Value.ProfanityList.Count.ToString(), stats.Values["ModClassID_" + modclass.Key.ToString() + "_ProfanityList"]);
                Assert.AreEqual(modclass.Value.ReferList.Count.ToString(), stats.Values["ModClassID_" + modclass.Key.ToString() + "_ReferList"]);
            }

            
            

        }