public void Create_Void_ReturnId() { _comment.Id = _commentRepository.Create(_comment); var result = _commentRepository.Get(_comment.Id); AreEqualComments(result, _comment); }
public void CommentRepozitoryTest() { var Repository = new CommentRepository(new InMemoryDbContextFactory()); Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(0)); var Comment1 = new CommentModel() { Author = 1, AuthorName = "Milos Hlava", Date = new DateTime(2019, 1, 4), Id = 1, Text = "Testovaci koment" }; var Comment2 = new CommentModel() { Author = 2, AuthorName = "Jozef Hlava", Date = new DateTime(2019, 1, 5), Id = 2, Text = "Testovaci koment cislo 2" }; Repository.Create(Comment1); Repository.Create(Comment2); var ReceivedComment1 = Repository.GetById(1); var ReceivedComment2 = Repository.GetById(2); Assert.Equal(Comment1, ReceivedComment1); Assert.Equal(Comment2, ReceivedComment2); Comment1.Text = "Updatovany text"; Repository.Update(Comment1); ReceivedComment1 = Repository.GetById(1); Assert.Equal(Comment1, ReceivedComment1); List <CommentModel> ReceivedAllComments = Repository.GetAll(); var AllComments = new List <CommentModel>(); AllComments.Add(Comment1); AllComments.Add(Comment2); var Comparer = new CollectionComparer <CommentModel>(); Assert.True(Comparer.Equals(AllComments, ReceivedAllComments)); Repository.Delete(1); Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(1)); Repository.Delete(2); Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(2)); }
/// <summary> /// 创建一个评论 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据库上下文</param> /// <param name="entity">一个评论</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, Comment entity) { try { repository.Create(entity); return(true); } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
public ActionResult Details([Bind(Include = "ID,UsersID")] Comments comment, int?id) { if (ModelState.IsValid) { repComment.Create(comment); return(RedirectToAction("Index")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var topic = new TopicPostViewModel(); topic.TopicList = repTopic.Read().Where(x => x.ID == id).ToList(); topic.PostList = repPost.Read().ToList(); topic.CommentList = repComment.Read().ToList(); if (topic == null) { return(HttpNotFound()); } return(View(topic)); }
public static bool CreateTask(Task task, IEnumerable <Comment> comments) { bool successful = true; try { var taskRepo = new TaskRepository(); var CreatedTask = taskRepo.Create(new Data.Entity.Task() { Title = task.Title, Description = task.Description, Creator = task.Creator, Contractor = task.Contractor, CreatedDate = System.DateTime.Now }); var commentsRepo = new CommentRepository(); foreach (var comment in comments) { commentsRepo.Create(new Data.Entity.Comment { Creator = comment.Creator, Description = comment.Description, Task = CreatedTask.Id }); } } catch (System.Exception ex) { successful = false; } return(successful); }
public ActionResult Create(Comment comment) { CommentRepository commentRepository = new CommentRepository(); commentRepository.Create(comment); return(RedirectToAction("Index")); }
public int CreateComment(Comment comment) { int id = CommentRepository.Create(comment); UnitOfWork.Save(); CacheRepository.DeleteByPartOfTheKey($"{CommentsByPostIdCache}-{comment.NewsPostId}"); return(id); }
public void CreateComment([FromBody] CommentModel value) { try { _repository.Create(value); } catch (Exception e) { } }
public Comment Create(long userId, Comment toAdd) { using (var tran = new TransactionScope()) { var toRet = _repository.Create(toAdd); BlLog.Log(userId, Module, "Create comment", "CommentCreated", new object[] { toAdd.Text.ManageTextLength(100), toAdd.Reference }); tran.Complete(); return(toRet); } }
public void AddNewComment(string text, Post post, string userName) { Comment comment = new Comment() { Post = post, Sender = userName, Text = text }; repository.Create(comment); }
/// <summary> /// Add's a new Comment to DB /// </summary> /// <param name="comment"></param> public void AddComment(Comment comment) { try { RepositoryComment.Create(comment); } catch (Exception ex) { throw ex; } }
public void TestEntityCreate() { var comment = CommentBuilder.New().Build(); var mockTeste = new Mock <ICreateDB <Comment> >(); var commentRepository = new CommentRepository(mockTeste.Object); commentRepository.Create(comment); mockTeste.Verify(x => x.CreateNewRegister(It.IsAny <Comment>())); }
public void TestGetComments() { Comment CCC = new Comment { Message = "qweqweQwe", UserName = "******", ProductId = 2, Rating = 4 }; cr.Create(CCC); List <Comment> getcomments = cr.GetComments(C.ProductId); int countcomments = getcomments.Count(); Assert.AreEqual(CC.Id, getcomments[countcomments - 1].Id, "Id should be equal"); }
public void CreateAsyncTest() { var repository = CommentRepository.Create(); var comment = this.CreateComment(repository, SeedComment.Create()); var service = this.GetCommentService(repository); service.CreateAsync(new CreateCommentInputModel { Content = "New comment" }).GetAwaiter(); Assert.Equal(2, repository.All().Count()); }
public void Create(CommentSendViewModel commentSendViewModel) { Comment comment = new Comment(); comment.Author = commentSendViewModel.Author; comment.CommentText = commentSendViewModel.CommentText; comment.PostId = commentSendViewModel.PostId; comment.DateTime = DateTime.Now; _commentRepository.Create(comment); }
public async void TestCreate() { var Comments = repository.FindAllByPost(3); var Posts = await postRepository.FirstOrDefaultAsync(3); Assert.NotNull(Comments); Assert.Single(Comments); await repository.Create(new Comment { DateTime = DateTime.Now, Post = Posts, Text = "Test5" }); Comments = repository.FindAllByPost(3); Assert.NotNull(Comments); Assert.Equal(2, Comments.Count); }
public ActionResult Read(ReadViewModel model) { var comment = new Comment { Post = PostRepository.Get(model.Id), Author = UserRepository.Get(Convert.ToInt32(User.Identity.GetUserId())), Content = model.Content, CreatedAt = DateTime.Now }; CommentRepository.Create(comment); return(RedirectToAction("Read/" + model.Id, "Post")); }
public void GetLatesByCreatedOnTest() { var repository = CommentRepository.Create(); var comment = this.CreateComment(repository, SeedComment.Create()); var secondComment = this.CreateComment(repository, SeedComment.CreateSecond()); var thirdComment = this.CreateComment(repository, SeedComment.CreateThird()); var service = this.GetCommentService(repository); var result = service.GetLatesByCreatedOn <CommentDummyModel>(1); Assert.Empty(result); }
public ActionResult Create(CommentViewModel model) { var comment = new Comment { Author = model.Author, Content = model.Content, CreatedAt = DateTime.Now, Post = model.Post, Inactive = false }; CommentRepository.Create(comment); return(RedirectToAction("Read/" + model.Post.Id, "Post")); }
public ActionResult Comment(CommentViewModel comment) { var x = new CommentViewModel() { Name = comment.Name, Title = comment.Title, Phone = comment.Phone, Email = comment.Email, IsConfirm = false, }; commentRepository.Create(x); return(Redirect("Index")); }
public async void TestCreate() { var Comments = repository.FindAllByArticle(1); Assert.NotNull(Comments); Assert.IsType <List <Comment> >(Comments); Assert.Equal(2, Comments.Count); await repository.Create(new Comment { DateTime = DateTime.Now, ArticleID = 1, Text = "Test4" }); Comments = repository.FindAllByArticle(1); Assert.NotNull(Comments); Assert.IsType <List <Comment> >(Comments); Assert.Equal(3, Comments.Count); }
public async Task <IActionResult> PostComments(CommentCreationModel model) { BlogViewModel mod = await _postRepository.GetById(model.PostId); if (mod != null && model.Comment.Trim() != "") { _commentsRepository.Create(new Comment() { PostId = model.PostId, UserId = (await _userManager.GetUserAsync(User)).Id, Content = model.Comment }); } return(RedirectToAction("Item", "Blog", new { id = model.PostId, view = false })); }
public async Task SendMessage(string ArticleID, string Text) { var user = await _userManager.FindByNameAsync(Context.User.Identity.Name); Comment comment = new Comment(); comment.Profile = user; DateTime timeUtc = DateTime.UtcNow; TimeZoneInfo kstZone = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time"); comment.DateTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, kstZone); comment.ArticleID = Int32.Parse(ArticleID); comment.Text = Text; await _commentRepository.Create(comment); await Clients.Group(ArticleID).SendAsync("ReceiveMessage", user.UserName, comment.Text, comment.DateTime); }
private static void CreatePost(string title) { var postRepository = new PostRepository(); var categoryRepository = new CategoryRepository(); var commentRepository = new CommentRepository(); var post = new Post { Title = title, PostedDate = DateTime.Now, Contents = "This is just a simple test post..." }; for (int i = 0; i < 10; i++) { var category = new Category { Name = "Category " + i, CreatedDate = DateTime.Now, Description = "Just a test..." }; post.AddCategory(category); categoryRepository.Create(category); } for (int i = 0; i < 20; i++) { var comment = new Comment { PostedDate = DateTime.Now, Author = "Author " + i, Text = "testing..." }; post.AddComment(comment); commentRepository.Create(comment); } postRepository.Create(post); }
public static bool SaveTask(Task task, IEnumerable <Comment> comments) { bool successful = true; try { var taskRepo = new TaskRepository(); var commentsRepo = new CommentRepository(); var taskForUpdate = taskRepo.Get(task.Id); if (taskForUpdate == null) { return(false); } taskForUpdate.Title = task.Title; taskForUpdate.Description = task.Description; taskForUpdate.Creator = task.Creator; taskForUpdate.Contractor = task.Contractor; taskRepo.Update(taskForUpdate); var dbcomments = taskForUpdate.Comments; foreach (var item in dbcomments) { commentsRepo.Delete(item); } foreach (var comment in comments) { commentsRepo.Create(new Data.Entity.Comment { Creator = comment.Creator, Description = comment.Description, Task = taskForUpdate.Id }); } } catch (System.Exception ex) { successful = false; } return(successful); }
public void ReadPostsComments() { using (var context = Context.CreateContext()) { Post testPost = new Post { Header = "Test" }; context.Posts.Add(testPost); CommentRepository commentRep = new CommentRepository(context); var testComment = new Comment { Post = testPost, Sender = "Test", Text = "Test" }; commentRep.Create(testComment); context.Posts.Remove(testPost); context.SaveChanges(); Assert.Equal(0, 0); } }
public void CreateCommentModelTest() { //Arrange var postDetailModel = new PostDetailModel() { Title = "NewTitle", Comments = new List <CommentDetailModel>(5) }; var postListModel = new PostListModel() { Title = "NewTitle" }; var commentModel = new CommentDetailModel() { CreationTime = new DateTime(), BelongsTo = postListModel, }; var userDetailModel = new UserDetailModel() { Name = "NewUser", Email = "*****@*****.**", Password = "******" }; //Act var returnedUserModel = _userRepository.Create(userDetailModel); var returnedPostDetailModel = _postRepository.Create(postDetailModel, returnedUserModel); var returnedCommentDetailModel = _commentRepository.Create(commentModel, returnedUserModel, returnedPostDetailModel); //Assert Assert.NotNull(returnedCommentDetailModel); //Teardown _commentRepository.Delete(returnedCommentDetailModel); _postRepository.Delete(returnedPostDetailModel); _userRepository.Delete(returnedUserModel); }
public ActionResult Create(CommentViewModel Comment) { Comment.IsConfirm = true; repository.Create(Comment); return(RedirectToAction("Index")); }
public void Create(CommentInfo comment) { var commentEntity = AutoMapper.Mapper.Map <CommentEntity>(comment); repository.Create(commentEntity); }
public void CreateComment(CommentViewModel comment) { var modelComment = Mapper.Map <CommentViewModel, CommentEntity>(comment); repository.Create(modelComment); }
public async Task <Comments> Create(Comments comment) { return(await _commentRepository.Create(comment)); }