-
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.
Added unit tests for CategoryName value object
- Loading branch information
1 parent
63aedb7
commit 4cdc81e
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
server/tests/Questeloper.Tests.Unit/DomainTests/ValueObjects/CategoryNameTests.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,87 @@ | ||
using FluentAssertions; | ||
using Questeloper.Domain.Exceptions; | ||
using Questeloper.Domain.ValueObjects; | ||
|
||
namespace Questeloper.Tests.Unit.DomainTests.ValueObjects; | ||
|
||
public class CategoryNameTests | ||
{ | ||
[Fact] | ||
public void Constructor_WhenValueIsNull_ShouldThrowValueIsEmptyException() | ||
{ | ||
// Act | ||
var act = () => new CategoryName(null); | ||
|
||
// Assert | ||
act.Should().Throw<ValueIsEmptyException>(); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WhenValueIsWhitespace_ShouldThrowValueIsEmptyException() | ||
{ | ||
// Act | ||
var act = () => new CategoryName(" "); | ||
|
||
// Assert | ||
act.Should().Throw<ValueIsEmptyException>(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("abc")] | ||
public void Constructor_ForValidValue_ShouldNotThrow(string validValue) | ||
{ | ||
// Act | ||
var act = () => new CategoryName(validValue); | ||
|
||
// Assert | ||
act.Should().NotThrow(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("ab")] | ||
public void Constructor_WhenValueIsIncorrectLength_ShouldThrowValueIncorrectLengthException(string invalidValue) | ||
{ | ||
// Act | ||
Action act = () => new CategoryName(invalidValue); | ||
|
||
// Assert | ||
act.Should().Throw<ValueIncorrectLengthException>(); | ||
} | ||
|
||
[Fact] | ||
public void ImplicitConversion_ToString_ShouldReturnCorrectStringValue() | ||
{ | ||
// Arrange | ||
var categoryName = new CategoryName("Programming"); | ||
|
||
// Act | ||
string result = categoryName; | ||
|
||
// Assert | ||
result.Should().Be("Programming"); | ||
} | ||
|
||
[Fact] | ||
public void ExplicitConversion_FromString_ShouldCreateValidObject() | ||
{ | ||
// Act | ||
var categoryName = (CategoryName)"Design"; | ||
|
||
// Assert | ||
categoryName.Should().NotBeNull(); | ||
categoryName.Value.Should().Be("Design"); | ||
} | ||
|
||
[Fact] | ||
public void ToString_Invoked_ShouldReturnCorrectValue() | ||
{ | ||
// Arrange | ||
var categoryName = new CategoryName("Art"); | ||
|
||
// Act | ||
var result = categoryName.ToString(); | ||
|
||
// Assert | ||
result.Should().Be("Art"); | ||
} | ||
} |