Esempio n. 1
0
        public void should_be_unloaded_at_final_destination()
        {
            var hangzou = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "HANGZOU");
            var tokyo = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "TOKYO");
            var newyork = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "NEW YORK");

            var cargo = SetUpCargoWithItinerary(hangzou, tokyo, newyork);

            Assert.False(cargo.Delivery.IsUnloadedAtDestination);

            // Adding an event unrelated to unloading at final destination
            var events = new List<HandlingEvent>();
            events.Add(new HandlingEvent(HandlingEventType.Receive, hangzou, DateTime.Now, new DateTime(10), cargo));
            cargo.DeriveDeliveryProgress(new HandlingHistory(events));
            Assert.False(cargo.Delivery.IsUnloadedAtDestination);

            var voyage = new VoyageBuilder(new VoyageNumber("0123"), hangzou)
                .AddMovement(newyork, DateTime.Now, DateTime.Now)
                .Build();

            // Adding an unload event, but not at the final destination
            events.Add(new HandlingEvent(HandlingEventType.Unload, tokyo, DateTime.Now, new DateTime(20), cargo, voyage));
            cargo.DeriveDeliveryProgress(new HandlingHistory(events));
            Assert.False(cargo.Delivery.IsUnloadedAtDestination);

            // Adding an event in the final destination, but not unload
            events.Add(new HandlingEvent(HandlingEventType.Customs, newyork, DateTime.Now, new DateTime(30), cargo));
            cargo.DeriveDeliveryProgress(new HandlingHistory(events));
            Assert.False(cargo.Delivery.IsUnloadedAtDestination);

            // Finally, cargo is unloaded at final destination
            events.Add(new HandlingEvent(HandlingEventType.Unload, newyork, DateTime.Now, new DateTime(40), cargo, voyage));
            cargo.DeriveDeliveryProgress(new HandlingHistory(events));
            Assert.True(cargo.Delivery.IsUnloadedAtDestination);
        }
        public void should_the_same_handling_activities()
        {
            var voyage = new VoyageBuilder(new VoyageNumber("VOY01"),
                                           new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "CHICAGO"))
                                           .AddMovement(new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "HAMBOURG"), DateTime.Now, DateTime.Now)
                                           .Build();
            var chicago = new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "CHICAGO");

            var firstHandlingActivity = new HandlingActivity(HandlingEventType.Load, chicago, voyage);
            var secondHandlingActivity = new HandlingActivity(HandlingEventType.Load, chicago, voyage);

            Assert.Equal(firstHandlingActivity, secondHandlingActivity);
        }
        public void build_is_idepotent()
        {
            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 voyageBuilder = new VoyageBuilder(voyageNumber, departureLocation).AddMovement(arrivalLocation, departureDataTime, arrivalDataTime);

            var voyage1 = voyageBuilder.Build();
            var voyage2 = voyageBuilder.Build();

            Assert.True(voyage1.Number == voyage2.Number);
            Assert.True(voyage1.Schedule == voyage2.Schedule);
        }
        public void should_throw_an_exception_when_location_is_null()
        {
            Assert.Throws<ArgumentNullException>(
                                                    delegate
                                                        {
                                                            new HandlingActivity(HandlingEventType.Load, null);
                                                        }
                                                );

            var voyage = new VoyageBuilder(new VoyageNumber("VOY01"),
                                           new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "CHICAGO"))
                                           .AddMovement(new BookingApi.Domain.Location.Location(UnLocodeHelpers.GetNewUnLocode(), "HAMBOURG"), DateTime.Now, DateTime.Now)
                                           .Build();

            Assert.Throws<ArgumentNullException>(
                                                    delegate
                                                    {
                                                        new HandlingActivity(HandlingEventType.Load, null, voyage);
                                                    }
                                                );
        }
        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);
                   }
               );
        }