-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* perf: decrease tests on phone validation (#12) * perf: decrease tests on phone validation * Refactor way to customize Validators * Change way to handle custom validation options * Update appveyor.yml * upgrade packages
- Loading branch information
Showing
23 changed files
with
271 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"projects": [ "src", "test" ], | ||
"sdk": { | ||
"version": "2.2.102" | ||
"version": "2.2.401" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...t.Br/Validation/BankContractExtensions.cs → ...t.Br/Extensions/BankContractExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...Br/Validation/PersonContractExtensions.cs → ...Br/Extensions/PersonContractExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Flunt.Br.Validations.PhoneValidations; | ||
using Flunt.Validations; | ||
|
||
namespace Flunt.Br.Extensions | ||
{ | ||
public static partial class ContractExtensions | ||
{ | ||
public static Contract IsPhone(this Contract contract, string value, string property, string message) | ||
{ | ||
if (string.IsNullOrEmpty(value) || !new Phone().Validate(value)) | ||
contract.AddNotification(property, message); | ||
return contract; | ||
} | ||
|
||
public static Contract IsPhone(this Contract contract, string value, string numberFormat, string property, string message, bool strictNineDigit = false) | ||
{ | ||
var result = new Phone(new PhoneValidationOptions { Format = numberFormat, StrictNineDigit = strictNineDigit }).Validate(value); | ||
if (string.IsNullOrEmpty(value) || !result) | ||
contract.AddNotification(property, message); | ||
return contract; | ||
} | ||
|
||
public static Contract IsCellPhone(this Contract contract, string value, string property, string message, bool strictNineDigit = false) | ||
{ | ||
var result = new Phone(new PhoneValidationOptions { StrictNineDigit = strictNineDigit, CellPhonesOnly = true }).Validate(value); | ||
if (string.IsNullOrEmpty(value) || !result) | ||
contract.AddNotification(property, message); | ||
return contract; | ||
} | ||
|
||
public static Contract IsNewFormatCellPhone(this Contract contract, string value, string property, string message) | ||
{ | ||
var result = new Phone(new PhoneValidationOptions { StrictNineDigit = true, CellPhonesOnly = true }).Validate(value); | ||
if (string.IsNullOrEmpty(value) || !result) | ||
contract.AddNotification(property, message); | ||
return contract; | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...Br/Validation/StreetContractExtensions.cs → ...Br/Extensions/StreetContractExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
11 changes: 6 additions & 5 deletions
11
src/Flunt.Br/Document/Cep.cs → src/Flunt.Br/Validations/Cep.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
using Flunt.Br.Document.Interfaces; | ||
using System.Text.RegularExpressions; | ||
using Flunt.Br.Document.interfaces; | ||
|
||
namespace Flunt.Br.Document | ||
namespace Flunt.Br.Validations | ||
{ | ||
internal class Cep : IValidate | ||
{ | ||
public bool Validate(string value) | ||
{ | ||
if (value.IndexOf("-") > 0) | ||
if (value.IndexOf("-") > 0) | ||
{ | ||
return new Regex(@"^\d{5}-\d{3}$", RegexOptions.Singleline).Match(value).Success; | ||
else | ||
return new Regex(@"^\d{8}$", RegexOptions.Singleline).Match(value).Success; | ||
} | ||
return new Regex(@"^\d{8}$", RegexOptions.Singleline).Match(value).Success; | ||
} | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
src/Flunt.Br/Document/Cnpj.cs → src/Flunt.Br/Validations/Cnpj.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.