Exemplo n.º 1
0
        public void AssignToRoute_01()
        {
            // arrange:
            TrackingId id        = new TrackingId("CRG01");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).Return(false);
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.Now + TimeSpan.FromDays(60)).Repeat.AtLeastOnce();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once();
            NewCargo state = new NewCargo(id, specification);

            // act:
            CargoState newState = state.AssignToRoute(itinerary);

            // assert:
            Assert.IsNotNull(newState);
            Assert.IsTrue(state.CalculationDate <= newState.CalculationDate);
            Assert.AreEqual(RoutingStatus.Routed, newState.RoutingStatus);
            Assert.AreSame(itinerary, newState.Itinerary);
            Assert.AreNotSame(state, newState);
            Assert.IsFalse(state.Equals(newState));
            Assert.IsFalse(newState.Equals(state));
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
        }
Exemplo n.º 2
0
        public void Ctor_01()
        {
            // arrange:
            UnLocode   final     = new UnLocode("FINAL");
            TrackingId id        = new TrackingId("CLAIM");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(final).Repeat.AtLeastOnce();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            previousState.Expect(s => s.IsUnloadedAtDestination).Return(true).Repeat.AtLeastOnce();
            previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.AtLeastOnce();
            DateTime claimDate = DateTime.UtcNow;


            // act:
            ClaimedCargo state = new ClaimedCargo(previousState, claimDate);

            // assert:
            Assert.AreEqual(TransportStatus.Claimed, state.TransportStatus);
            Assert.AreEqual(RoutingStatus.Routed, state.RoutingStatus);
            Assert.AreSame(final, state.LastKnownLocation);
            Assert.AreSame(specification, state.RouteSpecification);
            Assert.IsNull(state.CurrentVoyage);
            Assert.IsTrue(state.IsUnloadedAtDestination);
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
            previousState.VerifyAllExpectations();
        }
Exemplo n.º 3
0
        public void Recieve_01()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CRG01");
            UnLocode            code          = new UnLocode("START");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            ILocation           location      = MockRepository.GenerateMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce();
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.InitialDepartureLocation).Return(code).Repeat.AtLeastOnce();
            itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once();
            CargoState state = new NewCargo(id, specification);

            state = state.AssignToRoute(itinerary);

            // act:
            CargoState newState = state.Recieve(location, DateTime.UtcNow);

            // assert:
            Assert.IsNotNull(newState);
            Assert.IsInstanceOf <InPortCargo>(newState);
            Assert.AreSame(code, newState.LastKnownLocation);
            Assert.IsTrue(newState.EstimatedTimeOfArrival.HasValue);
            Assert.IsTrue(TransportStatus.InPort == newState.TransportStatus);
            location.VerifyAllExpectations();
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
        }
Exemplo n.º 4
0
        public void Recieve_04()
        {
            // arrange:
            TrackingId id        = new TrackingId("CRG01");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
            IRouteSpecification specification2 = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification2.Expect(s => s.IsSatisfiedBy(itinerary)).Return(false).Repeat.AtLeastOnce();
            specification.Expect(s => s.Equals(specification2)).Return(false).Repeat.Any();
            specification2.Expect(s => s.Equals(specification)).Return(false).Repeat.Any();
            ILocation  location       = MockRepository.GenerateMock <ILocation>();
            CargoState initialState   = new NewCargo(id, specification);
            CargoState routedState    = initialState.AssignToRoute(itinerary);
            CargoState misroutedState = routedState.SpecifyNewRoute(specification2);

            // assert:
            Assert.AreEqual(initialState.GetType(), routedState.GetType());
            Assert.AreNotSame(initialState, routedState);
            Assert.AreEqual(routedState.GetType(), misroutedState.GetType());
            Assert.AreNotSame(routedState, misroutedState);
            Assert.IsTrue(RoutingStatus.Misrouted == misroutedState.RoutingStatus);
            Assert.Throws <InvalidOperationException>(delegate { misroutedState.Recieve(location, DateTime.UtcNow); });
            location.VerifyAllExpectations();
            specification.VerifyAllExpectations();
            specification2.VerifyAllExpectations();
            itinerary.VerifyAllExpectations();
        }
Exemplo n.º 5
0
        public void AssignToRoute_03()
        {
            // arrange:
            TrackingId id            = new TrackingId("CRG01");
            IItinerary itinerary     = MockRepository.GenerateStrictMock <IItinerary>();
            DateTime   finalArrival1 = DateTime.Now + TimeSpan.FromDays(30);

            itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.AtLeastOnce();
            itinerary.Expect(i => i.FinalArrivalDate).Return(finalArrival1).Repeat.AtLeastOnce();
            IItinerary itinerary2 = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary2.Expect(i => i.Equals(itinerary)).Return(true).Repeat.AtLeastOnce();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once();
            CargoState initialState = new NewCargo(id, specification);
            CargoState state        = initialState.AssignToRoute(itinerary);

            // act:
            CargoState newState = state.AssignToRoute(itinerary2);

            // assert:
            Assert.AreEqual(finalArrival1, newState.EstimatedTimeOfArrival);
            Assert.AreEqual(initialState.GetType(), state.GetType());
            Assert.AreNotSame(initialState, state);
            Assert.IsNotNull(newState);
            Assert.AreSame(state, newState);
        }
Exemplo n.º 6
0
        public void Ctor_02()
        {
            // arrange:
            GList      mocks     = new GList();
            TrackingId id        = new TrackingId("START");
            DateTime   loadTime  = DateTime.Now;
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("ENDLC")).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            mocks.Add(previousState);

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { new OnboardCarrierCargo(previousState, null, loadTime); });
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
Exemplo n.º 7
0
        public void Ctor_05()
        {
            // arrange:
            TrackingId id        = new TrackingId("CLAIM");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            previousState.Expect(s => s.IsUnloadedAtDestination).Return(false).Repeat.AtLeastOnce();
            previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.AtLeastOnce();
            DateTime claimDate = DateTime.UtcNow;


            // act:
            Assert.Throws <ArgumentException>(delegate { new ClaimedCargo(previousState, claimDate); });

            // assert:
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
            previousState.VerifyAllExpectations();
        }
Exemplo n.º 8
0
		public OnboardCarrierCargo (CargoState previousState, IVoyage voyage, DateTime loadDate)
			: base(previousState)
		{
			if(null == voyage)
				throw new ArgumentNullException("voyage");
			_voyage = voyage.Number;
			_date = loadDate;
			_lastKnownLocation = voyage.LastKnownLocation;
		}
Exemplo n.º 9
0
        public void Ctor_withNullRoute_throwsArgumentNullException()
        {
            // arrange:
            TrackingId          identifier = new TrackingId("CARGO01");
            IRouteSpecification route      = MockRepository.GenerateStrictMock <IRouteSpecification>();
            CargoState          mock       = MockRepository.GeneratePartialMock <CargoState>(identifier, route);

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { new FakeState(mock, null as IRouteSpecification); });
        }
Exemplo n.º 10
0
        public async Task <IHttpActionResult> GetCargoState(int Id)//[FromBody] web api classic
        {
            CargoState CargoState = await _db.CargoStates.FindAsync(Id);

            if (CargoState == null)
            {
                return(NotFound());
            }

            return(Ok(CargoState));
        }
Exemplo n.º 11
0
        public void Ctor_03()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CLAIM");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            CargoState          previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);
            DateTime            claimDate     = DateTime.UtcNow;


            // act:
            Assert.Throws <ArgumentException>(delegate { new ClaimedCargo(previousState, claimDate); });

            // assert:
            specification.VerifyAllExpectations();
        }
Exemplo n.º 12
0
        public async Task <IHttpActionResult> Get(int Id)
        {
            //Find() and FindAsync() are methods on type DbSet (which is what db.Items is). Include() returns a DbQuery object,
            //which is why FindAsync() is not available. Use SingleOrDefaultAsync() to do the same thing as FindAsync()
            //(the difference is it will go straight to the database and won't look in the context to see if the entity exists first)...
            //CargoState CargoState = await _db.CargoStates.FindAsync(Id);
            CargoState CargoState = await _db.CargoStates.SingleOrDefaultAsync(i => i.Id == Id);

            if (CargoState == null)
            {
                return(NotFound());
            }

            return(Ok(CargoState));
        }
Exemplo n.º 13
0
        public async Task <IHttpActionResult> Put(int Id, [FromBody] CargoState CargoState)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (Id != CargoState.Id)
            {
                return(BadRequest());
            }
            _db.Entry(CargoState).State = EntityState.Modified;

            try
            {
                _db.CargoStates.AddOrUpdate(CargoState);
                await _db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                List <string> errors = new List <string>();
                foreach (var eve in e.EntityValidationErrors)
                {
                    errors.Add(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                             eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        errors.Add(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                 ve.PropertyName, ve.ErrorMessage));
                    }
                }
                throw;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CargoStateExists(Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Updated(CargoState));
            //return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 14
