public async Task CreateGroup_NameTooLong_BadRequest()
        {
            // Arrange
            var dto = GetGroupDto();

            dto.Name = RandomFactory.GetAlphanumericString(Constants.MaximumLengths.StringColumn + 1);

            // Act
            using var response = await Client.PostAsJsonAsync("/api/groups", dto);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public void GroupDtoValidation_NameTooLong_HasValidationErrors()
        {
            var dto = new GroupDto
            {
                Name = RandomFactory.GetAlphanumericString(Constants.MaximumLengths.StringColumn + 1),
            };

            var validationContext = new ValidationContext(dto);

            var validationResults = dto.Validate(validationContext);

            validationResults.Should().HaveCountGreaterThan(0);
            validationResults.FirstOrDefault(validationResult => validationResult.MemberNames.Any(memberName => memberName.Equals(nameof(GroupDto.Name))))?.Should().NotBeNull();
        }
Esempio n. 3
0
        public async Task UpdateGroup_NameTooLong_BadRequest()
        {
            // Arrange
            Data.Models.Group randomGroup = null;
            ServiceProvider.ExecuteWithDbScope(db => randomGroup = SeedHelper.GetRandomGroup(db));
            var dto = Mapper.Map <GroupDto>(randomGroup);

            dto.Name = RandomFactory.GetAlphanumericString(Constants.MaximumLengths.StringColumn + 1);

            // Act
            using var response = await Client.PutAsJsonAsync("/api/groups", dto);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }