-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Jack-Edwards/try-from
Implement validation without throwing exceptions
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using NUnit.Framework; | ||
|
||
namespace ValueOf.Tests | ||
{ | ||
public class TryValidateClientRef : ValueOf<string, TryValidateClientRef> | ||
{ | ||
protected override bool TryValidate() | ||
{ | ||
return !string.IsNullOrWhiteSpace(Value); | ||
} | ||
} | ||
|
||
public class TryValidation | ||
{ | ||
[Test] | ||
public void TryValidateReturnsFalse() | ||
{ | ||
bool isValid = TryValidateClientRef.TryFrom("", out TryValidateClientRef valueObject); | ||
|
||
Assert.IsFalse(isValid); | ||
Assert.IsNull(valueObject); | ||
} | ||
|
||
[Test] | ||
public void TryValidateReturnsTrue() | ||
{ | ||
bool isValid = TryValidateClientRef.TryFrom("something", out TryValidateClientRef valueObject); | ||
|
||
Assert.IsTrue(isValid); | ||
Assert.IsNotNull(valueObject); | ||
Assert.AreEqual("something", valueObject.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