Skip to content

Commit

Permalink
Added unit tests for CategoryName value object
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinKanarDev committed Mar 28, 2024
1 parent 63aedb7 commit 4cdc81e
Showing 1 changed file with 87 additions and 0 deletions.
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");
}
}

0 comments on commit 4cdc81e

Please sign in to comment.