-
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
bfc725c
commit 46380d6
Showing
10 changed files
with
112 additions
and
62 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 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,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace Validador.Application.Errors | ||
{ | ||
public static class ErrorFactory | ||
{ | ||
public static ValidationError Create(string errorMessage) | ||
{ | ||
switch (errorMessage) | ||
{ | ||
default: | ||
return new GenericValidationError(errorMessage); | ||
case var messagem when new Regex(@"The Pattern constraint failed").IsMatch(messagem): | ||
return new PatternConstraintFailed(errorMessage); | ||
case var messagem when new Regex(@"List of possible elements expected").IsMatch(messagem): | ||
return new InvalidChildElement(errorMessage); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
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,17 @@ | ||
using System.Xml.Schema; | ||
|
||
namespace Validador.Application.Errors | ||
{ | ||
public class GenericValidationError : ValidationError | ||
{ | ||
public GenericValidationError(string message) : base(message) | ||
{ | ||
SeverityType = XmlSeverityType.Warning; | ||
} | ||
|
||
public override string CreateValidationMessage() | ||
{ | ||
return string.Format("Erro de validação: '{0}'", 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Text.RegularExpressions; | ||
using System.Xml.Schema; | ||
|
||
namespace Validador.Application.Errors | ||
{ | ||
public class InvalidChildElement : ValidationError | ||
{ | ||
public InvalidChildElement(string message) : base(message) { | ||
SeverityType = XmlSeverityType.Error; | ||
} | ||
|
||
public const string Pattern = @"element '(\w+)'.*element '(\w+)'.*expected: '(\w+)'"; | ||
|
||
public override string CreateValidationMessage() | ||
{ | ||
Match match = new Regex(Pattern).Match(Message); | ||
return string.Format("O elemento '{0}' possui elemento filho inválido: '{1}'. Era esperado o elemento: '{2}'", match.Groups[1].Value, match.Groups[2].Value, match.Groups[3].Value); | ||
} | ||
} | ||
} |
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,20 @@ | ||
using System.Text.RegularExpressions; | ||
using System.Xml.Schema; | ||
|
||
namespace Validador.Application.Errors | ||
{ | ||
public class PatternConstraintFailed : ValidationError | ||
{ | ||
public PatternConstraintFailed(string message) : base(message) { | ||
SeverityType = XmlSeverityType.Error; | ||
} | ||
|
||
public const string Pattern = @"'(.+)'.*'(.+)'.*'(.+)'"; | ||
|
||
public override string CreateValidationMessage() | ||
{ | ||
Match match = new Regex(Pattern).Match(Message); | ||
return string.Format("O elemento '{0}' é inválido. O valor '{1}' não está de acordo com os tipos definidos em: {2}'", match.Groups[1].Value, match.Groups[2].Value, match.Groups[3].Value); | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System.Xml.Schema; | ||
|
||
namespace Validador.Application.Errors | ||
{ | ||
public abstract class ValidationError : Exception | ||
{ | ||
public ValidationError(string message) : base(message) | ||
{ | ||
} | ||
public string ValidationMessage | ||
{ | ||
get | ||
{ | ||
return CreateValidationMessage(); | ||
} | ||
} | ||
|
||
public abstract string CreateValidationMessage(); | ||
public XmlSeverityType SeverityType { get; set; } | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.