-
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.
[BDB-14] Create rule StringMustNotContainAnyWhiteSpace
- Loading branch information
1 parent
849435a
commit 5441afb
Showing
10 changed files
with
97 additions
and
44 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
26 changes: 26 additions & 0 deletions
26
Core/BuildingBlock.Core.Domain/Rules/Implementations/StringMustNotContainAnyWhiteSpace.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using BuildingBlock.Core.Domain.Rules.Abstractions; | ||
|
||
namespace BuildingBlock.Core.Domain.Rules.Implementations; | ||
|
||
public class StringMustNotContainAnyWhiteSpace : IBusinessRule | ||
{ | ||
private readonly string _name; | ||
private readonly string _value; | ||
|
||
public StringMustNotContainAnyWhiteSpace(string value, string name) | ||
{ | ||
_value = value; | ||
_name = name; | ||
} | ||
|
||
public string? Message { get; private set; } | ||
|
||
public bool IsBroken() | ||
{ | ||
if (!_value.Contains(' ')) return false; | ||
|
||
Message = $"{_name} with value: '{_value}' can not contain any white space."; | ||
|
||
return true; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Core/BuildingBlock.Core.Domain/Shared/Utils/ValueObjectUtility.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
1 change: 1 addition & 0 deletions
1
Core/BuildingBlock.Core.Domain/ValueObjects/Abstractions/PositiveIntegerRange.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 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
43 changes: 43 additions & 0 deletions
43
Tests/BuildingBlock.Test.UnitTest/Core/Domain/Rules/StringMustNotContainAnyWhiteSpaceTest.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using BuildingBlock.Core.Domain.Rules.Implementations; | ||
using FluentAssertions; | ||
|
||
namespace Tests.Core.Domain.Rules; | ||
|
||
public class StringMustNotContainAnyWhiteSpaceTest | ||
{ | ||
public class ShouldReturnTrue | ||
{ | ||
[Fact] | ||
public void WhenStringContainsWhiteSpace() | ||
{ | ||
// Arrange | ||
var stringMustNotContainAnyWhiteSpace = | ||
new StringMustNotContainAnyWhiteSpace("String with white space", "string"); | ||
|
||
// Act | ||
var result = stringMustNotContainAnyWhiteSpace.IsBroken(); | ||
|
||
// Assert | ||
result.Should().BeTrue(); | ||
stringMustNotContainAnyWhiteSpace.Message.Should() | ||
.Be("string with value: 'String with white space' can not contain any white space."); | ||
} | ||
} | ||
|
||
public class ShouldReturnFalse | ||
{ | ||
[Fact] | ||
public void WhenStringDoesNotContainWhiteSpace() | ||
{ | ||
// Arrange | ||
var stringMustNotContainAnyWhiteSpace = | ||
new StringMustNotContainAnyWhiteSpace("StringWithoutWhiteSpace", "string"); | ||
|
||
// Act | ||
var result = stringMustNotContainAnyWhiteSpace.IsBroken(); | ||
|
||
// Assert | ||
result.Should().BeFalse(); | ||
} | ||
} | ||
} |
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