コード例 #1
0
        public async void TestInterimTimesCalculation()
        {
            // Setup
            var timestamps = new[] { 1576850000.000, 1576850001.111, 1576850002.222 };

            var sensorMeasurementDaoMock = new Mock <ISensorMeasurementDao>();

            sensorMeasurementDaoMock.Setup(d => d.GetMeasurementsForRun(It.IsAny <Run>()))
            .Returns(Task.FromResult(
                         timestamps.Select(t => new SensorMeasurement {
                Timestamp = t
            })
                         ));

            var runDaoMock = new Mock <IRunDao>();

            runDaoMock.Setup(d => d.GetBySkierAndRace(It.IsAny <Race>(), It.IsAny <int>(), It.IsAny <Skier>()))
            .Returns(Task.FromResult(new Run()));

            var daoProvider = DaoProviderHelper.GetPartialDaoProvider(
                sensorMeasurementDao: sensorMeasurementDaoMock.Object,
                runDao: runDaoMock.Object
                );
            var runService = new RunService(daoProvider, new SimulatorRaceClock());

            // Execute
            var calculatedTimespans = (await runService.GetInterimTimes(null, 1, null)).ToArray();

            // Assert
            Assert.Equal(timestamps.Length - 1, calculatedTimespans.Length);
            Assert.Equal(calculatedTimespans[0], TimeSpan.FromSeconds(timestamps[1] - timestamps[0]));
            Assert.Equal(calculatedTimespans[1], TimeSpan.FromSeconds(timestamps[2] - timestamps[0]));
        }
コード例 #2
0
        public async void TestLeaderBoardCalculation()
        {
            // Setup
            var totalTimes = new[] { 2.2, 1.1, 3.3, 0.0, 0.0 };

            var runDaoMock = new Mock <IRunDao>();

            runDaoMock.Setup(d => d.GetAllRunsForRace(It.IsAny <Race>(), It.IsAny <int>()))
            .Returns(Task.FromResult(
                         totalTimes.Select(t => new Run {
                TotalTime = t
            })
                         ));

            var daoProvider = DaoProviderHelper.GetPartialDaoProvider(runDao: runDaoMock.Object);
            var runService  = new RunService(daoProvider, new SimulatorRaceClock());

            // Execute
            var leaderBoard = (await runService.GetLeaderBoard(null, 1)).ToArray();

            // Assert
            Assert.Equal(totalTimes.Length, leaderBoard.Length);
            Assert.Equal(1.1, leaderBoard[0].TotalTime);
            Assert.Equal(2.2, leaderBoard[1].TotalTime);
            Assert.Equal(3.3, leaderBoard[2].TotalTime);
            Assert.Equal(0.0, leaderBoard[3].TotalTime);
            Assert.Equal(0.0, leaderBoard[4].TotalTime);
        }
コード例 #3
0
        public void TestRunStatusChangedEventInvocation()
        {
            // Setup
            var runDaoMock = new Mock <IRunDao>();

            runDaoMock.Setup(d => d.GetBySkierAndRace(It.IsAny <Race>(), It.IsAny <int>(), It.IsAny <Skier>()))
            .Returns(Task.FromResult(
                         new Run {
                Status = RunStatus.Ready
            })
                     );

            var daoProvider = DaoProviderHelper.GetPartialDaoProvider(runDao: runDaoMock.Object);
            var runService  = new RunService(daoProvider, new SimulatorRaceClock());

            var eventTriggered = false;

            runService.RunStatusChanged += (race, runNumber, skier, runStatus) => eventTriggered = true;

            // Execute
            runService.UpdateRunStatus(null, 1, null, RunStatus.InProgress);

            // Assert
            Assert.True(eventTriggered);
        }
