当前位置: 首页>>代码示例>>C#>>正文


C# Comments.GetStartIndexForPostId方法代码示例

本文整理汇总了C#中Comments.GetStartIndexForPostId方法的典型用法代码示例。如果您正苦于以下问题:C# Comments.GetStartIndexForPostId方法的具体用法?C# Comments.GetStartIndexForPostId怎么用?C# Comments.GetStartIndexForPostId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Comments的用法示例。


在下文中一共展示了Comments.GetStartIndexForPostId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetStartIndexForPostId_NoRead_ReturnCorrectException

        public void GetStartIndexForPostId_NoRead_ReturnCorrectException()
        {
            var itemsPerPage = 10;
            var postIndex = 25;
            var postId = 5;
            var sortDirection = SortDirection.Ascending;
            var sortBy = SortBy.Created;

            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var reader = mocks.DynamicMock<IDnaDataReader>();

            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.HasRows).Return(false);
            reader.Stub(x => x.GetInt32NullAsZero("startIndex")).Return(postIndex);
            readerCreator.Stub(x => x.CreateDnaDataReader("getindexofcomment")).Return(reader);
            mocks.ReplayAll();

            var comments = new Comments(null, readerCreator, null, null)
            {
                ItemsPerPage = itemsPerPage,
                SortDirection = sortDirection,
                SortBy = sortBy
            };

            try
            {
                comments.GetStartIndexForPostId(postId);
                throw new Exception("Should have thrown expection");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.CommentNotFound, ex.type);
            }

            reader.AssertWasCalled((x => x.AddParameter("postid", postId)));
            reader.AssertWasCalled((x => x.AddParameter("sortby", sortBy.ToString())));
            reader.AssertWasCalled((x => x.AddParameter("sortdirection", sortDirection.ToString())));

        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:39,代码来源:CommentsTest.cs

示例2: GetStartIndexForPostId_DbException_ReturnCorrectException

        public void GetStartIndexForPostId_DbException_ReturnCorrectException()
        {
            var itemsPerPage = 10;
            var postId = 5;
            var sortDirection = SortDirection.Ascending;
            var sortBy = SortBy.Created;
            var expectedException = "dbexception thrown";

            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var reader = mocks.DynamicMock<IDnaDataReader>();

            reader.Stub(x => x.Execute()).Throw(new Exception(expectedException)); ;
            readerCreator.Stub(x => x.CreateDnaDataReader("getindexofcomment")).Return(reader);
            mocks.ReplayAll();

            var comments = new Comments(null, readerCreator, null, null)
            {
                ItemsPerPage = itemsPerPage,
                SortDirection = sortDirection,
                SortBy = sortBy
            };

            try
            {
                comments.GetStartIndexForPostId(postId);
                throw new Exception("Should have thrown expection");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(expectedException, ex.Message);
            }

            reader.AssertWasCalled((x => x.AddParameter("postid", postId)));
            reader.AssertWasCalled((x => x.AddParameter("sortby", sortBy.ToString())));
            reader.AssertWasCalled((x => x.AddParameter("sortdirection", sortDirection.ToString())));

        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:37,代码来源:CommentsTest.cs

示例3: GetStartIndexForPostId_ValidResult_ReturnCorrectIndex

        public void GetStartIndexForPostId_ValidResult_ReturnCorrectIndex()
        {
            var itemsPerPage = 10;
            var postIndex = 25;
            var expectedStartIndex = 20;
            var postId = 5;
            var sortDirection = SortDirection.Ascending;
            var sortBy = SortBy.Created;

            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var reader = mocks.DynamicMock<IDnaDataReader>();

            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("startIndex")).Return(postIndex);
            readerCreator.Stub(x => x.CreateDnaDataReader("getindexofcomment")).Return(reader);
            mocks.ReplayAll();

            var comments = new Comments(null, readerCreator, null, null)
            {
                ItemsPerPage= itemsPerPage,
                SortDirection =sortDirection,
                SortBy = sortBy
            };

            Assert.AreEqual(expectedStartIndex, comments.GetStartIndexForPostId(postId));
            reader.AssertWasCalled((x => x.AddParameter("postid", postId)));
            reader.AssertWasCalled((x => x.AddParameter("sortby", sortBy.ToString())));
            reader.AssertWasCalled((x => x.AddParameter("sortdirection", sortDirection.ToString())));

        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:31,代码来源:CommentsTest.cs


注:本文中的Comments.GetStartIndexForPostId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。