Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

59 linhas
2.1KB

  1. using CartWise.Domain.Entities;
  2. using CartWise.Domain.Enums;
  3. using System.Reflection;
  4. namespace CartWise.Domain.Tests;
  5. public class PriceObservationTests
  6. {
  7. private static readonly DateTime Now = new(2026, 8, 10, 12, 0, 0, DateTimeKind.Utc);
  8. [Fact]
  9. public void Constructor_SetsDefaultCurrencyCode()
  10. {
  11. var observation = new PriceObservation(Guid.NewGuid(), 3.99m, Now, PriceObservationSourceType.UserEntered, 1m, Now);
  12. Assert.Equal("USD", observation.CurrencyCode);
  13. }
  14. [Fact]
  15. public void Constructor_ThrowsWhenProductIdIsEmpty()
  16. {
  17. Assert.Throws<ArgumentException>(() => new PriceObservation(Guid.Empty, 3.99m, Now, PriceObservationSourceType.UserEntered, 1m, Now));
  18. }
  19. [Fact]
  20. public void Constructor_ThrowsWhenPriceIsNegative()
  21. {
  22. Assert.Throws<ArgumentOutOfRangeException>(() => new PriceObservation(Guid.NewGuid(), -1m, Now, PriceObservationSourceType.UserEntered, 1m, Now));
  23. }
  24. [Theory]
  25. [InlineData(-0.01)]
  26. [InlineData(1.01)]
  27. public void Constructor_ThrowsWhenConfidenceScoreIsOutOfRange(decimal confidence)
  28. {
  29. Assert.Throws<ArgumentOutOfRangeException>(() => new PriceObservation(Guid.NewGuid(), 3.99m, Now, PriceObservationSourceType.UserEntered, confidence, Now));
  30. }
  31. [Fact]
  32. public void Constructor_ThrowsWhenCurrencyCodeIsNotThreeLetters()
  33. {
  34. Assert.Throws<ArgumentException>(() => new PriceObservation(Guid.NewGuid(), 3.99m, Now, PriceObservationSourceType.UserEntered, 1m, Now, currencyCode: "US"));
  35. }
  36. [Fact]
  37. public void Type_HasNoPublicMutationMethods()
  38. {
  39. // Append-only enforcement: nothing beyond the constructor may change an existing
  40. // observation's state. If this test ever needs updating, the append-only invariant
  41. // has likely been broken.
  42. var publicMethods = typeof(PriceObservation)
  43. .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
  44. .Where(m => !m.IsSpecialName) // exclude property getters
  45. .ToList();
  46. Assert.Empty(publicMethods);
  47. }
  48. }

Powered by TurnKey Linux.