0
        public void Unload_04()
        {
            // arrange:
            GList mocks = new GList();

            UnLocode     code         = new UnLocode("START");
            VoyageNumber voyageNumber = new VoyageNumber("ATEST");
            DateTime     arrival      = DateTime.UtcNow;
            TrackingId   id           = new TrackingId("CARGO01");
            IItinerary   itinerary    = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(code).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            mocks.Add(specification);
            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.Any();
            voyage.Expect(v => v.LastKnownLocation).Return(code).Repeat.AtLeastOnce();
            voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce();
            mocks.Add(voyage);
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            mocks.Add(previousState);
            previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
            OnboardCarrierCargo state = new OnboardCarrierCargo(previousState, voyage, arrival);

            // act:
            CargoState newState = state.Unload(voyage, arrival + TimeSpan.FromDays(2));

            // assert:
            Assert.IsNotNull(newState);
            Assert.IsInstanceOf <InPortCargo>(newState);
            Assert.AreSame(code, newState.LastKnownLocation);
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
Exemplo n.º 15
0
        public void StateTransitions_01()
        {
            // arrange:
            UnLocode   final         = new UnLocode("FINAL");
            TrackingId id            = new TrackingId("CLAIM");
            ILocation  finalLocation = MockRepository.GenerateStrictMock <ILocation>();

            finalLocation.Expect(l => l.UnLocode).Return(final).Repeat.AtLeastOnce();
            ILocation otherLocation = MockRepository.GenerateStrictMock <ILocation>();

            otherLocation.Expect(l => l.UnLocode).Return(new UnLocode("OTHER")).Repeat.AtLeastOnce();
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(final).Repeat.Any();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            previousState.Expect(s => s.IsUnloadedAtDestination).Return(true).Repeat.Any();
            previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.Any();
            IVoyage  voyage    = MockRepository.GenerateStrictMock <IVoyage>();
            DateTime claimDate = DateTime.UtcNow;

            ClaimedCargo state = new ClaimedCargo(previousState, claimDate);

            // act:
            CargoState newState = state.Claim(finalLocation, claimDate);

            // assert:
            Assert.AreSame(state, newState);
            Assert.Throws <ArgumentNullException>(delegate { state.Claim(null, DateTime.UtcNow); });
            Assert.Throws <InvalidOperationException>(delegate { state.Claim(finalLocation, DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.Claim(otherLocation, claimDate); });
            Assert.Throws <InvalidOperationException>(delegate { state.LoadOn(voyage, DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.Unload(voyage, DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.SpecifyNewRoute(MockRepository.GenerateStrictMock <IRouteSpecification>()); });
            Assert.Throws <InvalidOperationException>(delegate { state.AssignToRoute(MockRepository.GenerateStrictMock <IItinerary>()); });
            Assert.Throws <InvalidOperationException>(delegate { state.Recieve(MockRepository.GenerateStrictMock <ILocation>(), DateTime.UtcNow + TimeSpan.FromSeconds(10) + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.ClearCustoms(MockRepository.GenerateStrictMock <ILocation>(), DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
        }
Exemplo n.º 16
0
 public async Task <IHttpActionResult> Post([FromBody] CargoState CargoState)//[FromBody] in classic web api
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (CargoState == null)
     {
         return(BadRequest("Object value null"));
     }
     _db.CargoStates.AddOrUpdate(CargoState);
     try
     {
         await _db.SaveChangesAsync();
     }
     catch (DbEntityValidationException e)
     {
         List <string> errors = new List <string>();
         foreach (var eve in e.EntityValidationErrors)
         {
             errors.Add(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State));
             foreach (var ve in eve.ValidationErrors)
             {
                 errors.Add(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage));
             }
         }
         throw;
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!CargoStateExists(CargoState.Id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(Created(CargoState));
     //return CreatedAtRoute("DefaultApi", new { id = CargoState.Id }, CargoState);
 }
Exemplo n.º 17
0
        public void LoadOn_02()
        {
            // arrange:
            GList mocks = new GList();

            UnLocode     code         = new UnLocode("START");
            VoyageNumber voyageNumber = new VoyageNumber("ATEST");
            DateTime     arrival      = DateTime.UtcNow;
            TrackingId   id           = new TrackingId("CARGO01");
            IItinerary   itinerary    = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(code).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            mocks.Add(specification);
            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.Any();
            voyage.Expect(v => v.LastKnownLocation).Return(code).Repeat.AtLeastOnce();
            mocks.Add(voyage);
            IVoyage voyage2 = MockRepository.GenerateStrictMock <IVoyage>();

            voyage2.Expect(v => v.Number).Return(new VoyageNumber("VYGOTHER")).Repeat.Any();
            mocks.Add(voyage2);
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            mocks.Add(previousState);
            previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();
            OnboardCarrierCargo state = new OnboardCarrierCargo(previousState, voyage, arrival);

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { state.LoadOn(voyage2, arrival + TimeSpan.FromDays(2)); });
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
Exemplo n.º 18
0
        public void SpecifyNewRoute_02()
        {
            // arrange:
            TrackingId          id             = new TrackingId("CRG01");
            IRouteSpecification specification  = MockRepository.GenerateStrictMock <IRouteSpecification>();
            IRouteSpecification specification2 = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.Equals(specification2)).Return(true).Repeat.Any();
            specification2.Expect(s => s.Equals(specification)).Return(true).Repeat.Any();
            NewCargo state = new NewCargo(id, specification);

            // act:
            CargoState newState = state.SpecifyNewRoute(specification2);

            // assert:
            Assert.IsNotNull(newState);
            Assert.AreSame(state, newState);
            specification.VerifyAllExpectations();
            specification2.VerifyAllExpectations();
        }
Exemplo n.º 19
0
        public void Ctor_01()
        {
            // arrange:
            GList        mocks        = new GList();
            TrackingId   id           = new TrackingId("START");
            DateTime     loadTime     = DateTime.Now;
            VoyageNumber voyageNumber = new VoyageNumber("VYG001");
            UnLocode     location     = new UnLocode("CURLC");
            IItinerary   itinerary    = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("ENDLC")).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            mocks.Add(previousState);
            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce();
            voyage.Expect(v => v.LastKnownLocation).Return(location).Repeat.AtLeastOnce();
            mocks.Add(voyage);

            // act:
            CargoState state = new OnboardCarrierCargo(previousState, voyage, loadTime);

            // assert:
            Assert.IsNotNull(state);
            Assert.AreSame(voyageNumber, state.CurrentVoyage);
            Assert.AreEqual(TransportStatus.OnboardCarrier, state.TransportStatus);
            Assert.AreSame(location, state.LastKnownLocation);
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
Exemplo n.º 20
0
        public void ClearCustoms_01()
        {
            // arrange:
            GList        mocks        = new GList();
            TrackingId   id           = new TrackingId("START");
            DateTime     loadTime     = DateTime.Now;
            VoyageNumber voyageNumber = new VoyageNumber("VYG001");
            UnLocode     locCode      = new UnLocode("CURLC");
            ILocation    location     = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(locCode).Repeat.Any();
            mocks.Add(location);
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("ENDLC")).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            mocks.Add(specification);
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            mocks.Add(previousState);
            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce();
            voyage.Expect(v => v.LastKnownLocation).Return(locCode).Repeat.AtLeastOnce();
            mocks.Add(voyage);
            CargoState state = new OnboardCarrierCargo(previousState, voyage, loadTime);

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { state.ClearCustoms(location, DateTime.Now + TimeSpan.FromDays(1)); });
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
Exemplo n.º 21
0
    protected void SetCargoState(CargoState _cargoState)
    {
        cargoState = _cargoState;
        switch (_cargoState)
        {
        case CargoState.Invalid:
            objectState = ObjectState.Idle;
            break;

        case CargoState.Idle:
            objectState = ObjectState.Idle;
            break;

        case CargoState.Prepare:
            //the hero needs to stay inside the cargo's range for 3 seconds for it to move.
            currentActiveTime = cargoActiveTime;
            activeCircle.SetTargetGameObject(this.gameObject);
            SetActivationCircleSize(startCircleSize);
            objectState = ObjectState.Idle;
            break;

        case CargoState.Run:
            objectState = ObjectState.Run;
            break;

        case CargoState.Finnished:
            objectState = ObjectState.Idle;
            Directors.instance.EndBattle();
            break;

        case CargoState.Die:
            objectState = ObjectState.Die;
            break;

        default:
            Debug.Log("<color=red> DEFAULT STATE IS NOT SET !!! PLEASE CHECK !!!!</color>");
            break;
        }
    }
Exemplo n.º 22
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            CargoState CargoState = await _db.CargoStates.FindAsync(id);

            if (CargoState == null)
            {
                return(NotFound());
            }

            _db.CargoStates.Remove(CargoState);
            try
            {
                await _db.SaveChangesAsync();
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
                throw;
            }


            return(Ok(CargoState));
        }
Exemplo n.º 23
0
        public void Ctor_02()
        {
            // arrange:
            System.Collections.Generic.List <object> mocks = new System.Collections.Generic.List <object>();
            TrackingId id        = new TrackingId("CLAIM");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            mocks.Add(specification);
            IRouteSpecification specification2 = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification2.Expect(s => s.IsSatisfiedBy(itinerary)).Return(false).Repeat.Any();
            mocks.Add(specification2);
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, specification2);
            mocks.Add(previousState);
            DateTime claimDate = DateTime.UtcNow;


            // act:
            Assert.Throws <ArgumentException>(delegate { new ClaimedCargo(previousState, claimDate); });

            // assert:
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
Exemplo n.º 24
0
		public FakeState2(CargoState previousState, IRouteSpecification route)
			: base(previousState, route)
		{
		}
Exemplo n.º 25
0
		public FakeState2(CargoState previousState, IItinerary itinerary)
			: base(previousState, itinerary)
		{
		}
Exemplo n.º 26
0
		protected NewCargo(CargoState previousState, IRouteSpecification newRoute)
			: base(previousState, newRoute)
		{
		}
Exemplo n.º 27
0
 public FakeState2(CargoState previousState, IRouteSpecification route)
     : base(previousState, route)
 {
 }
Exemplo n.º 28
0
 public FakeState2(CargoState previousState)
     : base(previousState)
 {
 }
Exemplo n.º 29
0
 public FakeState2(CargoState previousState, IItinerary itinerary)
     : base(previousState, itinerary)
 {
 }
Exemplo n.º 30
0
		public FakeCargo(CargoState initialState)
			: base(initialState)
		{
		}
Exemplo n.º 31
0
		protected NewCargo(CargoState previousState, IItinerary newItinerary)
			: base(previousState, newItinerary)
		{
		}
Exemplo n.º 32
0
		public FakeState2(CargoState previousState)
			: base(previousState)
		{
		}