Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

60 řádky
1.9KB

  1. using CartWise.Domain.Entities;
  2. using CartWise.Domain.Enums;
  3. namespace CartWise.Domain.Tests;
  4. public class ProductTests
  5. {
  6. private static readonly DateTime Now = new(2026, 8, 10, 12, 0, 0, DateTimeKind.Utc);
  7. [Fact]
  8. public void Constructor_SetsNormalizedName()
  9. {
  10. var product = new Product("Jif Creamy Peanut Butter", ProductSourceType.Manual, Now);
  11. Assert.Equal("JIF CREAMY PEANUT BUTTER", product.NormalizedName);
  12. }
  13. [Theory]
  14. [InlineData("")]
  15. [InlineData(" ")]
  16. [InlineData(null)]
  17. public void Constructor_ThrowsWhenNameIsMissing(string? name)
  18. {
  19. Assert.Throws<ArgumentException>(() => new Product(name!, ProductSourceType.Manual, Now));
  20. }
  21. [Fact]
  22. public void AddIdentifier_AddsNormalizedIdentifier()
  23. {
  24. var product = new Product("Jif Creamy 16 oz", ProductSourceType.Manual, Now);
  25. var identifier = product.AddIdentifier(ProductIdentifierType.UpcA, " 051500255516 ");
  26. Assert.Single(product.Identifiers);
  27. Assert.Equal("051500255516", identifier.NormalizedValue);
  28. Assert.Equal(product.ProductId, identifier.ProductId);
  29. }
  30. [Fact]
  31. public void AddIdentifier_ThrowsForDuplicateIdentifier()
  32. {
  33. var product = new Product("Jif Creamy 16 oz", ProductSourceType.Manual, Now);
  34. product.AddIdentifier(ProductIdentifierType.UpcA, "051500255516");
  35. Assert.Throws<InvalidOperationException>(() => product.AddIdentifier(ProductIdentifierType.UpcA, "051500255516"));
  36. }
  37. [Fact]
  38. public void AddIdentifier_AllowsSameValueUnderDifferentType()
  39. {
  40. var product = new Product("Jif Creamy 16 oz", ProductSourceType.Manual, Now);
  41. product.AddIdentifier(ProductIdentifierType.UpcA, "051500255516");
  42. var identifier = product.AddIdentifier(ProductIdentifierType.Gtin, "051500255516");
  43. Assert.Equal(2, product.Identifiers.Count);
  44. Assert.Equal(ProductIdentifierType.Gtin, identifier.IdentifierType);
  45. }
  46. }

Powered by TurnKey Linux.