本文整理汇总了C#中BlogPost.SetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# BlogPost.SetProperty方法的具体用法?C# BlogPost.SetProperty怎么用?C# BlogPost.SetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlogPost
的用法示例。
在下文中一共展示了BlogPost.SetProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMockedBlogPostRepository
public static Mock<IBlogPostRepository> CreateMockedBlogPostRepository(bool shouldBlogPostRepositoryAlwayReturnPost = true, int blogPostCount = 20)
{
//TODO: may need to allow return of specific blog post if no match
var blogPostList = new List<BlogPost>();
for (int i = 0; i < blogPostCount; i++)
{
var blogPost = new BlogPost(i.ToString(), i.ToString(), i.ToString(), new ImageReference(1, "/noimage.jpg"), DateTime.Now, new BlogUser());
blogPost.SetProperty(p => p.Id, i);
blogPostList.Add(blogPost);
}
var mockedBlogPostRepository = new Mock<IBlogPostRepository>();
mockedBlogPostRepository.Setup(r => r.Count).Returns(blogPostCount);
mockedBlogPostRepository.Setup(r => r.LoadAll()).Returns(blogPostList);
mockedBlogPostRepository.Setup(r => r.LoadFrom(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>()))
.Returns<int, int, int, string>((year, month, day, title) => ReturnBlogPost(year, month, day, title, blogPostList, shouldBlogPostRepositoryAlwayReturnPost));
mockedBlogPostRepository.Setup(r => r.GetPosts(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<IEnumerable<string>>()))
.Returns<int, int, IEnumerable<string>>((skip, take, tags) => blogPostList.Skip(skip).Take(take));
return mockedBlogPostRepository;
}
示例2: BlogPost
public void Delete_GIVEN_BlogPostRepository_Has_BlogPost_With_Id_1_WHEN_blogPostId_Parameter_Is_1_And_User_Is_Logged_In_THEN_Saves_BlogPost_With_DeletedByUser_Set_To_Logged_In_User()
{
const int UserId = 1;
const int BlogPostId = 1;
BlogPost savedBlogPost = null;
var blogPost = new BlogPost("test", "test", "test", new ImageReference(1, "/noimage.jpg"), DateTime.Now, new BlogUser());
blogPost.SetProperty(bp => bp.Id, BlogPostId);
var mockedBlogPostRepository = new Mock<IBlogPostRepository>();
mockedBlogPostRepository.Setup(r => r.LoadFullArticle(BlogPostId)).Returns(blogPost);
mockedBlogPostRepository.Setup(r => r.SaveOrUpdate(It.IsAny<BlogPost>())).Callback<BlogPost>(bp => savedBlogPost = bp);
var mockedLookupRepository = MockCreators.CreateMockedLookupRepository();
Mock<IJumbleblocksPrincipal> mockedPrincipal = MockCreators.CreateMockedPrincipalAndAddBlogUserToLookUp(mockedLookupRepository, UserId);
var controller = MockCreators.CreateBlogPostController(blogPostRepository: mockedBlogPostRepository.Object, lookupRepository: mockedLookupRepository.Object);
controller.SetPrincipal(mockedPrincipal.Object);
controller.Delete(BlogPostId);
savedBlogPost.ShouldNotBeNull();
savedBlogPost.DeletedByUser.Id.ShouldEqual(UserId);
}
示例3: ImageReference
public void BlogPostController_Edit_GIVEN_BlogPostRepository_Contains_BlogPost_With_ID_1_WHEN_blogPostId_Is_1_THEN_Returns_ViewModel_For_BlogPost()
{
const int BlogPostId = 1;
var imageReference = new ImageReference(1, "/noimage.jpg");
var author = new BlogUser { Id = 1, Forenames = "Joe", Surname = "Blogs" };
var blogPost = new BlogPost("Test", "This is the description", "Not much in this article", imageReference, DateTime.Now, author);
blogPost.SetProperty("Id", BlogPostId);
blogPost.UpdateSeries(new Series { Name = "Series A" });
blogPost.UpdateTags(new Tag[] { new Tag { Text = "Tag 1" } });
var mockedBlogPostRepository = new Mock<IBlogPostRepository>();
mockedBlogPostRepository.Setup(r => r.Load(BlogPostId)).Returns(blogPost);
var controller = MockCreators.CreateBlogPostController(blogPostRepository: mockedBlogPostRepository.Object);
var result = controller.Edit(blogPost.Id.Value) as ViewResult;
result.ShouldNotBeNull();
result.Model.ShouldBeInstanceOfType(typeof(CreateEditModel));
var model = (CreateEditModel)result.Model;
model.BlogPostId.ShouldEqual(blogPost.Id);
model.PublishedDate.ShouldEqual(blogPost.PublishedDate);
model.Title.ShouldEqual(blogPost.Title);
model.Description.ShouldEqual(blogPost.Description);
model.FullArticle.ShouldEqual(blogPost.FullArticle);
model.ImageId.ShouldEqual(blogPost.ImageReference.Id.Value);
model.SeriesName.ShouldEqual(blogPost.Series.Name);
}
示例4: ImageReference
public void BlogPostController_List_GIVEN_BlogPost_Has_1_Item_THEN_Returns_1_ArticleListingViewModel_With_Data_From_Post()
{
const int BlogPostId = 1;
var imageReference = new ImageReference(1, "/noimage.jpg");
var author = new BlogUser { Id = 1, Forenames = "Joe", Surname = "Blogs" };
var blogPost = new BlogPost("Test", "This is the description", "Not much in this article", imageReference, DateTime.Now, author);
blogPost.SetProperty("Id", BlogPostId);
blogPost.UpdateSeries(new Series { Name = "Series A" });
blogPost.UpdateTags(new Tag[] { new Tag { Text = "Tag 1" } });
var mockedBlogPostRepository = new Mock<IBlogPostRepository>();
mockedBlogPostRepository.Setup(r => r.LoadAll()).Returns(new BlogPost[] { blogPost });
var controller = MockCreators.CreateBlogPostController(blogPostRepository: mockedBlogPostRepository.Object);
var result = controller.List() as ViewResult;
result.ShouldNotBeNull();
result.Model.ShouldBeInstanceOfType(typeof(IEnumerable<BlogPostListingItemModel>));
var viewModelForPost = ((IEnumerable<BlogPostListingItemModel>)result.Model).First();
viewModelForPost.BlogPostId.ShouldEqual(blogPost.Id.Value);
viewModelForPost.Title.ShouldEqual(blogPost.Title);
viewModelForPost.PublishedDate.ShouldEqual(blogPost.PublishedDate);
viewModelForPost.AuthorsName.ShouldEqual(blogPost.Author.FullName);
}
示例5: BlogPostController_Edit_Returns_ViewResult
public void BlogPostController_Edit_Returns_ViewResult()
{
const int BlogPostId = 1;
var imageReference = new ImageReference(1, "/noimage.jpg");
var author = new BlogUser { Id = 1, Forenames = "Joe", Surname = "Blogs" };
var blogPost = new BlogPost("Test", "This is the description", "Not much in this article", imageReference, DateTime.Now, author);
blogPost.SetProperty("Id", BlogPostId);
blogPost.UpdateSeries(new Series { Name = "Series A" });
blogPost.UpdateTags(new Tag[] { new Tag { Text = "Tag 1" } });
var mockedBlogPostRepository = new Mock<IBlogPostRepository>();
mockedBlogPostRepository.Setup(r => r.Load(BlogPostId)).Returns(blogPost);
var controller = MockCreators.CreateBlogPostController(blogPostRepository: mockedBlogPostRepository.Object);
var result = controller.Edit(1);
result.ShouldBeInstanceOfType(typeof(ViewResult));
}
示例6: ReturnBlogPost
private static BlogPost ReturnBlogPost(int year, int month, int day, string title, IList<BlogPost> blogPostList, bool shouldBlogPostRepositoryAlwayReturnPost)
{
if (shouldBlogPostRepositoryAlwayReturnPost)
{
var blogPost = new BlogPost("Test", "Test", "Test", new ImageReference(1, "/noimage.jpg"), DateTime.Now, new BlogUser());
blogPost.SetProperty(p => p.Id, 1);
return blogPost;
}
return blogPostList.SingleOrDefault(p => p.PublishedDate.Year == year && p.PublishedDate.Month == month && p.PublishedDate.Day == day && p.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase));
}