예제 #1
0
        public void OnTimeManagerTick_WhenSomeTimes_RaiseExpectedEventCount(int addedMilliseconds, int tickCount, int expectedEventCount)
        {
            var scheduleProvider = new FakeScheduleProvider();
            var schedule         = scheduleProvider.GetSchedule();

            scheduleProvider.Shedule = schedule;
            var timeManager = new FakeTimeManager();
            int eventCount  = 0;
            var engine      = CreateEngine(timeManager, scheduleProvider);

            engine.PlaneArrived    += (s, a) => eventCount++;
            engine.PlaneDepartured += (s, a) => eventCount++;
            engine.Start();
            var time = TimeSpan.Zero;

            for (var i = 0; i < tickCount; i++)
            {
                time += TimeSpan.FromMilliseconds(addedMilliseconds);
                if (time.Days > 0)
                {
                    time = time.Subtract(TimeSpan.FromDays(time.Days));
                }
                timeManager.RaiseTick(new TickEventArgs {
                    Time = time
                });
            }

            Assert.AreEqual(expectedEventCount, eventCount);
        }
예제 #2
0
        public void Start_Always_OrderFlights()
        {
            var scheduleProvider = new FakeScheduleProvider();
            var schedule         = scheduleProvider.GetSchedule();

            schedule.Flights         = schedule.Flights.OrderByDescending(x => x.Time).ToList();
            scheduleProvider.Shedule = schedule;
            var engine = CreateEngine(scheduleProvider);

            engine.Start();

            var orderedFlights = schedule.Flights.OrderBy(x => x.Time).ToList();

            Assert.IsTrue(orderedFlights.SequenceEqual(schedule.Flights));
        }
예제 #3
0
        public void OnTimeManagerTick_WhenExistsFlights_RaiseExpectedEvent(int addedMilliseconds, int expectedArrived, int expectedDepartured)
        {
            var scheduleProvider = new FakeScheduleProvider();
            var schedule         = scheduleProvider.GetSchedule();

            scheduleProvider.Shedule = schedule;
            var timeManager = new FakeTimeManager();
            int arrived     = 0;
            int departured  = 0;
            var engine      = CreateEngine(timeManager, scheduleProvider);

            engine.PlaneArrived    += (s, a) => arrived++;
            engine.PlaneDepartured += (s, a) => departured++;
            engine.Start();

            timeManager.RaiseTick(new TickEventArgs {
                Time = schedule.Flights.First().Time.Add(TimeSpan.FromMilliseconds(addedMilliseconds))
            });

            Assert.AreEqual(expectedArrived, arrived);
            Assert.AreEqual(expectedDepartured, departured);
        }