예제 #1
0
        public async Task <IActionResult> Create(Guid userId, [FromBody] CreateTweetInputModel createTweetInputModel)
        {
            var createTweetCommand = new CreateTweetCommand(createTweetInputModel, userId);

            var createTweetViewModel = await _mediator.Send(createTweetCommand);

            return(CreatedAtAction(nameof(GetById), new { userId = userId, tweetId = createTweetViewModel.Id }, createTweetViewModel));
        }
        public async Task ContentIsEmpty_Called_ThrowArgumentNullException() {
            // Arrange
            var createTweetInputModel = new CreateTweetInputModel {
                Content = null
            };

            var userId = Guid.NewGuid();

            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(ur => ur.AddTweet(userId, It.IsAny<Tweet>())).Verifiable();
            
            var createTweetCommand = new CreateTweetCommand(createTweetInputModel, userId);
            var createTweetCommandHandler = new CreateTweetCommandHandler(userRepository.Object);

            // Act
            Func<Task> funcHandle = () => createTweetCommandHandler.Handle(createTweetCommand, new CancellationToken());

            // Assert
            var exception = await Assert.ThrowsAsync<ArgumentException>(funcHandle);
            Assert.Equal("Content parameter is invalid.", exception.Message);
        }