예제 #1
0
        public void OnlyWaitingRider_LeavingRangeOfStart_ShouldRemoveThem()
        {
            Beacon martijnBeacon = new Beacon(new byte[] { 0, 0, 0, 0, 0, 1 }, 0);
            Rider  martijn       = new Rider("Martijn", martijnBeacon);

            subject.AddRider(martijn);

            bool isEmpty = false;

            subject.OnStartEmpty += (obj, args) => isEmpty = true;

            //rider enters start box
            startId.EmitIdEvent(martijn, new DateTime(2000, 1, 1, 1, 1, 1));

            //the race tracker is processing events in a different thread, we must wait for it
            Thread.Sleep(1000);

            //event should not have fired
            Assert.IsFalse(isEmpty);

            startId.EmitExitEvent(martijn, new DateTime(2000, 1, 1, 1, 1, 1));

            source.Cancel();
            race.Wait();

            var state = subject.GetState;

            Assert.AreEqual(0, state.waiting.Count);

            Assert.IsTrue(isEmpty);
        }
예제 #2
0
        public void Penalty_WithRiderOnTrack_ShouldApplyOnFinish()
        {
            Beacon martijnBeacon = new Beacon(new byte[] { 0, 0, 0, 0, 0, 1 }, 0);
            Rider  martijn       = new Rider("Martijn", martijnBeacon);

            subject.AddRider(martijn);

            //rider enters start box
            startId.EmitIdEvent(martijn, new DateTime(2000, 1, 1, 1, 1, 1));

            //Martijn triggers timing gate
            timer.EmitTriggerEvent(100, "Timer", 0, new DateTime(2000, 1, 1, 1, 2, 1));

            subject.AddEvent(new PenaltyEventArgs(DateTime.Now, martijn.Name, "staff", "testEvent", 1));
            subject.AddEvent(new PenaltyEventArgs(DateTime.Now, martijn.Name, "staff", "testEvent", 2));

            //finish the lap
            endId.EmitIdEvent(martijn, new DateTime(2000, 1, 1, 1, 2, 1));
            timer.EmitTriggerEvent(200, "Timer", 1, new DateTime(2000, 1, 1, 1, 2, 1));
            endId.EmitExitEvent(martijn, new DateTime(2000, 1, 1, 1, 2, 1));


            //do another lap, this one should not have any penalties
            MakeStartEvents(martijn, DateTime.Now, startId, timer);
            MakeEndEvents(martijn, DateTime.Now, endId, timer);

            source.Cancel();
            race.Wait();

            Assert.AreEqual(0, endId.KnownRiders.Count);
            Assert.AreEqual(2, subject.Laps.Count);

            Lap penaltyLap = subject.Laps[0];

            Assert.IsTrue(penaltyLap.End is FinishedEvent);
            //100 micros lap time, 3 second penalty
            Assert.AreEqual(3000100, penaltyLap.GetLapTime());
            Assert.IsFalse(penaltyLap.Disqualified);

            Lap normalLap = subject.Laps[1];

            Assert.IsTrue(normalLap.End is FinishedEvent);
            //Lap from MakeEvent methods has nonsense lap time
            Assert.AreEqual(0, normalLap.GetLapTime());
            Assert.IsFalse(normalLap.Disqualified);
        }
예제 #3
0
 /// <summary>
 /// Makes events for a lap finish at start + 1 minute
 /// </summary>
 /// <param name="riderName"></param>
 /// <param name="sensorId"></param>
 /// <param name="end"></param>
 /// <param name="id"></param>
 /// <param name="time"></param>
 private void MakeEndEvents(Rider rider, DateTime end, MockRiderIdUnit id, MockTimingUnit time)
 {
     id.EmitIdEvent(rider, end);
     time.EmitTriggerEvent(100, "Timer", 1, end);
     id.EmitExitEvent(rider, end);
 }
예제 #4
0
 /// <summary>
 /// Makes events for a lap begin at start
 /// </summary>
 /// <param name="riderName"></param>
 /// <param name="sensorId"></param>
 /// <param name="start"></param>
 /// <param name="id"></param>
 /// <param name="time"></param>
 private void MakeStartEvents(Rider rider, DateTime start, MockRiderIdUnit id, MockTimingUnit time)
 {
     id.EmitIdEvent(rider, start);
     time.EmitTriggerEvent(100, "Timer", 0, start);
     id.EmitExitEvent(rider, start);
 }