public async Task ShouldReturnCommentsFromSameUser() { //Arrange Guid deviceId = _baseTest.Fixture.Create <Guid>(); string comment = _baseTest.Fixture.Create <string>(); Guid userId = _baseTest.Fixture.Create <Guid>(); UserModel userStub = _baseTest.Fixture.Build <UserModel>() .With(x => x.CompanyId, 2222) .With(x => x.DisplayName, "DDDD") .With(x => x.Id, userId) .Create(); Comment commentDb = new Comment() { Message = comment, CreateOn = DateTime.UtcNow, DeviceId = deviceId, UserId = userId, UserName = "******" }; List <UserModel> userList = new List <UserModel>(); userList.Add(userStub); _httpServiceMock.Setup(x => x.GetUsersByIdTrustedAsync(It.IsAny <string>())).ReturnsAsync(userList); Guid idComment = await _commrepository.AddAsync(commentDb); //Act var result = await _commentService.GetAllByDeviceIdAsync(It.IsAny <string>(), deviceId); //Assert _baseTest.DbContext.Comments.Count().Should().Be(1); var newComment = _baseTest.DbContext.Comments.First(); newComment.Id.Should().Be(idComment); newComment.IsDeleted.Should().Be(false); newComment.UserId.Should().Be(userId); newComment.UserName.Should().Be("DDDD"); newComment.DeviceId.Should().Be(deviceId); newComment.Message.Should().Be(comment); }
public async Task <ActionResult> CreateComment(PostComment comment) { if (ModelState.IsValid) { comment.CommentDate = DateTime.Now.ToUniversalTime(); await _cRepository.AddAsync(comment); return(RedirectToAction("Index", "Home")); } return(View(comment)); }
public async Task <IActionResult> Reply(int?id, [Bind("Description,PostId,Image,IsEdited,Created,UserId")] Comment comment) { Post post = await repo.GetByIdAsync(id); if (ModelState.IsValid) { comment.Created = DateTime.Now; comment.UserId = User.FindFirstValue(ClaimTypes.NameIdentifier); comment.PostId = post.Id; await commentRepo.AddAsync(comment); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(post.UserId); return(View(post)); }
/// <summary> /// 添加评论 /// </summary> /// <param name="t"></param> /// <returns></returns> public async Task <bool> AddCommentAsync(CommentEntity t) { bool flag; var user = await UserService.GetUserByIdAsync(t.userId); if (await IsExistsCommentOnNewestByUserIdAsync(t.userId)) { // 判断用户是否为空 if (user == null) { return(false); } t.location = LocationHelper.GetLocation(t.location); flag = await CommentRepository.AddAsync(t); } else { throw new Exception("你已经在一分钟前提交过一次了"); } return(flag); }
public async Task <IActionResult> CreateComment([FromBody] Comments comment)//Comments { //Comments comment2 = null;//comment; if (comment == null) { return(BadRequest("Запрос с пустыми параметрами")); } if (!ModelState.IsValid) { return(BadRequest("Модель не соответсвует")); } comment.ID_User = (Guid)ur.GetID(User.Identity.Name); comment.DateTime = DateTime.Now; Guid insertedCommentId = (Guid)await commentRepository.AddAsync(comment); CommentWithUserInfo commentWithUserInfo = await commentRepository.GetByIDWithUserInfoAsync(insertedCommentId); return(Ok(commentWithUserInfo)); }
public async Task <ActionResult> Comment(string name, [Bind(Include = "Message")] Comment comment) { if (!ModelState.IsValid) { return(HttpNotFound("Invalid message")); } string photoContainer = CloudConfigurationManager.GetSetting("storage:photocontainer"); CloudBlobClient client = _account.CreateCloudBlobClient(); CloudBlobContainer container = client.GetContainerReference(photoContainer); var blob = container.GetBlockBlobReference(name); try { await blob.FetchAttributesAsync(); } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound) { return(HttpNotFound("Image does not exist")); } throw; } var entity = new CommentEntity { Created = DateTime.Now, Message = comment.Message, PictureId = name, UserId = User.Identity.Name }; await _context.AddAsync(entity); return(RedirectToAction("Details", new { name = name })); }