|
- using CartWise.Domain.Entities;
- using CartWise.Domain.Enums;
-
- namespace CartWise.Domain.Tests;
-
- public class PurchaseTests
- {
- private static readonly DateTime Now = new(2026, 8, 10, 12, 0, 0, DateTimeKind.Utc);
-
- [Fact]
- public void Constructor_DefaultsToManualSourceAndNoStore()
- {
- var purchase = new Purchase(Guid.NewGuid(), "user-1", Now, Now);
-
- Assert.Equal(PurchaseSourceType.Manual, purchase.SourceType);
- Assert.Null(purchase.StoreLocationId);
- Assert.Empty(purchase.Items);
- }
-
- [Fact]
- public void Constructor_ThrowsWhenHouseholdIdIsEmpty()
- {
- Assert.Throws<ArgumentException>(() => new Purchase(Guid.Empty, "user-1", Now, Now));
- }
-
- [Theory]
- [InlineData("")]
- [InlineData(" ")]
- [InlineData(null)]
- public void Constructor_ThrowsWhenPurchasedByUserIdIsMissing(string? userId)
- {
- Assert.Throws<ArgumentException>(() => new Purchase(Guid.NewGuid(), userId!, Now, Now));
- }
- }
-
- public class PurchaseItemTests
- {
- private static readonly DateTime Now = new(2026, 8, 10, 12, 0, 0, DateTimeKind.Utc);
-
- [Fact]
- public void Constructor_DefaultsQuantityToOne()
- {
- var item = new PurchaseItem(Guid.NewGuid(), "Milk", 3.99m, Now);
-
- Assert.Equal(1m, item.Quantity);
- Assert.Equal(3.99m, item.LinePrice);
- }
-
- [Theory]
- [InlineData("")]
- [InlineData(" ")]
- [InlineData(null)]
- public void Constructor_ThrowsWhenDescriptionIsMissing(string? description)
- {
- Assert.Throws<ArgumentException>(() => new PurchaseItem(Guid.NewGuid(), description!, 3.99m, Now));
- }
-
- [Fact]
- public void Constructor_ThrowsWhenQuantityIsZeroOrNegative()
- {
- Assert.Throws<ArgumentOutOfRangeException>(() => new PurchaseItem(Guid.NewGuid(), "Milk", 3.99m, Now, quantity: 0));
- Assert.Throws<ArgumentOutOfRangeException>(() => new PurchaseItem(Guid.NewGuid(), "Milk", 3.99m, Now, quantity: -1));
- }
-
- [Fact]
- public void Constructor_ThrowsWhenLinePriceIsNegative()
- {
- Assert.Throws<ArgumentOutOfRangeException>(() => new PurchaseItem(Guid.NewGuid(), "Milk", -1m, Now));
- }
- }
|