コード例 #4
0
        private static RunService GetRunServiceForSensorImpulseHandlingTest(IRaceClock raceClock)
        {
            var existingMeasurementsTimestamps = new[] { 1576850000.000, 1576850001.111, 1576850002.222 };

            var sensorMeasurementDaoMock = new Mock <ISensorMeasurementDao>();

            sensorMeasurementDaoMock.Setup(d => d.GetMeasurementsForRun(It.IsAny <Run>()))
            .Returns(Task.FromResult(
                         existingMeasurementsTimestamps.Select((t, i) => new SensorMeasurement
            {
                SensorId  = i,
                Timestamp = t
            })
                         ));

            var runDaoMock = new Mock <IRunDao>();

            runDaoMock.Setup(d => d.GetCurrentRun())
            .Returns(Task.FromResult(
                         new Run
            {
                Race = new Race {
                    NumberOfSensors = existingMeasurementsTimestamps.Length + 1
                }
            }
                         ));

            var daoProvider = DaoProviderHelper.GetPartialDaoProvider(
                runDao: runDaoMock.Object,
                sensorMeasurementDao: sensorMeasurementDaoMock.Object
                );

            return(new RunService(daoProvider, raceClock));
        }
コード例 #5
0
        public void TestRaceStatusChangedEventInvocation()
        {
            // Setup
            var raceDaoMock = new Mock <IRaceDao>();

            raceDaoMock.Setup(d => d.FindById(It.IsAny <int>()))
            .Returns(Task.FromResult(
                         new Race {
                Status = RaceStatus.Ready
            })
                     );

            var daoProvider = DaoProviderHelper.GetPartialDaoProvider(raceDao: raceDaoMock.Object);
            var raceService = new RaceService(daoProvider);

            var eventTriggered = false;

            raceService.RaceStatusChanged += (race, status) => eventTriggered = true;

            // Execute and Assert
            raceService.EditRace(new Race {
                Status = RaceStatus.Ready
            });
            Assert.False(eventTriggered);

            raceService.EditRace(new Race {
                Status = RaceStatus.InProgress
            });
            Assert.True(eventTriggered);
        }
コード例 #6
0
        public void TestAutomaticStartListCreation()
        {
            // Setup
            var skiers = new[] { new Skier(), new Skier(), new Skier() };

            var raceDaoMock = new Mock <IRaceDao>();
            var runDaoMock  = new Mock <IRunDao>();

            var daoProvider = DaoProviderHelper.GetPartialDaoProvider(
                raceDao: raceDaoMock.Object,
                runDao: runDaoMock.Object
                );
            var raceService = new RaceService(daoProvider);

            // Execute
            raceService.CreateRace(new Race(), skiers.ToList());

            // Assert
            runDaoMock.Verify(
                d => d.InsertMany(It.IsAny <IEnumerable <Run> >()),
                Times.Once()
                );
        }
コード例 #7
0
        public void TestAutomaticInvertedStartListCreation()
        {
            // Setup
            var lastRunStatuses            = new[] { RunStatus.Completed, RunStatus.Disqualified, RunStatus.Completed };
            IEnumerable <Run> newRunsAdded = null;

            var raceDaoMock = new Mock <IRaceDao>();
            var runDaoMock  = new Mock <IRunDao>();

            runDaoMock.Setup(d => d.GetAllRunsForRace(It.IsAny <Race>(), It.IsAny <int>()))
            .Returns(Task.FromResult(
                         lastRunStatuses.Select(s => new Run {
                Status = s
            })
                         ));
            runDaoMock.Setup(d => d.InsertMany(It.IsAny <IEnumerable <Run> >()))
            .Callback <IEnumerable <Run> >(runs =>
                                           newRunsAdded = runs
                                           );

            var daoProvider = DaoProviderHelper.GetPartialDaoProvider(
                raceDao: raceDaoMock.Object,
                runDao: runDaoMock.Object
                );
            var raceService = new RaceService(daoProvider);

            // Execute
            raceService.CompleteRun(new Race(), 1);

            // Assert
            runDaoMock.Verify(
                d => d.InsertMany(It.IsAny <IEnumerable <Run> >()),
                Times.Once()
                );
            Assert.Equal(2, newRunsAdded.ToArray().Length);
        }