public async Task MultiValidatorTest() { MultiValidator.Validators.AddRange(new[] { typeof(DataValidator <>), typeof(SQLInjectionValidator <>) }); UpdateUserProfileDataRequestDto message = new UpdateUserProfileDataRequestDto() { NewBiography = null, NewEmail = ";DROP TABLE test;", NewPassword = null, NewPhoneNumber = null, OldBiography = null, OldEmail = "*****@*****.**", OldPassword = null, OldPhoneNumber = null, UserID = -2 }; bool result = await MultiValidator <UpdateUserProfileDataRequestDto> .IsValid(message); result.Should().BeFalse(); message.NewEmail = "*****@*****.**"; result = await MultiValidator <UpdateUserProfileDataRequestDto> .IsValid(message); result.Should().BeFalse(); message.NewEmail = ";DROP TABLE test;"; message.UserID = 2; result = await MultiValidator <UpdateUserProfileDataRequestDto> .IsValid(message); result.Should().BeFalse(); message.NewEmail = "*****@*****.**"; result = await MultiValidator <UpdateUserProfileDataRequestDto> .IsValid(message); result.Should().BeTrue(); }
public static Task <bool> IsValid <T>(this T obj) => MultiValidator <T> .IsValid(obj);