Skip to content

Commit

Permalink
Develop (#14)
Browse files Browse the repository at this point in the history
* 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
lira92 authored Sep 22, 2019
1 parent 1acdacd commit 3c61028
Show file tree
Hide file tree
Showing 23 changed files with 271 additions and 339 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This lib enables in your validation contracts this methods:
.IsCnpj(company.document, "Document", "Invalid document")
.IsPhone(company.phone, "Phone", "Invalid phone")
.IsCellPhone(person.cellphone, "Phone", "Invalid cellphone")
.IsNewFormatCellPhone(person.cellphone, "Phone", "Invalid cellphone")
.IsCep(company.Cep, "Cep", "Invalid Cep")
```

Expand All @@ -52,6 +53,7 @@ Essa biblioteca possibilita esses métodos em seus Validation Contracts:
.IsCnpj(empresa.documento, "Documento", "Documento inválido")
.IsPhone(empresa.telefone, "Telefone", "Telefone inválido")
.IsCellPhone(pessoa.telefone, "Telefone", "Telefone inválido")
.IsNewFormatCellPhone(pessoa.telefone, "Telefone", "Telefone inválido")
.IsCep(company.Cep, "Cep", "Cep Inválido");
```

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 1.0.{build}
image: Visual Studio 2017 Preview
image: Ubuntu1804
dotnet_csproj:
patch: true
file: '**\*.csproj'
Expand Down
2 changes: 1 addition & 1 deletion global.json
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"
}
}
206 changes: 0 additions & 206 deletions src/Flunt.Br/Document/Phone.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Flunt.Br.Document;
using Flunt.Br.Validations;
using Flunt.Validations;

namespace Flunt.Br.Validation
namespace Flunt.Br.Extensions
{
public static partial class ContractExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using Flunt.Br.Document;
using Flunt.Br.Validations;
using Flunt.Validations;
using System;

namespace Flunt.Br.Validation
namespace Flunt.Br.Extensions
{
public static partial class ContractExtensions
{
Expand Down
39 changes: 39 additions & 0 deletions src/Flunt.Br/Extensions/PhoneContractExtensions.cs
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Flunt.Br.Document;
using Flunt.Br.Validations;
using Flunt.Validations;

namespace Flunt.Br.Validation
namespace Flunt.Br.Extensions
{
public static partial class ContractExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion src/Flunt.Br/Flunt.Br.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<PackageTags>Validation;Flunt.Br;Flunt;Cnpj;Cpf;Telefone;Cep</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Flunt" Version="1.0.3" />
<PackageReference Include="Flunt" Version="1.0.4" />
</ItemGroup>
</Project>
33 changes: 0 additions & 33 deletions src/Flunt.Br/Validation/PhoneContractExtensions.cs

This file was deleted.

11 changes: 6 additions & 5 deletions src/Flunt.Br/Document/Cep.cs → src/Flunt.Br/Validations/Cep.cs
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Flunt.Br.Document.interfaces;
using System;
using Flunt.Br.Document.Interfaces;

namespace Flunt.Br.Document
namespace Flunt.Br.Validations
{
internal class Cnpj : IValidate
{
Expand Down
Loading

0 comments on commit 3c61028

Please sign in to comment.