-
-
Save dcomartin/6e9fcac8f4918020ed82f70c620077ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using Shouldly; | |
using Xunit; | |
namespace Demo.EventSourced | |
{ | |
public class Tests | |
{ | |
private readonly ShipmentAggregateRoot _shipmentAggregateRootAggregateRoot; | |
public Tests() | |
{ | |
var stops = new List<ShipmentStop> | |
{ | |
new(1, StopType.Pickup, 1), | |
new(2, StopType.Delivery, 2) | |
}; | |
_shipmentAggregateRootAggregateRoot = new ShipmentAggregateRoot(); | |
_shipmentAggregateRootAggregateRoot.Dispatch(1, stops); | |
} | |
[Fact] | |
public void CompleteShipment() | |
{ | |
_shipmentAggregateRootAggregateRoot.Arrive(1); | |
_shipmentAggregateRootAggregateRoot.Pickup(1); | |
_shipmentAggregateRootAggregateRoot.Arrive(2); | |
_shipmentAggregateRootAggregateRoot.Deliver(2); | |
_shipmentAggregateRootAggregateRoot.IsComplete().ShouldBeTrue(); | |
} | |
[Fact] | |
public void CannotPickupWithoutArriving() | |
{ | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Pickup(1), "Stop hasn't arrived yet."); | |
} | |
[Fact] | |
public void CannotDeliverWithoutArriving() | |
{ | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Deliver(2), "Stop hasn't arrived yet."); | |
} | |
[Fact] | |
public void CannotPickupAtDelivery() | |
{ | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Pickup(2), "Stop is not a delivery."); | |
} | |
[Fact] | |
public void CannotDeliverAtPickup() | |
{ | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Deliver(1), "Stop is not a pickup."); | |
} | |
[Fact] | |
public void ArriveStopDoesNotExist() | |
{ | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Arrive(0), "Stop does not exist."); | |
} | |
[Fact] | |
public void PickupStopDoesNotExist() | |
{ | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Pickup(0), "Stop does not exist."); | |
} | |
[Fact] | |
public void DeliverStopDoesNotExist() | |
{ | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Deliver(0), "Stop does not exist."); | |
} | |
[Fact] | |
public void ArriveNonDepartedStops() | |
{ | |
_shipmentAggregateRootAggregateRoot.Arrive(1); | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Arrive(2), "Previous stops have not departed."); | |
} | |
[Fact] | |
public void AlreadyArrived() | |
{ | |
_shipmentAggregateRootAggregateRoot.Arrive(1); | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Arrive(1), "Stop has already arrived."); | |
} | |
[Fact] | |
public void AlreadyPickedUp() | |
{ | |
_shipmentAggregateRootAggregateRoot.Arrive(1); | |
_shipmentAggregateRootAggregateRoot.Pickup(1); | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Pickup(1), "Stop has already departed."); | |
} | |
[Fact] | |
public void AlreadyDelivered() | |
{ | |
_shipmentAggregateRootAggregateRoot.Arrive(1); | |
_shipmentAggregateRootAggregateRoot.Pickup(1); | |
_shipmentAggregateRootAggregateRoot.Arrive(2); | |
_shipmentAggregateRootAggregateRoot.Deliver(2); | |
Should.Throw<InvalidOperationException>(() => _shipmentAggregateRootAggregateRoot.Deliver(2), "Stop has already departed."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment