Ejemplo n.º 1
0
        public static void ShouldBeLikeDefault(this IValidatorSettings @this)
        {
            @this.Should().NotBeNull();

            @this.Translations.Keys.Should().HaveCount(1);
            @this.Translations.Keys.Should().Contain("English");
            @this.Translations["English"].Should().NotBeNull();

            foreach (var pair in Translation.English)
            {
                @this.Translations["English"].Keys.Should().Contain(pair.Key);
                @this.Translations["English"][pair.Key].Should().Be(pair.Value);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates instance of <see cref="IValidator{T}"/> that can validate objects of type <typeparamref name="T"/> against the provided specification.
        /// </summary>
        /// <param name="specification">Specification used to validate models.</param>
        /// <param name="settings">Settings used to validate models.</param>
        /// <typeparam name="T">Type of the models that this instance of <see cref="IValidator{T}"/> can validate.</typeparam>
        /// <returns>Instance of <see cref="IValidator{T}"/>, fully initialized and ready to work.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="settings"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="settings"/> is not an instance of <see cref="ValidatorSettings"/>.</exception>
        public IValidator <T> Create <T>(Specification <T> specification, IValidatorSettings settings)
        {
            var modelScheme = ModelSchemeFactory.Create(specification);

            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (!(settings is ValidatorSettings validatorSettings))
            {
                throw new ArgumentException($"Custom {nameof(IValidatorSettings)} implementations are not supported.", nameof(settings));
            }

            validatorSettings.IsLocked = true;

            return(new Validator <T>(modelScheme, settings));
        }
Ejemplo n.º 3
0
 public ValidatorTests()
 {
     _settings  = new ValidatorSettings();
     _validator = new Validator(_settings);
 }
Ejemplo n.º 4
0
 public Validator(IValidatorSettings settings)
 {
     _settings = settings;
 }