public void StandardShipEtasFromStLouisBay()
        {
            Position testPosition = ShipPositions.StLouisBay;

            var ship = new ShipTest
            {
                Position            = testPosition,
                NavigationalStatus  = NavigationalStatus.Underway,
                CanalEntryTimestamp = DateTime.UtcNow.AddHours(-6),
                Speed = 1
            };

            var directDistanceToDuluth = GeoHelper.DistanceBetweenCoord(Ports.Duluth, testPosition);
            var shipSideDistance       = directDistanceToDuluth * Math.Sin(60d.ToRadians());
            var canalSideDistance      = directDistanceToDuluth * Math.Cos(60d.ToRadians());
            var totalDistance          = shipSideDistance + canalSideDistance;

            var expected = DateTime.UtcNow.AddHours(totalDistance / ship.Speed) + ShipTestProcessor.DataLag;

            ship.Update();

            // ReSharper disable once PossibleInvalidOperationException
            Assert.IsTrue(expected > ship.DerivedEta.Value.AddSeconds(-1));
            Assert.IsTrue(expected < ship.DerivedEta.Value.AddSeconds(1));
        }
        public void ShipsNotUnderway()
        {
            var ship = new ShipTest
            {
                Position           = ShipPositions.FiftyMilesFromDuluthCanal,
                NavigationalStatus = NavigationalStatus.Other
            };

            ship.Update();

            Assert.IsNull(ship.DerivedEta);
        }
        public void NoCanalEntryTimestampForShipsNotInHarbor()
        {
            var ship = new ShipTest
            {
                Position            = ShipPositions.TwentyMilesFromDuluthCanal,
                NavigationalStatus  = NavigationalStatus.Other,
                CanalEntryTimestamp = DateTime.UtcNow
            };

            ship.Update();

            Assert.IsNull(ship.CanalEntryTimestamp);
        }
        public void ShipsRecentlyEnteringTheHarbor()
        {
            var ship = new ShipTest
            {
                Position            = ShipPositions.StLouisBay,
                NavigationalStatus  = NavigationalStatus.Underway,
                CanalEntryTimestamp = DateTime.UtcNow
            };

            ship.Update();

            Assert.IsNull(ship.DerivedEta);
        }
        public void ShipsInStLouisBayForAPeriodOfTime()
        {
            var ship = new ShipTest
            {
                Position            = ShipPositions.StLouisBay,
                NavigationalStatus  = NavigationalStatus.Underway,
                CanalEntryTimestamp = DateTime.UtcNow.AddHours(-6),
                Speed = 1
            };

            ship.Update();

            Assert.IsNotNull(ship.DerivedEta);
        }
        public void ShipsNearDuluthAndNotHeadingToDuluth()
        {
            var ship = new ShipTest
            {
                Position           = ShipPositions.FiftyMilesFromDuluthCanal,
                NavigationalStatus = NavigationalStatus.Underway,
                Destination        = Ports.Duluth,
                Heading            = 45
            };

            ship.Update();

            Assert.IsNull(ship.DerivedEta);
        }
        public void ShipsFarOutDeclaringDuluthButMovingOtherwise()
        {
            var ship = new ShipTest
            {
                Position           = ShipPositions.EastLakeSuperior,
                NavigationalStatus = NavigationalStatus.Underway,
                Destination        = Ports.Duluth,
                Heading            = 45
            };

            ship.Update();

            Assert.IsNull(ship.DerivedEta);
        }
        public void ShipsInHarborForAPeriodOfTimeNotHeadingToDuluth()
        {
            var ship = new ShipTest
            {
                Position            = ShipPositions.DuluthSuperiorDeadZone,
                NavigationalStatus  = NavigationalStatus.Underway,
                CanalEntryTimestamp = DateTime.UtcNow.AddHours(-6),
                Speed   = 1,
                Heading = 90
            };

            ship.Update();

            Assert.IsNull(ship.DerivedEta);
        }
        public void StationaryShipsInStLouisBay()
        {
            var testPosition = ShipPositions.StLouisBay;

            var ship = new ShipTest
            {
                Position            = testPosition,
                NavigationalStatus  = NavigationalStatus.Underway,
                CanalEntryTimestamp = DateTime.UtcNow.AddHours(-6),
                Speed = 0
            };

            ship.Update();

            Assert.AreEqual(DateTime.MaxValue, ship.DerivedEta);
        }
        public void ShipsFarOutAndMovingToDuluth()
        {
            var testTime = DateTime.Now;

            var ship = new ShipTest
            {
                Position           = ShipPositions.EastLakeSuperior,
                NavigationalStatus = NavigationalStatus.Underway,
                Destination        = Ports.Duluth,
                Heading            = 200,
                Eta = testTime
            };

            ship.Update();

            Assert.AreEqual(testTime, ship.DerivedEta);
        }
        public void StationaryShipsInStandardLocations()
        {
            var testPosition = ShipPositions.DuluthSuperiorDeadZone;

            var ship = new ShipTest
            {
                Position            = testPosition,
                NavigationalStatus  = NavigationalStatus.Underway,
                CanalEntryTimestamp = DateTime.UtcNow.AddHours(-6),
                Speed   = 0,
                Heading = 280
            };

            ship.Update();

            Assert.AreEqual(DateTime.MaxValue, ship.DerivedEta);
        }
        public void CanalEntryTimestampForShipsInHarbor()
        {
            var ship = new ShipTest
            {
                Position            = ShipPositions.StLouisBay,
                NavigationalStatus  = NavigationalStatus.Other,
                CanalEntryTimestamp = null
            };

            ship.Update();

            DateTime expected = DateTime.UtcNow.AddHours(ShipTestProcessor.CanalEntryTimestampOffset);

            // ReSharper disable once PossibleInvalidOperationException
            Assert.IsTrue(expected > ship.CanalEntryTimestamp.Value.AddSeconds(-1));
            Assert.IsTrue(expected < ship.CanalEntryTimestamp.Value.AddSeconds(1));
        }
        public void ShipEtasFromStandardLocations()
        {
            var testPosition = ShipPositions.DuluthSuperiorDeadZone;

            var ship = new ShipTest
            {
                Position            = testPosition,
                NavigationalStatus  = NavigationalStatus.Underway,
                CanalEntryTimestamp = DateTime.UtcNow.AddHours(-6),
                Speed   = 1,
                Heading = 280
            };

            var directDistanceToDuluth = GeoHelper.DistanceBetweenCoord(Ports.Duluth, testPosition);

            var expected = DateTime.UtcNow.AddHours(directDistanceToDuluth / ship.Speed) + ShipTestProcessor.DataLag;

            ship.Update();

            // ReSharper disable once PossibleInvalidOperationException
            Assert.IsTrue(expected > ship.DerivedEta.Value.AddSeconds(-1));
            Assert.IsTrue(expected < ship.DerivedEta.Value.AddSeconds(1));
        }