You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.5 KiB

  1. using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
  2. using System;
  3. using Xunit;
  4. public class OrderAggregateTest
  5. {
  6. public OrderAggregateTest()
  7. { }
  8. [Fact]
  9. public void Create_order_item_success()
  10. {
  11. //Arrange
  12. var productId = 1;
  13. var productName = "FakeProductName";
  14. var unitPrice = 12;
  15. var discount = 15;
  16. var pictureUrl = "FakeUrl";
  17. var units = 5;
  18. //Act
  19. var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
  20. //Assert
  21. Assert.NotNull(fakeOrderItem);
  22. }
  23. [Fact]
  24. public void Invalid_number_of_units()
  25. {
  26. //Arrange
  27. var productId = 1;
  28. var productName = "FakeProductName";
  29. var unitPrice = 12;
  30. var discount = 15;
  31. var pictureUrl = "FakeUrl";
  32. var units = -1;
  33. //Act - Assert
  34. Assert.Throws<ArgumentNullException>(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units));
  35. }
  36. [Fact]
  37. public void Invalid_total_of_order_item_lower_than_discount_applied()
  38. {
  39. //Arrange
  40. var productId = 1;
  41. var productName = "FakeProductName";
  42. var unitPrice = 12;
  43. var discount = 15;
  44. var pictureUrl = "FakeUrl";
  45. var units = 1;
  46. //Act - Assert
  47. Assert.Throws<ArgumentException>(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units));
  48. }
  49. [Fact]
  50. public void Invalid_discount_setting()
  51. {
  52. //Arrange
  53. var productId = 1;
  54. var productName = "FakeProductName";
  55. var unitPrice = 12;
  56. var discount = 15;
  57. var pictureUrl = "FakeUrl";
  58. var units = 5;
  59. //Act
  60. var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
  61. //Assert
  62. Assert.Throws<ArgumentException>(() => fakeOrderItem.SetNewDiscount(-1));
  63. }
  64. [Fact]
  65. public void Invalid_units_setting()
  66. {
  67. //Arrange
  68. var productId = 1;
  69. var productName = "FakeProductName";
  70. var unitPrice = 12;
  71. var discount = 15;
  72. var pictureUrl = "FakeUrl";
  73. var units = 5;
  74. //Act
  75. var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
  76. //Assert
  77. Assert.Throws<ArgumentException>(() => fakeOrderItem.AddUnits(-1));
  78. }
  79. }