Skip to content

Commit

Permalink
Add unit tests for Category creation in Catalog module
Browse files Browse the repository at this point in the history
Introduce tests to ensure Category creation throws exceptions for null, empty, and whitespace names. Also, verify correct Category creation with valid name.
  • Loading branch information
danielmackay committed Aug 18, 2024
1 parent eb17d05 commit f6ae751
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/Modules/Products/Modules.Catalog.Tests/CatalogTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using FluentAssertions;
using Modules.Catalog.Categories.Domain;

namespace Modules.Catalog.Tests;

public class CatalogTests
{
[Fact]
public void Create_ShouldThrowException_WhenNameIsNull()
{
// Arrange
Action act = () => Category.Create(null!);

// Act & Assert
act.Should().Throw<ArgumentException>();
}

[Fact]
public void Create_ShouldThrowException_WhenNameIsEmpty()
{
// Arrange
Action act = () => Category.Create(string.Empty);

// Act & Assert
act.Should().Throw<ArgumentException>();
}

[Fact]
public void Create_ShouldThrowException_WhenNameIsWhiteSpace()
{
// Arrange
Action act = () => Category.Create(" ");

// Act & Assert
act.Should().Throw<ArgumentException>();
}

[Fact]
public void Create_ShouldReturnCategory_WhenNameIsValid()
{
// Arrange
var name = "ValidName";

// Act
var category = Category.Create(name);

// Assert
category.Name.Should().Be(name);
category.Id.Should().NotBeNull();
}
}

0 comments on commit f6ae751

Please sign in to comment.