예제 #1
0
        public void AddCargo(Cargo cargo)
        {
            if(cargo == null) throw new ArgumentNullException("cargo");

            // Opdracht 4c
            // Roep de methode GuardThatThereIsEnoughRoomLeft aan die controleert of een voyage nog genoeg capaciteit heeft voor de cargo
            // Zo niet, dan wordt er een NotEnoughtCapacityLeftForCargoException gegooid

            // Opdracht 3i
            // Maak een nieuw CargoAddedToVoyageEvent aan en vul hiervan de properties.
            // Gebruik vervolgens de ApplyEvent(..) methode om het event uit te voeren.
        }
예제 #2
0
        public void AddCargo(Cargo cargo)
        {
            if(cargo == null) throw new ArgumentNullException("cargo");

            GuardThatThereIsEnoughRoomLeft(cargo);

            ApplyEvent(new CargoAddedToVoyageEvent
            {
                CargoId = cargo.EventSourceId,
                VoyageId = EventSourceId,
                ArrivalDate = _arrivalDate,
                DepartureDate = _departureDate,
                CapacityUsed = _capacityUsed + cargo.Size,
                CapacityLeft = _capacityLeft - cargo.Size
            });
        }
예제 #3
0
        /// <summary>
        /// Throws an <see cref="NotEnoughCapacityLeftForCargoException"/> when there is not enough
        /// room left for the specified cargo.
        /// </summary>
        /// <param name="cargo">The cargo to add to this <see cref="Voyage"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when cargo is null.</exception>
        /// <exception cref="NotEnoughCapacityLeftForCargoException">Thrown when there is not enough
        /// room for the cargo to be added to this voyage.</exception>
        private void GuardThatThereIsEnoughRoomLeft(Cargo cargo)
        {
            if(cargo == null) throw new ArgumentNullException("cargo");

            var capacityLeftIncludingOverbook = _overbookingCapcity - _capacityUsed;

            if (cargo.Size > capacityLeftIncludingOverbook)
            {
                throw new NotEnoughCapacityLeftForCargoException(EventSourceId, capacityLeftIncludingOverbook,
                                                                  cargo.EventSourceId, cargo.Size);
            }
        }
예제 #4
0
        /// <summary>
        /// Throws an <see cref="NotEnoughtCapacityLeftForCargoException"/> when there is not enough
        /// room left for the specified cargo.
        /// </summary>
        /// <param name="cargo">The cargo to add to this <see cref="Voyage"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when cargo is null.</exception>
        /// <exception cref="NotEnoughtCapacityLeftForCargoException">Thrown when there is not enough
        /// room for the cargo to be added to this voyage.</exception>
        private void GuardThatThereIsEnoughRoomLeft(Cargo cargo)
        {
            if(cargo == null) throw new ArgumentNullException("cargo");

            // Controleer of er genoeg ruimte is door gebruik te maken van de variabelen _overbookingCapcity, _capacityUsed en cargo.Size
        }