|
|
- using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
- using System;
- using Xunit;
-
- public class OrderAggregateTest
- {
- public OrderAggregateTest()
- { }
-
- [Fact]
- public void Create_order_item_success()
- {
- //Arrange
- var productId = 1;
- var productName = "FakeProductName";
- var unitPrice = 12;
- var discount = 15;
- var pictureUrl = "FakeUrl";
- var units = 5;
-
- //Act
- var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
-
- //Assert
- Assert.NotNull(fakeOrderItem);
- }
-
- [Fact]
- public void Invalid_number_of_units()
- {
- //Arrange
- var productId = 1;
- var productName = "FakeProductName";
- var unitPrice = 12;
- var discount = 15;
- var pictureUrl = "FakeUrl";
- var units = -1;
-
- //Act - Assert
- Assert.Throws<ArgumentNullException>(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units));
- }
-
- [Fact]
- public void Invalid_total_of_order_item_lower_than_discount_applied()
- {
- //Arrange
- var productId = 1;
- var productName = "FakeProductName";
- var unitPrice = 12;
- var discount = 15;
- var pictureUrl = "FakeUrl";
- var units = 1;
-
- //Act - Assert
- Assert.Throws<ArgumentException>(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units));
- }
-
- [Fact]
- public void Invalid_discount_setting()
- {
- //Arrange
- var productId = 1;
- var productName = "FakeProductName";
- var unitPrice = 12;
- var discount = 15;
- var pictureUrl = "FakeUrl";
- var units = 5;
-
- //Act
- var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
-
- //Assert
- Assert.Throws<ArgumentException>(() => fakeOrderItem.SetNewDiscount(-1));
- }
-
- [Fact]
- public void Invalid_units_setting()
- {
- //Arrange
- var productId = 1;
- var productName = "FakeProductName";
- var unitPrice = 12;
- var discount = 15;
- var pictureUrl = "FakeUrl";
- var units = 5;
-
- //Act
- var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
-
- //Assert
- Assert.Throws<ArgumentException>(() => fakeOrderItem.AddUnits(-1));
- }
- }
|