示例#1
0
        public async Task AddAsync(Form form)
        {
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }

            if (forms.Any(_ => _.Key == form.Key))
            {
                throw new ArgumentException("form id already exist");
            }

            var context = new FormValidationContext(form);
            await formValidator.ValidateAsync(context);

            if (!context.IsValid)
            {
                throw new ArgumentException(context.ErrorMessage);
            }
            forms.Add(form);
        }
示例#2
0
        public async Task Valid_should_success()
        {
            var forms = TestData.FormDefinitions;

            foreach (var form in forms)
            {
                var context = new FormValidationContext(form);
                await validator.ValidateAsync(context);

                context.IsValid.Should().BeTrue();
            }
        }