Пример #1
0
        public async Task <PassengerAdditionResource> AddPassenger(string bookingId, Passenger passenger)
        {
            passenger = new PassengerBuilder().CreatePassenger();

            var command = new AddPassengerCommand(new BookingId(bookingId), passenger);
            await _commandBus.PublishAsync(command, CancellationToken.None);

            return(new PassengerAdditionResource(Url, bookingId, passenger.PassengerKey));
        }
Пример #2
0
        public void EvaluateOAPReturnsCorrectFare()
        {
            Passenger passenger   = new PassengerBuilder().OAP70YearOld().Build();
            DateTime  journeyTime = DateTime.Now;
            decimal   fare        = 5.00m;

            decimal evaluatedFare = new OAPFareRule().Evaluate(passenger, journeyTime, fare);

            Assert.AreEqual((fare * 0.45m), evaluatedFare);
        }
        public void CanBuildCompletePassenger()
        {
            var passenger = PassengerBuilder.Create(p =>
                                                    p.WithName("Matthijs", "van der Veer").BornOn(1989, 03, 25).OfType(PassengerType.Adult));

            Assert.Equal(new DateTime(1989, 03, 25), passenger.Birthdate);
            Assert.Equal("Matthijs", passenger.FirstName);
            Assert.Equal("van der Veer", passenger.LastName);
            Assert.Equal(PassengerType.Adult, passenger.PassengerType);
        }
Пример #4
0
        public void EvaluateReturnsCorrectFare()
        {
            Passenger passenger   = new PassengerBuilder().Student20YearOld().Build();
            DateTime  journeyTime = DateTime.Now;
            decimal   fare        = 5.00m;

            decimal evaluatedFare = new StudentFareRule().Evaluate(passenger, journeyTime, fare);

            Assert.AreEqual((fare / 2.0m), evaluatedFare);
        }
Пример #5
0
        public void EvaluateNonPeakReturnsCorrectFare()
        {
            Passenger passenger   = new PassengerBuilder().NonStudent30YearOld().Build();
            DateTime  journeyTime = DateTime.Now;
            DateTime  peakStart   = journeyTime.AddHours(-2);
            DateTime  peakEnd     = journeyTime.AddHours(-1);
            decimal   fare        = 5.00m;

            decimal evaluatedFare = new PeakFareRule(peakStart.TimeOfDay, peakEnd.TimeOfDay)
                                    .Evaluate(passenger, journeyTime, fare);

            Assert.AreEqual(fare, evaluatedFare);
        }
        public void WhenPassengerNameIsEmptyShouldFailed()
        {
            // Arrange
            var passenger = new PassengerBuilder().CreatePassenger()
                            .Mutate(p => p.Name = null);

            var specification = new PassengerIsValidSpecification(new List <Passenger>());

            //Act
            var result = specification.IsSatisfiedBy(passenger);
            var why    = specification.WhyIsNotSatisfiedBy(passenger);

            //Assert
            result.Should().BeFalse();
            why.Should().HaveCount(1);
        }
Пример #7
0
        public async Task AfterAddedPassengerTwiceShouldAddTwoPassengersToReadModel()
        {
            //Arrange
            var addPassengerScenario = new AddPassengerScenario(CommandBus);
            await addPassengerScenario.Execute();

            var bookingId = addPassengerScenario.BookingId;

            //Act
            var p = new PassengerBuilder().CreatePassenger(x => { x.Name = "AnotherYang"; });
            var addAnotherPassengerScenario = new AddPassengerScenario(CommandBus, bookingId, p);
            await addAnotherPassengerScenario.Execute();

            //Assert
            var booking = await _bookingReadModel.GetAsync(bookingId.Value, CancellationToken.None);

            booking.ReadModel.Passengers.Should().HaveCount(2);
        }
        public void CanBuildPassenger()
        {
            var passenger = PassengerBuilder.Create(p => p);

            Assert.NotNull(passenger);
        }