Example #1
0
        public static Voyage Empty = new Voyage(new VoyageNumber(""), Schedule.Empty); // Null object pattern

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Creates new Voyage object.
        /// </summary>
        /// <param name="number">Identifier of this voyage.</param>
        /// <param name="schedule">Voyage schedule.</param>
        public Voyage(VoyageNumber number, Schedule schedule)
        {
            if (number == null)
                throw new ArgumentNullException("number");

            if (schedule == null)
                throw new ArgumentNullException("schedule");

            Number = number;
            Schedule = schedule;
        }
        public void build_returns_valid_voyage_instance_with_valid_inputs()
        {
            // AUTOFIXTURE
            //var fixture = new Fixture();

            //var departureLocation = fixture.CreateAnonymous<Location>();
            //var arrivalLocation = fixture.CreateAnonymous<Location>();
            //var departureTime = fixture.CreateAnonymous<DateTime>();
            //var arrivalTime = fixture.CreateAnonymous<DateTime>().AddDays(11);

            //fixture.Register(UnLocodeHelpers.GetNewUnLocode);
            //var voyageNumber = fixture.CreateAnonymous<VoyageNumber>();
            //fixture.Register(() => new VoyageBuilder(voyageNumber, departureLocation));
            //var voyageBuilder = fixture.CreateAnonymous<VoyageBuilder>();

            //fixture.Register(() => new CarrierMovement(departureLocation, arrivalLocation, departureTime, arrivalTime));
            //var carrierMovements = fixture.CreateMany<CarrierMovement>(1).ToList();
            //fixture.Register(() => new Schedule(carrierMovements));
            //var schedule = fixture.CreateAnonymous<Schedule>();

            //var voyage = voyageBuilder.AddMovement(arrivalLocation, departureTime, arrivalTime).Build();

            //Assert.True(voyage.Number.Equals(voyageNumber));
            //Assert.True(voyage.Schedule.Equals(schedule));

            var voyageNumber = new VoyageNumber("12");
            var departureLocation = new BookingApi.Domain.Location.Location(new UnLocode("AZ23H"), "HAMBOURG");
            var arrivalLocation = new BookingApi.Domain.Location.Location(new UnLocode("XE44K"), "TUNIS");
            var departureDataTime = new DateTime(2010, 4, 10);
            var arrivalDataTime = new DateTime(2010, 5, 15);
            var schedule =
                new Schedule(new List<CarrierMovement>
                                 {
                                     new CarrierMovement(departureLocation, arrivalLocation, departureDataTime,
                                                         arrivalDataTime)
                                 });

            BookingApi.Domain.Voyage.Voyage voyage = new VoyageBuilder(voyageNumber, departureLocation)
                .AddMovement(arrivalLocation, departureDataTime, arrivalDataTime).Build();

            Assert.True(voyage.Number.Equals(voyageNumber));
            Assert.True(voyage.Schedule.Equals(schedule));
        }
        public void build_throws_exception_if_called_without_valid_addMovement()
        {
            Assert.Throws<ArgumentException>(
                   delegate
                   {
                       var voyageNumber = new VoyageNumber("12");
                       var departureLocation = new BookingApi.Domain.Location.Location(new UnLocode("AZ23H"), "HAMBOURG");
                       var arrivalLocation = new BookingApi.Domain.Location.Location(new UnLocode("XE44K"), "TUNIS");
                       var departureDataTime = new DateTime(2010, 4, 10);
                       var arrivalDataTime = new DateTime(2010, 5, 15);
                       var schedule =
                           new Schedule(new List<CarrierMovement>
                                 {
                                     new CarrierMovement(departureLocation, arrivalLocation, departureDataTime,
                                                         arrivalDataTime)
                                 });

                       BookingApi.Domain.Voyage.Voyage voyage = new VoyageBuilder(voyageNumber, departureLocation).Build();

                       voyage.Number.Equals(voyageNumber);
                       voyage.Schedule.Equals(schedule);
                   }
               );
        }