diff options
author | 杨宇千 <crupest@outlook.com> | 2019-08-22 15:29:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-22 15:29:03 +0800 |
commit | 11f01c56b4ea1dbb09d04258bec89f800c6ee2b6 (patch) | |
tree | af83f8596b4fa78713733c0db6b4b6d1695d0ff0 /Timeline.Tests/UserDetailValidatorTest.cs | |
parent | fd95f9abc017575b13a31dd16ac72ef663e984d6 (diff) | |
parent | 96c18fb2e17c94ff04094608c705db087400f510 (diff) | |
download | timeline-11f01c56b4ea1dbb09d04258bec89f800c6ee2b6.tar.gz timeline-11f01c56b4ea1dbb09d04258bec89f800c6ee2b6.tar.bz2 timeline-11f01c56b4ea1dbb09d04258bec89f800c6ee2b6.zip |
Merge pull request #48 from crupest/user-details
Add user details.
Diffstat (limited to 'Timeline.Tests/UserDetailValidatorTest.cs')
-rw-r--r-- | Timeline.Tests/UserDetailValidatorTest.cs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Timeline.Tests/UserDetailValidatorTest.cs b/Timeline.Tests/UserDetailValidatorTest.cs new file mode 100644 index 00000000..9b112946 --- /dev/null +++ b/Timeline.Tests/UserDetailValidatorTest.cs @@ -0,0 +1,97 @@ +using FluentAssertions;
+using System.Collections.Generic;
+using Timeline.Models.Validation;
+using Xunit;
+
+namespace Timeline.Tests
+{
+ public static class UserDetailValidatorsTest
+ {
+ private static void SucceedWith<TValidator>(object value) where TValidator : class, IValidator, new()
+ {
+ var result = new TValidator().Validate(value, out var message);
+ result.Should().BeTrue();
+ message.Should().Equals(ValidationConstants.SuccessMessage);
+ }
+
+ private static void FailWith<TValidator>(object value, params string[] messageContains) where TValidator : class, IValidator, new()
+ {
+ var result = new TValidator().Validate(value, out var message);
+ result.Should().BeFalse();
+
+ foreach (var m in messageContains)
+ {
+ message.Should().ContainEquivalentOf(m);
+ }
+ }
+
+ public class QQ
+ {
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ [InlineData("12345678")]
+ public void Success(object qq)
+ {
+ SucceedWith<UserDetailValidators.QQValidator>(qq);
+ }
+
+ [Theory]
+ [InlineData(123, "type")]
+ [InlineData("123", "short")]
+ [InlineData("111111111111111111111111111111111111", "long")]
+ [InlineData("aaaaaaaa", "digit")]
+ public void Fail(object qq, string messageContains)
+ {
+ FailWith<UserDetailValidators.QQValidator>(qq, messageContains);
+ }
+ }
+
+ public class EMail
+ {
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ [InlineData("aaa@aaa.net")]
+ public void Success(object email)
+ {
+ SucceedWith<UserDetailValidators.EMailValidator>(email);
+ }
+
+ public static IEnumerable<object[]> FailTestData()
+ {
+ yield return new object[] { 123, "type" };
+ yield return new object[] { new string('a', 100), "long" };
+ yield return new object[] { "aaaaaaaa", "format" };
+ }
+
+ [Theory]
+ [MemberData(nameof(FailTestData))]
+ public void Fail(object email, string messageContains)
+ {
+ FailWith<UserDetailValidators.EMailValidator>(email, messageContains);
+ }
+ }
+
+ public class PhoneNumber
+ {
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ [InlineData("12345678910")]
+ public void Success(object phoneNumber)
+ {
+ SucceedWith<UserDetailValidators.PhoneNumberValidator>(phoneNumber);
+ }
+
+ [Theory]
+ [InlineData(123, "type")]
+ [InlineData("111111111111111111111111111111111111", "long")]
+ [InlineData("aaaaaaaa", "digit")]
+ public void Fail(object phoneNumber, string messageContains)
+ {
+ FailWith<UserDetailValidators.PhoneNumberValidator>(phoneNumber, messageContains);
+ }
+ }
+ }
+}
|