-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb498f9
commit c2dc672
Showing
9 changed files
with
78 additions
and
36 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
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.
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,9 @@ | ||
namespace Product.Domain.Exceptions; | ||
|
||
public class DomainValidationException : Exception | ||
{ | ||
public DomainValidationException(string message) : base(message) | ||
{ | ||
|
||
} | ||
} |
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.
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,42 @@ | ||
using System.Security; | ||
using Product.Domain.Constants.Messages; | ||
using Product.Domain.Exceptions; | ||
|
||
namespace Product.Domain.ValueObjects; | ||
|
||
public class Ip : ValueObject | ||
{ | ||
private const int Lenght = 15; | ||
public string Value{ get;private set; } | ||
|
||
public Ip(string ip) | ||
{ | ||
SetValue(ip); | ||
} | ||
protected override IEnumerable<object> GetEqualityComponents() | ||
{ | ||
yield return Value; | ||
} | ||
|
||
private void SetValue(string value) | ||
{ | ||
if (string.IsNullOrWhiteSpace(value)) | ||
{ | ||
throw new DomainValidationException(ExceptionMessage.IpIsMandatry); | ||
} | ||
|
||
if (value.Length > Lenght || value.Length < Lenght) | ||
{ | ||
throw new DomainValidationException(ExceptionMessage.IpLenghtShouldBe(Lenght)); | ||
} | ||
|
||
if (IsIpValid(value)) | ||
{ | ||
throw new InvalidIpException(); | ||
} | ||
|
||
Value = value; | ||
} | ||
|
||
bool IsIpValid(string ip) => System.Net.IPAddress.TryParse(ip, out _); | ||
} |