public void CommentOnMatchTest() { //Arrange. User commentarist = GetFakeUser(); CommentaryDto made = new CommentaryDto() { makerUsername = commentarist.UserName, text = "this is a comment" }; CommentModelIn input = new CommentModelIn() { Text = "this is a comment" }; matchService.Setup(ms => ms.CommentOnEncounter(3, "username", input.Text)).Returns(made); //Act. IActionResult result = controller.CommentOnMatch(3, input); CreatedAtRouteResult createdResult = result as CreatedAtRouteResult; CommentModelOut comment = createdResult.Value as CommentModelOut; //Assert. matchService.Verify(ms => ms.CommentOnEncounter(3, "username", input.Text), Times.Once); Assert.IsNotNull(result); Assert.IsNotNull(createdResult); Assert.AreEqual(201, createdResult.StatusCode); Assert.AreEqual("GetCommentById", createdResult.RouteName); Assert.IsNotNull(comment); Assert.AreEqual(comment.Text, input.Text); Assert.AreEqual("username", comment.MakerUsername); }
public void ViewAllTheCommentsTest() { //Arrange. User dummyUser = GetFakeUser(); CommentaryDto dummyComment = new CommentaryDto() { text = "Comment", makerUsername = dummyUser.UserName }; ICollection <CommentaryDto> fakeList = new List <CommentaryDto>() { dummyComment, dummyComment, dummyComment }; matchService.Setup(ms => ms.GetAllCommentaries()).Returns(fakeList); //Act. IActionResult result = controller.GetAllComments(); OkObjectResult okResult = result as OkObjectResult; ICollection <CommentModelOut> comments = okResult.Value as ICollection <CommentModelOut>; //Do. matchService.Verify(ms => ms.GetAllCommentaries(), Times.Once); Assert.IsNotNull(result); Assert.IsNotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); Assert.IsNotNull(comments); Assert.AreEqual(fakeList.Count, comments.Count); }
public async Task GivenCommentaryService_WhenGetCommentaryByID_ThenShouldGetThisCommentary() { CommentaryDto accpected = _mapper.Map <CommentaryDto>(Commentary); CommentaryService CommentaryService = new CommentaryService(_mockUnitofwork, _mapper); CommentaryDto CommentaryDto = await CommentaryService.GetCommentaryById(new Guid()); accpected.Should().BeEquivalentTo(CommentaryDto); }
public async Task <ActionResult> CreateCommentary(CommentaryDto model) { if (ModelState.IsValid) { await _commentaryService.AddCommentary(model); return(Ok(new { message = "You added commentary." })); } return(BadRequest()); }
private CommentModelOut BuildCommentModelOut(CommentaryDto aComment) { CommentModelOut comment = new CommentModelOut() { Id = aComment.commentId, MakerUsername = aComment.makerUsername, Text = aComment.text }; return(comment); }
private IActionResult TryGetComment(int id) { CommentaryDto comment = encounterService.GetComment(id); CommentModelOut output = new CommentModelOut { Id = comment.commentId, MakerUsername = comment.makerUsername, Text = comment.text }; return(Ok(output)); }
public CommentaryDto CommentOnEncounter(int encounterId, string userName, string commentText) { CommentaryDto dto = new CommentaryDto() { makerUsername = userName, text = commentText }; Commentary toAdd = commentConverter.ToCommentary(dto); Commentary added = AddComment(encounterId, toAdd); dto.commentId = added.Id; return(dto); }
public async Task <ActionResult> DeleteCommentary(Guid id) { CommentaryDto commentary = await _commentaryService.GetCommentaryById(id); if (commentary.UserId == User.Identity.Name || User.IsInRole("Admin")) { await _commentaryService.RemoveCommentary(id); return(Ok(new { message = "This commentary was deleted." })); } return(BadRequest("You do not have rules to do it.")); }
private IActionResult TryAddComment(int matchId, CommentModelIn input) { string username = HttpContext.User.Claims.First(c => c.Type.Equals(AuthenticationConstants.USERNAME_CLAIM)).Value; CommentaryDto created = encounterService.CommentOnEncounter(matchId, username, input.Text); CommentModelOut output = new CommentModelOut { Id = created.commentId, MakerUsername = username, Text = input.Text }; return(CreatedAtRoute("GetCommentById", new { id = output.Id }, output)); }
public async Task AddCommentary(CommentaryDto commentaryDto) { Commentary commentary = new Commentary { Id = Guid.NewGuid(), Content = commentaryDto.Content, User = await _unit.UserRepository.GetUserById(commentaryDto.UserId), Video = await _unit.VideoRepository.GetVideoById(commentaryDto.VideoId), DayOfCreation = DateTime.Now }; _unit.CommentaryRepository.AddCommentary(commentary); await _unit.SaveAsync(); }
public void GetCommentTest() { UserId identity = new UserId() { Name = "name", Surname = "surname", UserName = "******", Password = "******", Email = "*****@*****.**" }; User commentarist = new User(identity, true); usersRepo.Add(commentarist); teamsRepo.Add(teamA); teamsRepo.Add(teamB); teamsRepo.Add(teamC); Encounter added1 = matchesRepo.Add(matchAvsB); Encounter added2 = matchesRepo.Add(matchAvsC); SetUpRepository(); CommentaryDto comment = serviceToTest.CommentOnEncounter(added1.Id, commentarist.UserName, "a Comment"); CommentaryDto retrieved = serviceToTest.GetComment(comment.commentId); Assert.AreEqual(comment.text, retrieved.text); }
public void ViewCommentTest() { //Arrange. User dummyUser = GetFakeUser(); CommentaryDto dummyComment = new CommentaryDto() { text = "Comment", makerUsername = dummyUser.UserName }; matchService.Setup(ms => ms.GetComment(3)).Returns(dummyComment); //Act. IActionResult result = controller.GetComment(3); OkObjectResult okResult = result as OkObjectResult; CommentModelOut comment = okResult.Value as CommentModelOut; //Assert. Assert.IsNotNull(result); Assert.IsNotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); Assert.IsNotNull(comment); Assert.AreEqual(dummyComment.text, comment.Text); }
public Commentary ToCommentary(CommentaryDto dto) { User maker = TryGetMaker(dto.makerUsername); return(new Commentary(dto.commentId, dto.text, maker)); }