Пример #1
0
        public Task <object?> InvokeAsync(QueryContext context, CancellationToken cancellationToken)
        {
            try { DataAnnotationsValidator.Validate(context.Query, context.ScopedServices); }
            catch (ValidationException ex) { throw ServiceErrorException.From(ex); }

            return(_next(context, cancellationToken));
        }
Пример #2
0
        public void RespectsNullableRefTypeAnnotation()
        {
            var command = new GetUserQuery {
            };

            var validationEx = Assert.Throws <ValidationException>(() => DataAnnotationsValidator.Validate(command));

            Assert.IsType <RequiredAttribute>(validationEx.ValidationAttribute);
            Assert.Equal(new[] { nameof(command.Identifier) }, validationEx.ValidationResult.MemberNames);

            var serviceErrorEx = ServiceErrorException.From(validationEx);

            Assert.Equal(ServiceErrorCode.ParamNotSpecified, serviceErrorEx.ErrorCode);
            Assert.Equal(new[] { nameof(command.Identifier) }, serviceErrorEx.Args);
        }
Пример #3
0
        public void ChecksNestedProperty()
        {
            var command = new GetUserQuery
            {
                Identifier = new UserIdentifier.Name {
                }
            };

            var validationEx = Assert.Throws <ValidationException>(() => DataAnnotationsValidator.Validate(command));

            Assert.IsType <RequiredAttribute>(validationEx.ValidationAttribute);
            Assert.Equal(new[] { nameof(UserIdentifier.Name.Value) }, validationEx.ValidationResult.MemberNames);

            var serviceErrorEx = ServiceErrorException.From(validationEx);

            Assert.Equal(ServiceErrorCode.ParamNotSpecified, serviceErrorEx.ErrorCode);
            Assert.Equal(new[] { nameof(command.Identifier) + "." + nameof(UserIdentifier.Name.Value) }, serviceErrorEx.Args);
        }
Пример #4
0
        public void RespectsIValidatableObjectImplementation()
        {
            var command = new ApproveUserCommand
            {
                UserName          = "******",
                Verify            = true,
                VerificationToken = null
            };

            var validationEx = Assert.Throws <ValidationException>(() => DataAnnotationsValidator.Validate(command));

            Assert.IsType <ExtendedValidationResult>(validationEx.ValidationResult);
            Assert.IsType <RequiredAttribute>(validationEx.ValidationAttribute);
            Assert.Equal(new[] { nameof(command.VerificationToken) }, validationEx.ValidationResult.MemberNames);

            var serviceErrorEx = ServiceErrorException.From(validationEx);

            Assert.Equal(ServiceErrorCode.ParamNotSpecified, serviceErrorEx.ErrorCode);
            Assert.Equal(new[] { nameof(command.VerificationToken) }, serviceErrorEx.Args);
        }