From f6ae751280f6c721d9072765f7c997d0fdeb7671 Mon Sep 17 00:00:00 2001 From: "Daniel Mackay [SSW]" <2636640+danielmackay@users.noreply.github.com> Date: Sun, 18 Aug 2024 18:14:07 +1000 Subject: [PATCH] Add unit tests for Category creation in Catalog module Introduce tests to ensure Category creation throws exceptions for null, empty, and whitespace names. Also, verify correct Category creation with valid name. --- .../Modules.Catalog.Tests/CatalogTests.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/Modules/Products/Modules.Catalog.Tests/CatalogTests.cs diff --git a/src/Modules/Products/Modules.Catalog.Tests/CatalogTests.cs b/src/Modules/Products/Modules.Catalog.Tests/CatalogTests.cs new file mode 100644 index 0000000..e5449be --- /dev/null +++ b/src/Modules/Products/Modules.Catalog.Tests/CatalogTests.cs @@ -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(); + } + + [Fact] + public void Create_ShouldThrowException_WhenNameIsEmpty() + { + // Arrange + Action act = () => Category.Create(string.Empty); + + // Act & Assert + act.Should().Throw(); + } + + [Fact] + public void Create_ShouldThrowException_WhenNameIsWhiteSpace() + { + // Arrange + Action act = () => Category.Create(" "); + + // Act & Assert + act.Should().Throw(); + } + + [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(); + } +}