PostGetByIdDto IPostBusinessLogic.GetById(Guid id, UserInfoModel userInfo) { Post post = postRepository.GetById(id, "Reacts"); if (post == null) { return(null); } PostGetByIdDto returnedPost = mapper.Map <PostGetByIdDto>(post); if (userInfo != null && post.Reacts != null) { PostReact react = post.Reacts.FirstOrDefault(pr => pr.UserId == userInfo.CreatorId); if (react != null) { if (react.Type == ReactType.Like) { returnedPost.Liked = true; } else if (react.Type == ReactType.Dislike) { returnedPost.Disliked = true; } } } return(returnedPost); }
public void GetById_ReturnsNullIfPostDoesNotExist() { //Arrange postRepositoryMock.Setup(x => x.GetById(Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6"), "Reacts")).Returns(() => null); PostGetByIdDto postGetById = new PostGetByIdDto(); UserInfoModel userInfo = new UserInfoModel(); //Act postGetById = systemUnderTest.GetById(Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6"), userInfo); //Assert Assert.Null(postGetById); }
public void GetById_ReturnsPostWithThatId() { //Arrange PostGetByIdDto postGetById = new PostGetByIdDto(); UserInfoModel userInfo = new UserInfoModel(); Post post = new Post { Id = Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6") }; postRepositoryMock.Setup(x => x.GetById(Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6"), "Reacts")).Returns(post); PostGetByIdDto mappedPost = mapper.Map <PostGetByIdDto>(post); //Act postGetById = systemUnderTest.GetById(Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6"), userInfo); //Assert Assert.True(postGetById.Id.Equals(mappedPost.Id)); }