本文整理汇总了C#中IDbSet.Stub方法的典型用法代码示例。如果您正苦于以下问题:C# IDbSet.Stub方法的具体用法?C# IDbSet.Stub怎么用?C# IDbSet.Stub使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbSet
的用法示例。
在下文中一共展示了IDbSet.Stub方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
//.........这里部分代码省略.........
new Category
{
Description = "Programming",
Id = 2,
Name = "Programming",
//Posts = this.Posts.ToList(),
UrlSlug = "programming"
},
new Category
{
Description = "School",
Id = 3,
Name = "School",
//Posts = this.Posts.ToList(),
UrlSlug = "school"
}
}.AsQueryable();
#endregion
#region Sample Tags and Mock Set Up
Tags = new List<Tag>
{
new Tag
{
Description = "Hello World",
Id = 1,
Name = "Hello World",
//Posts = this.Posts.ToList(),
UrlSlug = "helloworld"
},
new Tag
{
Description = "MVC",
Id = 2,
Name = "MVC",
// Posts = this.Posts.ToList(),
UrlSlug = "MVC"
},
new Tag
{
Description = "Hello World",
Id = 3,
Name = "Hello World",
//Posts = this.Posts.ToList(),
UrlSlug = "helloworld"
},
}.AsQueryable();
#endregion
#region Setting relationships
// setting relations for posts
Random rnd = new Random();
foreach (var post in Posts)
{
//assigns random tags to posts
post.Tags = this.Tags.Where(p => p.Id == rnd.Next(1, 4)).ToList();
//assigns random category to post
post.Category = this.Categories.Single(p => p.Id == 1);
}
//setting relations for tags
foreach (var tag in Tags)
{
//assigns random tags to posts
tag.Posts = this.Posts.Where(p => p.Id == rnd.Next(1, 4)).ToList();
}
foreach (var category in Categories)
{
category.Posts = this.Posts.Where(p => p.Id == rnd.Next(1, 4)).ToList();
}
#endregion
SetPosts.Stub(m => m.Provider).Return(Posts.Provider);
SetPosts.Stub(m => m.Expression).Return(Posts.Expression);
SetPosts.Stub(m => m.ElementType).Return(Posts.ElementType);
SetPosts.Stub(m => m.GetEnumerator()).Return(Posts.GetEnumerator());
MockContext.Stub(x => x.Posts).PropertyBehavior();
MockContext.Posts = SetPosts;
SetCategories.Stub(m => m.Provider).Return(Categories.Provider);
SetCategories.Stub(m => m.Expression).Return(Categories.Expression);
SetCategories.Stub(m => m.ElementType).Return(Categories.ElementType);
SetCategories.Stub(m => m.GetEnumerator()).Return(Categories.GetEnumerator());
MockContext.Stub(x => x.Categories).PropertyBehavior();
MockContext.Categories = SetCategories;
SetTags.Stub(m => m.Provider).Return(Tags.Provider);
SetTags.Stub(m => m.Expression).Return(Tags.Expression);
SetTags.Stub(m => m.ElementType).Return(Tags.ElementType);
SetTags.Stub(m => m.GetEnumerator()).Return(Tags.GetEnumerator());
MockContext.Stub(x => x.Tags).PropertyBehavior();
MockContext.Tags = SetTags;
}