本文整理汇总了C#中IPostRepository.Stub方法的典型用法代码示例。如果您正苦于以下问题:C# IPostRepository.Stub方法的具体用法?C# IPostRepository.Stub怎么用?C# IPostRepository.Stub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPostRepository
的用法示例。
在下文中一共展示了IPostRepository.Stub方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
private static void Init()
{
posts = (new List<Post>() {
new Post("title", "content", "#", "J", DateTime.UtcNow),
new Post("title 2", "content z", "#", "M", DateTime.UtcNow.AddDays(2)){PostId = 2, Tags = new List<Tag>(){new Tag("aa"),new Tag("bb")}},
new Post("fan roosh", "content k", "#", "F", DateTime.UtcNow.AddDays(-1))
}).AsQueryable();
postRepository = MockRepository.GenerateStub<IPostRepository>();
postRepository.Stub(x => x.RecentPosts(Arg<int>.Is.Anything))
.WhenCalled(x => x.ReturnValue = posts.Where(y => y.PublishDate <= DateTime.UtcNow).Take((int)x.Arguments[0]));
postRepository.Stub(x => x.Find(Arg<long>.Is.Anything))
.WhenCalled(x => x.ReturnValue = posts.FirstOrDefault(y => y.PostId == (long)x.Arguments[0]))
.Return(new Post());
}
示例2: SetUp
public void SetUp()
{
TestData.Init();
_repository = MockRepository.GenerateStub<IPostRepository>();
_service = new SyndicationService(_repository);
_repository.Stub(m => m.FindAll()).Return(new[] {TestData.PublishedPost});
_feed = _service.GetPostsAsSyndicationFeed(new Uri("http://test.com/testrss"));
}
示例3: Before
public void Before()
{
var builder = new TestControllerBuilder();
_postRepository = MockRepository.GenerateStub<IPostRepository>();
_postRepository.Stub(x => x.GetAllPost()).Return(new List<Post>());
// using real automapper
AutomapperConfiguration.Configure();
_sut = new HomeController(_postRepository, new AutomapperWrapper());
builder.InitializeController(_sut);
}
示例4: Setup
public static void Setup(TestContext testContext)
{
// generate a mock repository
_repository = MockRepository.GenerateStub<IPostRepository>();
// the subject under test
Sut = new PostController(_repository);
// a random id to test
postId = new Random().Next();
// set a dumy post
ExpectedModel = new Post(postId, "","","",0,"",DateTime.Now, DateTime.MinValue);
// stub the repo to return a post when it is called GetById with a id is PostId
_repository.Stub(repo => repo.GetById(postId)).Return(ExpectedModel);
// the result returned by calling Edit to the controller
Actual = Sut.Edit(postId).Model;
}
示例5: InitTest
public void InitTest()
{
_postRepository = MockRepository.GenerateMock<IPostRepository>();
_postRepository.Stub(pr => pr.RecentPosts(10)).IgnoreArguments()
.Return(new List<Post>().AsQueryable());
}
示例6: InitTest
public void InitTest()
{
_postRepository = MockRepository.GenerateMock<IPostRepository>();
_postRepository.Stub(pr => pr.Find("my_first_test")).Return(new Post());
}