コード例 #1
0
        public async Task Handle_GivenInvalidCategoryId_ThrowsBadRequestException()
        {
            var command = new UpsertTopicCommand()
            {
                CategoryId = 10
            };

            await ShouldThrowAsyncExtensions.ShouldThrowAsync <BadRequestException>(() => _handler.Handle(command, CancellationToken.None));
        }
コード例 #2
0
        public async Task Handle_GivenIdAndDoesntExist_ThrowsNotFoundException()
        {
            var id = 10;

            var command = new UpsertTopicCommand()
            {
                Id = id, CategoryId = 1
            };

            await ShouldThrowAsyncExtensions.ShouldThrowAsync <NotFoundException>(() => _handler.Handle(command, CancellationToken.None));
        }
コード例 #3
0
        public async Task Handle_NotGivenId_CreatesTopic()
        {
            var topicName        = "New Topic";
            var topicDescription = "Nice new topic description";

            var command = new UpsertTopicCommand()
            {
                Title = topicName, Description = topicDescription, CategoryId = 1
            };
            await _handler.Handle(command, CancellationToken.None);

            var topic = await _context.Topics.FindAsync(3);

            topic.ShouldNotBe(null);
        }
コード例 #4
0
        public async Task Handle_GivenIdAndExists_UpdatesTopic()
        {
            var id             = 1;
            var newDescription = "A brand new topic description";

            var command = new UpsertTopicCommand()
            {
                Id = id, CategoryId = 1, Description = newDescription, Title = "Non-empty Topic"
            };
            await _handler.Handle(command, CancellationToken.None);

            var topic = await _context.Topics.FindAsync(id);

            topic.Description.ShouldBe(newDescription);
        }
コード例 #5
0
        public async Task <IActionResult> Upsert([FromBody] UpsertTopicCommand command)
        {
            int topicId = await Mediator.Send(command);

            return(Ok(topicId));
        }