Example #1
0
        public Route(
            LocationId originLocationId,
            LocationId destinationLocationId,
            DateTimeOffset departureTime,
            DateTimeOffset arrivalDeadline)
        {
            if (originLocationId == null) throw new ArgumentNullException(nameof(originLocationId));
            if (destinationLocationId == null) throw new ArgumentNullException(nameof(destinationLocationId));
            if (arrivalDeadline == default(DateTimeOffset)) throw new ArgumentOutOfRangeException(nameof(arrivalDeadline));
            if (departureTime == default(DateTimeOffset)) throw new ArgumentOutOfRangeException(nameof(departureTime));
            if (originLocationId == destinationLocationId) throw new ArgumentException("Origin and destination cannot be the same");
            if (departureTime.IsAfter(arrivalDeadline)) throw new ArgumentException("Departure must be before arrival");

            OriginLocationId = originLocationId;
            DestinationLocationId = destinationLocationId;
            DepartureTime = departureTime;
            ArrivalDeadline = arrivalDeadline;
        }