diff --git a/Address.cs b/Address.cs new file mode 100644 index 0000000..4e6e89e --- /dev/null +++ b/Address.cs @@ -0,0 +1,4 @@ +namespace AggregateConsistencyBoundary +{ + public record Address(string Street, string City, string Postal, string Country); +} \ No newline at end of file diff --git a/Address.cs b/Address.cs new file mode 100644 index 0000000..4e6e89e --- /dev/null +++ b/Address.cs @@ -0,0 +1,4 @@ +namespace AggregateConsistencyBoundary +{ + public record Address(string Street, string City, string Postal, string Country); +} \ No newline at end of file diff --git a/SalesOrderAggregateRoot.cs b/SalesOrderAggregateRoot.cs index c01b961..decee85 100644 --- a/SalesOrderAggregateRoot.cs +++ b/SalesOrderAggregateRoot.cs @@ -1,3 +1,5 @@ +using System; + namespace AggregateConsistencyBoundary { public class OrderAggregateRoot @@ -21,9 +23,11 @@ } - public ShipmentAggregateRoot Ship() + public ShipmentAggregateRoot Ship(DateTime expectedPickup, DateTime expectedDelivery) { - return ShipmentAggregateRoot.Factory(new PickupStop(1, _restaurant), new DeliveryStop(2, _customer)); + var pickup = new PickupStop(1, _restaurant, expectedPickup); + var delivery = new DeliveryStop(2, _customer, expectedDelivery); + return ShipmentAggregateRoot.Factory(pickup, delivery); } } } \ No newline at end of file diff --git a/Address.cs b/Address.cs new file mode 100644 index 0000000..4e6e89e --- /dev/null +++ b/Address.cs @@ -0,0 +1,4 @@ +namespace AggregateConsistencyBoundary +{ + public record Address(string Street, string City, string Postal, string Country); +} \ No newline at end of file diff --git a/SalesOrderAggregateRoot.cs b/SalesOrderAggregateRoot.cs index c01b961..decee85 100644 --- a/SalesOrderAggregateRoot.cs +++ b/SalesOrderAggregateRoot.cs @@ -1,3 +1,5 @@ +using System; + namespace AggregateConsistencyBoundary { public class OrderAggregateRoot @@ -21,9 +23,11 @@ } - public ShipmentAggregateRoot Ship() + public ShipmentAggregateRoot Ship(DateTime expectedPickup, DateTime expectedDelivery) { - return ShipmentAggregateRoot.Factory(new PickupStop(1, _restaurant), new DeliveryStop(2, _customer)); + var pickup = new PickupStop(1, _restaurant, expectedPickup); + var delivery = new DeliveryStop(2, _customer, expectedDelivery); + return ShipmentAggregateRoot.Factory(pickup, delivery); } } } \ No newline at end of file diff --git a/ShipmentAggregateRoot.cs b/ShipmentAggregateRoot.cs index 595b96c..8f0895d 100644 --- a/ShipmentAggregateRoot.cs +++ b/ShipmentAggregateRoot.cs @@ -95,6 +95,4 @@ return Stops.All(x => x.Value.Status == StopStatus.Departed); } } - - public record Address(string Street, string City, string Postal, string Country); } diff --git a/Address.cs b/Address.cs new file mode 100644 index 0000000..4e6e89e --- /dev/null +++ b/Address.cs @@ -0,0 +1,4 @@ +namespace AggregateConsistencyBoundary +{ + public record Address(string Street, string City, string Postal, string Country); +} \ No newline at end of file diff --git a/SalesOrderAggregateRoot.cs b/SalesOrderAggregateRoot.cs index c01b961..decee85 100644 --- a/SalesOrderAggregateRoot.cs +++ b/SalesOrderAggregateRoot.cs @@ -1,3 +1,5 @@ +using System; + namespace AggregateConsistencyBoundary { public class OrderAggregateRoot @@ -21,9 +23,11 @@ } - public ShipmentAggregateRoot Ship() + public ShipmentAggregateRoot Ship(DateTime expectedPickup, DateTime expectedDelivery) { - return ShipmentAggregateRoot.Factory(new PickupStop(1, _restaurant), new DeliveryStop(2, _customer)); + var pickup = new PickupStop(1, _restaurant, expectedPickup); + var delivery = new DeliveryStop(2, _customer, expectedDelivery); + return ShipmentAggregateRoot.Factory(pickup, delivery); } } } \ No newline at end of file diff --git a/ShipmentAggregateRoot.cs b/ShipmentAggregateRoot.cs index 595b96c..8f0895d 100644 --- a/ShipmentAggregateRoot.cs +++ b/ShipmentAggregateRoot.cs @@ -95,6 +95,4 @@ return Stops.All(x => x.Value.Status == StopStatus.Departed); } } - - public record Address(string Street, string City, string Postal, string Country); } diff --git a/Stop.cs b/Stop.cs index 2451e0a..876a73f 100644 --- a/Stop.cs +++ b/Stop.cs @@ -4,7 +4,8 @@ { public class PickupStop : Stop { - public PickupStop(int stopId, Address address) + public PickupStop(int stopId, Address address, DateTime scheduled) + : base(stopId, address, scheduled) { StopId = stopId; Address = address; @@ -13,7 +14,8 @@ public class DeliveryStop : Stop { - public DeliveryStop(int stopId, Address address) + public DeliveryStop(int stopId, Address address, DateTime scheduled) + : base(stopId, address, scheduled) { StopId = stopId; Address = address; @@ -25,9 +27,16 @@ public int StopId { get; protected set; } public StopStatus Status { get; private set; } = StopStatus.InTransit; public Address Address { get; protected set;} - public DateTime Scheduled { get; protected set;} + public DateTime Scheduled { get; } public DateTime? Departed { get; protected set; } + public Stop(int stopId, Address address, DateTime scheduled) + { + StopId = stopId; + Address = address; + Scheduled = scheduled; + } + public void Arrive() { if (Status != StopStatus.InTransit) diff --git a/Address.cs b/Address.cs new file mode 100644 index 0000000..4e6e89e --- /dev/null +++ b/Address.cs @@ -0,0 +1,4 @@ +namespace AggregateConsistencyBoundary +{ + public record Address(string Street, string City, string Postal, string Country); +} \ No newline at end of file diff --git a/SalesOrderAggregateRoot.cs b/SalesOrderAggregateRoot.cs index c01b961..decee85 100644 --- a/SalesOrderAggregateRoot.cs +++ b/SalesOrderAggregateRoot.cs @@ -1,3 +1,5 @@ +using System; + namespace AggregateConsistencyBoundary { public class OrderAggregateRoot @@ -21,9 +23,11 @@ } - public ShipmentAggregateRoot Ship() + public ShipmentAggregateRoot Ship(DateTime expectedPickup, DateTime expectedDelivery) { - return ShipmentAggregateRoot.Factory(new PickupStop(1, _restaurant), new DeliveryStop(2, _customer)); + var pickup = new PickupStop(1, _restaurant, expectedPickup); + var delivery = new DeliveryStop(2, _customer, expectedDelivery); + return ShipmentAggregateRoot.Factory(pickup, delivery); } } } \ No newline at end of file diff --git a/ShipmentAggregateRoot.cs b/ShipmentAggregateRoot.cs index 595b96c..8f0895d 100644 --- a/ShipmentAggregateRoot.cs +++ b/ShipmentAggregateRoot.cs @@ -95,6 +95,4 @@ return Stops.All(x => x.Value.Status == StopStatus.Departed); } } - - public record Address(string Street, string City, string Postal, string Country); } diff --git a/Stop.cs b/Stop.cs index 2451e0a..876a73f 100644 --- a/Stop.cs +++ b/Stop.cs @@ -4,7 +4,8 @@ { public class PickupStop : Stop { - public PickupStop(int stopId, Address address) + public PickupStop(int stopId, Address address, DateTime scheduled) + : base(stopId, address, scheduled) { StopId = stopId; Address = address; @@ -13,7 +14,8 @@ public class DeliveryStop : Stop { - public DeliveryStop(int stopId, Address address) + public DeliveryStop(int stopId, Address address, DateTime scheduled) + : base(stopId, address, scheduled) { StopId = stopId; Address = address; @@ -25,9 +27,16 @@ public int StopId { get; protected set; } public StopStatus Status { get; private set; } = StopStatus.InTransit; public Address Address { get; protected set;} - public DateTime Scheduled { get; protected set;} + public DateTime Scheduled { get; } public DateTime? Departed { get; protected set; } + public Stop(int stopId, Address address, DateTime scheduled) + { + StopId = stopId; + Address = address; + Scheduled = scheduled; + } + public void Arrive() { if (Status != StopStatus.InTransit) diff --git a/Tests.cs b/Tests.cs index 3aa766b..d301fa2 100644 --- a/Tests.cs +++ b/Tests.cs @@ -10,8 +10,8 @@ public Tests() { - var pickup = new PickupStop(1, new Address("123 Street", "Lakeshore", "N0R1A0", "CA")); - var delivery = new DeliveryStop(2, new Address("456 Ave", "Windsor", "N8N0A1", "CA")); + var pickup = new PickupStop(1, new Address("123 Street", "Lakeshore", "N0R1A0", "CA"), DateTime.UtcNow); + var delivery = new DeliveryStop(2, new Address("456 Ave", "Windsor", "N8N0A1", "CA"), DateTime.UtcNow); _shipmentAggregateRoot = ShipmentAggregateRoot.Factory(pickup, delivery); }