public async Task NumericFieldFluentValidationTest1() { var validator = new FluentValueValidator <string>(x => x.Cascade(CascadeMode.Stop) .NotEmpty() .Length(1, 100)); var comp = ctx.RenderComponent <MudNumericField <decimal> >(Parameter(nameof(MudNumericField <decimal> .Validation), validator.Validation), Parameter(nameof(MudNumericField <decimal> .Max), 100M)); var numericField = comp.Instance; Console.WriteLine(comp.Markup); // first try a valid value comp.Find("input").Change(99); numericField.Error.Should().BeFalse(because: "The value is < 100"); numericField.ErrorText.Should().BeNullOrEmpty(); // now try something that's outside of range comp.Find("input").Change("100.1"); numericField.Error.Should().BeFalse(because: "The value should be set to Max (100)"); numericField.Value.Should().Be(100M); Console.WriteLine("Error message: " + numericField.ErrorText); numericField.ErrorText.Should().BeNullOrEmpty(); }
public async Task TextFieldFluentValidationTest1() { var validator = new FluentValueValidator <string>(x => x.Cascade(CascadeMode.Stop) .NotEmpty() .Length(1, 100) .CreditCard()); var comp = Context.RenderComponent <MudTextField <string> >(Parameter(nameof(MudTextField <string> .Validation), validator.Validation)); var textfield = comp.Instance; //Console.WriteLine(comp.Markup); // first try a valid credit card number comp.Find("input").Change("4012 8888 8888 1881"); textfield.Error.Should().BeFalse(because: "The number is a valid VISA test credit card number"); textfield.ErrorText.Should().BeNullOrEmpty(); // now try something that produces a validation error comp.Find("input").Change("0000 1111 2222 3333"); textfield.Error.Should().BeTrue(because: "The credit card number is fake"); //Console.WriteLine("Error message: " + textfield.ErrorText); textfield.ErrorText.Should().NotBeNullOrEmpty(); }