コード例 #1
0
ファイル: StoryService.cs プロジェクト: spetz/trill-api
        public async Task AddAsync(SendStory command)
        {
            var story = new Story(command.Id, command.Title, command.Text, command.Author, command.Tags);
            await _storyRepository.AddAsync(story);

            _logger.LogInformation($"Added a story with ID: '{command.Id}'.");
        }
コード例 #2
0
        public async Task <ActionResult> Post(SendStory command)
        {
            await _commandDispatcher.SendAsync(command);

            var storyId = _storyRequestStorage.GetStoryId(command.Id);

            return(Created($"stories/{storyId}", null));
        }
コード例 #3
0
        public async Task AddAsync(SendStory command)
        {
            var author = new Author(command.Author);
            var story  = new Story(command.Id, command.Title, command.Text, author, command.Tags, DateTime.UtcNow);
            await _storyRepository.AddAsync(story);

            _logger.LogInformation($"Added a story with ID: '{story.Id}'.");
        }
コード例 #4
0
        public async Task add_should_fail_given_missing_author()
        {
            var command   = new SendStory(Guid.NewGuid(), "Test", "Lorem ipsum", string.Empty, new[] { "tag1", "tag2" });
            var exception = await Record.ExceptionAsync(async() => await _storyService.AddAsync(command));

            exception.ShouldNotBeNull();
            exception.ShouldBeOfType <MissingAuthorException>();
        }
コード例 #5
0
        public async Task add_should_succeed_given_valid_data()
        {
            // Arrange
            var command = new SendStory(Guid.NewGuid(), "test", "Lorem ipsum", "user1", new[] { "tag1", "tag2" });

            // Act
            await _storyService.AddAsync(command);

            // Assert
            await _storyRepository.Received(1).AddAsync(Arg.Is <Story>(x => x.Id == command.Id));
        }
コード例 #6
0
        public async Task post_send_story_should_return_created_and_location_header()
        {
            var command = new SendStory(Guid.NewGuid(), "test", "Lorem ipsum",
                                        "test_user", new[] { "tag1", "tag2" });
            var payload = GetPayload(command);

            var response = await _client.PostAsync("api/stories", payload);

            response.StatusCode.ShouldBe(HttpStatusCode.Created);
            var location = response.Headers.Location;

            location.ShouldNotBeNull();
            location.ToString().ShouldBe($"http://localhost/api/Stories/{command.Id}");
        }
コード例 #7
0
        public async Task post_send_story_should_create_story_and_return_location_header()
        {
            var storyId = 1;
            var userId  = Guid.NewGuid();
            await _userRepository.AddAsync(new User(userId, "Test", DateTime.UtcNow));

            // await AddUserToDatabaseAsync(userId);
            var id      = Guid.NewGuid();
            var command = new SendStory(storyId, userId, $"Test story {id:N}", $"Lorem ipsum {id}",
                                        new[] { $"test-1-{id:N}", $"test-2-{id:N}" });
            var response = await PostAsync("stories", command);

            response.StatusCode.ShouldBe(HttpStatusCode.Created);
            var location = response.Headers.Location;

            location.ShouldNotBeNull();
        }
コード例 #8
0
ファイル: StoryService.cs プロジェクト: spetz/workshops-asp
        public async Task AddAsync(SendStory request)
        {
            var user = await _userRepository.GetAsync(request.UserId);

            if (user is null)
            {
                throw new UserNotFoundException(request.UserId);
            }

            if (user.Locked)
            {
                throw new UserLockedException(user.Id);
            }

            var author = new Author(user.Name);
            var story  = new Story(request.Id, request.Title, request.Text, author, request.Tags, _dateTimeProvider.Now);
            await _storyRepository.AddAsync(story);

            _logger.LogInformation($"Added a story with ID: '{story.Id}'.");
        }
コード例 #9
0
        public async Task <ActionResult> Post(SendStory command)
        {
            await _storyService.AddAsync(command);

            return(CreatedAtAction(nameof(Get), new { storyId = command.Id }, null));
        }
コード例 #10
0
        public async Task <long?> SendStoryAsync(SendStory command)
        {
            var response = await _moduleClient.RequestAsync <SendStory.Response>($"{Module}/send-story", command);

            return(response?.StoryId);
        }
コード例 #11
0
 private Task Act(SendStory command) => _handler.HandleAsync(command);
コード例 #12
0
        public async Task <ActionResult> Post([FromBody] SendStory request)
        {
            await _storyService.AddAsync(request);

            return(CreatedAtAction(nameof(Get), new { storyId = request.Id }, null));
        }