public void AddThread_ShouldCallRestAddEndpoint() { // Arrange _target = new ThreadService(_threadApiServiceMock.Object); // Act _target.Create(new ThreadRequestDTO()).Subscribe(); // Assert _threadApiMock.Verify(x => x.CreateThread(It.IsAny <ThreadRequestDTO>()), Times.Once); }
public async Task <ActionResult <ThreadResponseDTO> > Create([FromBody] ThreadRequestDTO threadRequest) { var createdThread = await _threadsService.Create(new ThreadEntity { Title = threadRequest.Title, Content = threadRequest.Content, Comments = new List <CommentEntity>(), Author = await GettingCurrentClient(), }); return(Created($"threads/{createdThread.Id}", _threadMapper.ToDto(createdThread))); }
public async Task Create_ShouldReturnTheCreatedThread() { // Arrange var id = 1; var threadEntity = new ThreadEntity { Id = id, Title = "Thread1", Content = "Thread1 content", Author = new UserEntity(), Comments = new List <CommentEntity>() }; _threadRepositoryMock .Setup(x => x.Create(threadEntity)) .ReturnsAsync(() => threadEntity); // Act var result = await _threadService.Create(threadEntity); // Assert Assert.NotNull(result); _threadRepositoryMock.Verify(x => x.Create(threadEntity), Times.Once); }