private bool ValidateModelValues(CombinedAllowedValuesProviderModel model, object values)
        {
            model.Values = values;

            var context = new ValidationContext(model)
            {
                MemberName = nameof(model.Values)
            };

            return(Validator.TryValidateProperty(model.Values, context, new List <ValidationResult>()));
        }
        public void AllowedValuesAndProviderAreCombined()
        {
            var model = new CombinedAllowedValuesProviderModel();

            Assert.True(ValidateModelValues(model, ListOf <string>()));
            Assert.True(ValidateModelValues(model, ListOf("a")));
            Assert.True(ValidateModelValues(model, ListOf("b")));
            Assert.True(ValidateModelValues(model, ListOf("c")));
            Assert.True(ValidateModelValues(model, ListOf("a", "b")));
            Assert.True(ValidateModelValues(model, ListOf("a", "b", "c")));
            Assert.True(ValidateModelValues(model, ListOf("a", "a", "b")));
            Assert.True(ValidateModelValues(model, ListOf("a", "a", "b", "b")));
            Assert.True(ValidateModelValues(model, ListOf("a", "a", "b", "b", "c")));
            Assert.True(ValidateModelValues(model, ListOf("a", "a", "b", "b", "c", "c")));
        }
        public void AllowedValuesAndProviderAreCombined_Invalid()
        {
            var model = new CombinedAllowedValuesProviderModel();

            Assert.False(ValidateModelValues(model, ListOf("A")));
            Assert.False(ValidateModelValues(model, ListOf("A", "a")));
            Assert.False(ValidateModelValues(model, ListOf("d")));
            Assert.False(ValidateModelValues(model, ListOf("d", "a")));
            Assert.False(ValidateModelValues(model, ListOf("d", "a", "a")));
            Assert.False(ValidateModelValues(model, ListOf("d", "a", "b", "c")));
            Assert.False(ValidateModelValues(model, ListOf("d", "d")));
            Assert.False(ValidateModelValues(model, ListOf("d", "d", "a")));
            Assert.False(ValidateModelValues(model, ListOf("d", "d", "a", "a")));
            Assert.False(ValidateModelValues(model, ListOf("d", "d", "a", "b", "c")));
            Assert.False(ValidateModelValues(model, ListOf(1)));
            Assert.False(ValidateModelValues(model, ListOf(new { })));
            Assert.False(ValidateModelValues(model, ListOf <object>("a", 1, new { })));
        }