Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created September 9, 2021 21:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dcomartin/6e9fcac8f4918020ed82f70c620077ff to your computer and use it in GitHub Desktop.
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