-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
eb17d05
commit f6ae751
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/Modules/Products/Modules.Catalog.Tests/CatalogTests.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,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(); | ||
} | ||
} |