Exemple #1
0
        public async Task CreateAttractionCategory_ShouldReturnSuccessWithCreatedData()
        {
            var client = _factory.GetClient();

            var token = ApiTokenHelper.GenerateFakeToken();

            client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");

            var command = new CreateAttractionCategoryCommand
            {
                Name = "Fountain"
            };

            var content  = Utilities.GetRequestContent(command);
            var response = await client.PostAsync($"/attractioncategories", content);

            response.EnsureSuccessStatusCode();

            var result = await Utilities.GetResponseContent <Application.Features.AttractionCategories.Commands.CreateAttractionCategory.AttractionCategoryDto>(response);

            result.Should().BeOfType(typeof(Application.Features.AttractionCategories.Commands.CreateAttractionCategory.AttractionCategoryDto));
            result.Should().NotBeNull();
            response.StatusCode.Should().Be(HttpStatusCode.Created);
            response.Headers.Location.LocalPath.Should().Be($"/AttractionCategories/{result.Id}");
        }
Exemple #2
0
        public async Task <ActionResult <AttractionCategoryDto> > CreateCity
            ([FromBody] CreateAttractionCategoryCommand createAttractionCategoryCommand)
        {
            var response = await _mediator.Send(createAttractionCategoryCommand);

            return(CreatedAtAction(nameof(GetAttractionCategoryDetails), new { id = response.Id }, response));
        }
Exemple #3
0
        public void Handle_InvalidCommand_TooLongName_ShouldThrowValidationException()
        {
            var handler = new CreateAttractionCategoryCommandHandler(_mapper, _mockAttractionCategoryRepository.Object);
            var command = new CreateAttractionCategoryCommand {
                Name = "ThisNameShouldHaveMoreThan50CharactersSoINeedToAddAFewMoreThisNameShouldHaveMoreThan50CharactersSoINeedToAddAFewMore"
            };

            Func <Task> func = async() => await handler.Handle(command, CancellationToken.None);

            func.Should().Throw <ValidationException>().Where(e => e.Errors.Any(x => x.Contains("must not exceed 100 characters")));

            _mockAttractionCategoryRepository.Verify(repo => repo.AddAsync(It.IsAny <AttractionCategory>()), Times.Never());
        }
Exemple #4
0
        public async Task CreateAttractionCategory_ShouldReturnUnauthorized()
        {
            var client = _factory.GetClient();

            var command = new CreateAttractionCategoryCommand
            {
                Name = "Fountain"
            };

            var content  = Utilities.GetRequestContent(command);
            var response = await client.PostAsync($"/attractioncategories", content);

            response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }