public async Task Can_get_post() { // Arrange var post = new Post { Id = Guid.NewGuid().ToString(), Title = "Climate", Description = "Global warming", PostedOn = DateTime.UtcNow, TrainedMeanRateValue = 2, Features = new double[] { 1, 0.5, 0.3, 5 }, Article = new Article { Content = "Global warming is the long-term heating of Earth’s climate system", Image = "data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P" } }; using var context = new PersonalBlogContext(_contextOptions); context.Add(post); context.SaveChanges(); var repository = new Repository <Post>(context); // Act var receivedPost = await repository.Get(p => p.Id == post.Id).FirstOrDefaultAsync(); // Assert receivedPost.Should().BeEquivalentTo(post, options => options .Excluding(p => p.Id) .Excluding(p => p.Article.Id)); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,Password,Administrator,CreationDate")] Author author) { if (ModelState.IsValid) { _context.Add(author); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(author)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description")] ArticleCategory articleCategory) { if (ModelState.IsValid) { _context.Add(articleCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(articleCategory)); }
public async Task <IActionResult> Create([Bind("Id,Slug,ShortDescription,MainContent,CreatedDate,UpdatedDate")] PostModel postModel) { if (ModelState.IsValid) { postModel.Id = Guid.NewGuid(); _context.Add(postModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(postModel)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description")] CategoryModel categoryModel) { if (ModelState.IsValid) { categoryModel.Id = Guid.NewGuid(); _context.Add(categoryModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categoryModel)); }
public async Task <IActionResult> Create([Bind("Id,Title,Content,PublishDate,ArticleCategoryId,AuthorId,Removed")] Article article) { if (ModelState.IsValid) { _context.Add(article); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ArticleCategoryId"] = new SelectList(_context.ArticleCategories, "Id", "Name", article.ArticleCategoryId); ViewData["AuthorId"] = new SelectList(_context.Authors, "Id", "Id", article.AuthorId); return(View(article)); }