本文整理汇总了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())));
}
示例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())));
}
示例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())));
}