示例#1
0
        public void ForumCreate_WithoutUid_ThrowsError()
        {
            var commentForum = new Forum{Id = ""};
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            //readerCreator.Stub(x => x.CreateDnaDataReader("getmoderationclasslist")).Return(reader);

           
            mocks.ReplayAll();

            var context = new Context(null, readerCreator, cacheManager, null);
            

            try
            {
                context.CreateForum(commentForum, site);
                throw new Exception("Error not thrown within code");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual("Forum uid is empty, null or exceeds 255 characters.", ex.Message);
                Assert.AreEqual(ErrorType.InvalidForumUid, ex.type);               
            }
            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("commentforumcreate"));
        }
示例#2
0
        public void ForumCreate_WithWithNotSignedIn_ReturnsOK()
        {
            var commentForum = new Forum
            {
                Id = "".PadRight(10, 'a'),
                ParentUri = "http://www.bbc.co.uk/dna",
                Title = "title",
                allowNotSignedInCommenting = true
            };
            var siteId = 1;
            var forumId = 10;

            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var site = mocks.DynamicMock<ISite>();
            site.Stub(x => x.SiteID).Return(siteId);
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSiteOptionValueBool(siteId, "CommentForum", "AllowNotSignedInCommenting")).Return(true);
            readerCreator.Stub(x => x.CreateDnaDataReader("commentforumcreate")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("createnewuserforforum")).Return(reader);
            
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("forumid")).Return(forumId);

            mocks.ReplayAll();

            var context = new Context(null, readerCreator, cacheManager, siteList);

            context.CreateForum(commentForum, site);

            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentforumcreate"));
            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("createnewuserforforum"));
        }
示例#3
0
        public void ForumCreate_DBError_ThrowsError()
        {
            var commentForum = new Forum
            {
                Id = "".PadRight(10, 'a'),
                ParentUri = "http://www.bbc.co.uk/dna",
                Title = "title",
                ModerationServiceGroup = ModerationStatus.ForumStatus.PostMod,
                CloseDate = DateTime.Now.AddDays(2)
            };
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            readerCreator.Stub(x => x.CreateDnaDataReader("commentforumcreate")).Return(reader);
            reader.Stub(x => x.Execute()).Throw(new Exception("DB ERROR"));


            mocks.ReplayAll();

            var context = new Context(null, readerCreator, cacheManager, null);


            try
            {
                context.CreateForum(commentForum, site);
                throw new Exception("Error not thrown within code");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.Unknown, ex.type);
            }
            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentforumcreate"));
        }
示例#4
0
        public void ForumCreate_WithDuration_ReturnsOK()
        {
            var commentForum = new Forum
            {
                Id = "".PadRight(10, 'a'),
                ParentUri = "http://www.bbc.co.uk/dna",
                Title = "title",
                ModerationServiceGroup = ModerationStatus.ForumStatus.PostMod,
                CloseDate = DateTime.Now.AddDays(2)
            };
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var site = mocks.DynamicMock<ISite>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            readerCreator.Stub(x => x.CreateDnaDataReader("commentforumcreate")).Return(reader);


            mocks.ReplayAll();

            var context = new Context(null, readerCreator, cacheManager, null);

            context.CreateForum(commentForum, site);

            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentforumcreate"));
        }
示例#5
0
        public void ForumCreate_WithoutSite_ThrowsError()
        {
            var commentForum = new Forum
            {
                Id = "".PadRight(10, 'a'),
                ParentUri = "http://www.bbc.co.uk/dna",
                Title = "title"
            };
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            //readerCreator.Stub(x => x.CreateDnaDataReader("getmoderationclasslist")).Return(reader);


            mocks.ReplayAll();

            var context = new Context(null, readerCreator, cacheManager, null);


            try
            {
                context.CreateForum(commentForum, null);
                throw new Exception("Error not thrown within code");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.UnknownSite, ex.type);
            }
            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("commentforumcreate"));
        }