예제 #1
0
        public async Task InsertTest()
        {
            var skierId = (await SkierDao.FindAllAsync()).First().Id;
            var raceId  = (await RaceDao.FindAllAsync()).First().Id;

            var newSkierId = await SkierDao.InsertGetIdAsync(new Skier
            {
                Retired     = false,
                CountryId   = (await CountryDao.FindAllAsync()).First().Id,
                FirstName   = "ABC",
                LastName    = "DEF",
                GenderId    = 1,
                DateOfBirth = DateTime.Now
            });

            await StartListDao.InsertAsync(new StartList
            {
                SkierId      = newSkierId.Value,
                RaceId       = raceId,
                StartNumber  = 99,
                StartStateId = (int)Domain.Enums.RaceState.Finished
            });

            var startList = await StartListDao.FindByIdAsync(skierId, raceId);

            Assert.AreEqual(skierId, startList.SkierId);
            Assert.AreEqual(raceId, startList.RaceId);
            Assert.AreEqual((int)Domain.Enums.RaceState.Finished, startList.StartStateId);
            Assert.NotNull(startList.Skier);
            Assert.NotNull(startList.StartState);
            Assert.NotNull(startList.Race);
        }
예제 #2
0
        protected TestBase()
        {
            var config  = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
            var section = config.GetSection("ConnectionStrings").GetSection("huraceTest");

            var provider         = section["ProviderName"];
            var connectionString = section["ConnectionString"];

            ConnectionFactory =
                new ConcreteConnectionFactory(DbUtil.GetProviderFactory(provider), connectionString);

            RaceDao        = new RaceDao(ConnectionFactory, StatementFactory);
            SeasonDao      = new SeasonDao(ConnectionFactory, StatementFactory);
            LocationDao    = new LocationDao(ConnectionFactory, StatementFactory);
            CountryDao     = new CountryDao(ConnectionFactory, StatementFactory);
            DisciplineDao  = new DisciplineDao(ConnectionFactory, StatementFactory);
            SkierDao       = new SkierDao(ConnectionFactory, StatementFactory);
            StartListDao   = new StartListDao(ConnectionFactory, StatementFactory);
            RaceEventDao   = new RaceEventDao(ConnectionFactory, StatementFactory);
            SkierEventDao  = new SkierEventDao(ConnectionFactory, StatementFactory);
            TimeDataDao    = new TimeDataDao(ConnectionFactory, StatementFactory);
            GenderDao      = new GenderDao(ConnectionFactory, StatementFactory);
            SensorDao      = new SensorDao(ConnectionFactory, StatementFactory);
            RaceDataDao    = new RaceDataDao(ConnectionFactory, StatementFactory);
            RaceStateDao   = new RaceStateDao(ConnectionFactory, StatementFactory);
            StartStateDao  = new StartStateDao(ConnectionFactory, StatementFactory);
            EventTypeDao   = new EventTypeDao(ConnectionFactory, StatementFactory);
            _dataGenerator = new DataGenerator.Core.DataGenerator(provider, connectionString);
        }
예제 #3
0
        public override void Initialize()
        {
            var connectionString       = ConfigurationReader.GetConnectionString(Environment.Production);
            var databaseName           = GetDatabaseName(connectionString);
            var task                   = Task.Run(async() => await ApplicationData.Current.LocalFolder.CreateFileAsync(databaseName, CreationCollisionOption.OpenIfExists)).Result;
            var databasePath           = Path.Combine(ApplicationData.Current.LocalFolder.Path, databaseName);
            var customConnectionString = connectionString.Replace(databaseName, databasePath, StringComparison.CurrentCulture);

            var connectionFactory    = new ConnectionFactory(Environment.Production, customConnectionString);
            var locationDao          = new LocationDao(connectionFactory);
            var skierDao             = new SkierDao(connectionFactory);
            var countryDao           = new CountryDao(connectionFactory);
            var raceDao              = new RaceDao(connectionFactory);
            var runDao               = new RunDao(connectionFactory);
            var sensorMeasurementDao = new SensorMeasurementDao(connectionFactory);

            var daoProvider        = new DaoProvider(countryDao, locationDao, raceDao, runDao, sensorMeasurementDao, skierDao);
            var messengerHub       = new MvxMessengerHub();
            var simulatorRaceClock = new SimulatorRaceClock();

            Mvx.IoCProvider.RegisterSingleton <IMvxMessenger>(messengerHub);
            Mvx.IoCProvider.RegisterSingleton <IDialogService>(new DialogService(messengerHub));
            Mvx.IoCProvider.RegisterSingleton <IRaceService>(new RaceService(daoProvider));
            Mvx.IoCProvider.RegisterSingleton <ILocationService>(new LocationService(daoProvider));
            Mvx.IoCProvider.RegisterSingleton <ISkierService>(new SkierService(daoProvider));
            Mvx.IoCProvider.RegisterSingleton <IRunService>(new RunService(daoProvider, simulatorRaceClock));
            Mvx.IoCProvider.RegisterSingleton <SimulatorRaceClock>(simulatorRaceClock);

            RegisterAppStart <ViewModels.NavigationRootViewModel>();
        }
예제 #4
0
        public async Task FindAvailableSkiersForRaceTest()
        {
            var skier = (await SkierDao.FindAllAsync()).First();
            var race  = (await RaceDao.FindAllAsync()).First();

            var availableSkiers = await SkierDao.FindAvailableSkiersForRace(race.Id);

            Assert.IsTrue(availableSkiers.All(s => s.Id != skier.Id));


            var newSkierId = await SkierDao.InsertGetIdAsync(new Skier
            {
                Retired     = false,
                FirstName   = "xy",
                LastName    = "z",
                CountryId   = (await CountryDao.FindAllAsync()).First().Id,
                GenderId    = race.GenderId,
                DateOfBirth = DateTime.Today
            });

            availableSkiers = await SkierDao.FindAvailableSkiersForRace(race.Id);

            Assert.IsTrue(availableSkiers.All(s => s.Id != newSkierId.Value));

            var newSkier = await SkierDao.FindByIdAsync(newSkierId.Value);

            newSkier.GenderId = newSkier.GenderId == 1 ? 2 : 1;

            await SkierDao.UpdateAsync(newSkier);

            availableSkiers = await SkierDao.FindAvailableSkiersForRace(race.Id);

            Assert.IsFalse(availableSkiers.Any(s => s.Id != newSkierId.Value));
        }
예제 #5
0
        public async Task GetSensorForSensorNumberTest()
        {
            var race   = (await RaceDao.FindAllAsync()).First();
            var sensor = (await SensorDao.FindAllSensorsForRace(race.Id)).First();

            Assert.AreEqual(sensor.Id, (await SensorDao.GetSensorForSensorNumber(sensor.SensorNumber, race.Id)).Id);
        }
예제 #6
0
        public async Task InsertTest()
        {
            var disciplineId = (await DisciplineDao.FindAllAsync()).First().Id;
            var locationId   = (await LocationDao.FindAllAsync()).First().Id;
            var seasonId     = (await SeasonDao.FindAllAsync()).First().Id;

            var raceId = await RaceDao.InsertGetIdAsync(new Race
            {
                DisciplineId    = disciplineId,
                GenderId        = (int)Domain.Enums.Gender.Male,
                LocationId      = locationId,
                RaceDescription = "Description",
                SeasonId        = seasonId,
                RaceStateId     = (int)Domain.Enums.RaceDataEvent.RaceFinished,
                RaceDate        = new DateTime(2019, 11, 15)
            });

            var raceById = await RaceDao.FindByIdAsync(raceId.Value);

            Assert.AreEqual(disciplineId, raceById.DisciplineId);
            Assert.AreEqual((int)Domain.Enums.Gender.Male, raceById.GenderId);
            Assert.AreEqual(locationId, raceById.LocationId);
            Assert.AreEqual("Description", raceById.RaceDescription);
            Assert.AreEqual(seasonId, raceById.SeasonId);
            Assert.AreEqual((int)Domain.Enums.RaceDataEvent.RaceFinished, raceById.RaceStateId);
            Assert.AreEqual(new DateTime(2019, 11, 15), raceById.RaceDate);
            Assert.NotNull(raceById.Location);
            Assert.NotNull(raceById.Gender);
            Assert.NotNull(raceById.Season);
        }
예제 #7
0
        public async Task GetRankingForSensorTest()
        {
            var race    = (await RaceDao.FindAllAsync()).First();
            var ranking = (await TimeDataDao.GetRankingForSensor(race.Id, 1)).ToList();

            Assert.AreEqual(5, ranking.Count());
            Assert.IsTrue(ranking[0].Time < ranking[1].Time);
        }
예제 #8
0
        public async Task UpdateTest()
        {
            var race = (await RaceDao.FindAllAsync()).First();

            race.RaceDescription = "Test123";
            await RaceDao.UpdateAsync(race);

            Assert.AreEqual(race.RaceDescription, (await RaceDao.FindByIdAsync(race.Id))?.RaceDescription);
        }
예제 #9
0
        public async Task GetActiveRacesTest()
        {
            var race = (await RaceDao.FindAllAsync()).First();

            race.RaceStateId = 2;
            await RaceDao.UpdateAsync(race);

            Assert.AreEqual(1, (await RaceDao.GetActiveRaces()).Count());
        }
예제 #10
0
        public async Task GetActiveRaceByIdTest()
        {
            var race = (await RaceDao.FindAllAsync()).First();

            race.RaceStateId = 2;
            await RaceDao.UpdateAsync(race);

            Assert.NotNull(await RaceDao.GetActiveRaceById(race.Id));
        }
예제 #11
0
        public async Task FindByIdTest()
        {
            var race     = (await RaceDao.FindAllAsync()).First();
            var raceById = await RaceDao.FindByIdAsync(race.Id);

            Assert.AreEqual(race.RaceDescription, raceById?.RaceDescription);
            Assert.NotNull(raceById?.Gender);
            Assert.NotNull(raceById?.Location);
            Assert.NotNull(raceById?.Season);
            Assert.NotNull(raceById?.RaceState);
        }
예제 #12
0
        public async Task DeleteTest()
        {
            var raceDataId = await RaceDataDao.InsertGetIdAsync(new RaceData
            {
                RaceId        = (await RaceDao.FindAllAsync()).First().Id,
                EventDateTime = DateTime.Now,
                EventTypeId   = (await EventTypeDao.FindAllAsync()).First().Id
            });

            await RaceDataDao.DeleteAsync(raceDataId.Value);

            Assert.IsNull(await RaceDataDao.FindByIdAsync(raceDataId.Value));
        }
        public async void TestDelete()
        {
            ConnectionFactory connectionFactory = new ConnectionFactory(Environment.Testing);
            IRaceDao          raceDao           = new RaceDao(connectionFactory);

            Race race = await InsertRace(connectionFactory);

            Assert.NotNull(await raceDao.FindById(race.Id));

            await raceDao.Delete(race.Id);

            Assert.Null(await raceDao.FindById(race.Id));
        }
        public async void TestFindById()
        {
            ConnectionFactory connectionFactory = new ConnectionFactory(Environment.Testing);
            IRaceDao          raceDao           = new RaceDao(connectionFactory);

            Race race = await InsertRace(connectionFactory);

            Race raceFound = await raceDao.FindById(race.Id);

            Assert.Equal(race.Name, raceFound.Name);
            Assert.Equal(race.Gender, raceFound.Gender);
            Assert.Equal(race.RaceType, raceFound.RaceType);
        }
예제 #15
0
        public async Task FindByIdTest()
        {
            var skier    = (await SkierDao.FindAllAsync()).First();
            var race     = (await RaceDao.FindAllAsync()).First();
            var sensor   = (await SensorDao.FindAllAsync()).First();
            var timeData = await TimeDataDao.FindByIdAsync(skier.Id, race.Id, sensor.Id);

            Assert.NotNull(timeData);
            Assert.NotNull(timeData.StartList);
            Assert.NotNull(timeData?.SkierEvent);
            Assert.NotNull(timeData?.SkierEvent?.RaceData);
            Assert.NotNull(timeData?.Sensor);
            Assert.AreEqual(DateTime.Today.Millisecond, timeData?.Time);
        }
예제 #16
0
        public async Task InsertTest()
        {
            var raceId = (await RaceDao.FindAllAsync()).First().Id;
            var id     = await SensorDao.InsertGetIdAsync(new Sensor
            {
                RaceId       = raceId,
                SensorNumber = 21
            });

            var sensor = await SensorDao.FindByIdAsync(id.Value);

            Assert.AreEqual(21, sensor.SensorNumber);
            Assert.AreEqual(raceId, sensor.RaceId);
        }
예제 #17
0
        public async Task GetAverageTimeForSensorTest()
        {
            var race      = (await RaceDao.FindAllAsync()).First();
            var timeDatas = await TimeDataDao.FindAllAsync();

            var tasks = timeDatas.Where(t => t.RaceId == race.Id && t.Sensor.SensorNumber == 1).Select(
                async t =>
            {
                t.Time = 1500;
                await TimeDataDao.UpdateAsync(t);
            });
            await Task.WhenAll(tasks);

            Assert.AreEqual(1500, await TimeDataDao.GetAverageTimeForSensor(race.Id, 1));
        }
예제 #18
0
        public async Task InsertTest()
        {
            var raceId     = (await RaceDao.FindAllAsync()).First().Id;
            var raceDataId = await RaceDataDao.InsertGetIdAsync(new RaceData
            {
                RaceId        = raceId,
                EventDateTime = new DateTime(1969, 4, 20),
                EventTypeId   = (int)Domain.Enums.RaceDataEvent.RaceFinished
            });

            var raceDataById = await RaceDataDao.FindByIdAsync(raceDataId.Value);

            Assert.AreEqual(raceId, raceDataById.RaceId);
            Assert.AreEqual(new DateTime(1969, 4, 20), raceDataById.EventDateTime);
            Assert.AreEqual((int)Domain.Enums.RaceDataEvent.RaceFinished, raceDataById.EventTypeId);
        }
        public async void TestUpdate()
        {
            ConnectionFactory connectionFactory = new ConnectionFactory(Environment.Testing);
            IRaceDao          raceDao           = new RaceDao(connectionFactory);

            Race race = await InsertRace(connectionFactory);

            race.Name     = "Hinterstoder Slalom";
            race.RaceType = RaceType.SuperSlalom;
            await raceDao.Update(race);

            Race raceAfter = await raceDao.FindById(race.Id);

            Assert.Equal(race.Name, raceAfter.Name);
            Assert.Equal(race.RaceType, raceAfter.RaceType);
        }
        public async void TestFindAll()
        {
            ConnectionFactory connectionFactory = new ConnectionFactory(Environment.Testing);
            IRaceDao          raceDao           = new RaceDao(connectionFactory);

            foreach (var _ in await raceDao.FindAll())
            {
                Assert.True(false, "FindAll should return an empty collection");
            }

            await InsertRace(connectionFactory);

            foreach (var _ in await raceDao.FindAll())
            {
                return;
            }
            Assert.True(false, "FindAll should return a non-empty collection");
        }
예제 #21
0
        private void AddHuraceServices(IServiceCollection services)
        {
            var connectionString     = ConfigurationReader.GetConnectionString(Environment.Production);
            var connectionFactory    = new ConnectionFactory(Environment.Production, connectionString);
            var locationDao          = new LocationDao(connectionFactory);
            var skierDao             = new SkierDao(connectionFactory);
            var countryDao           = new CountryDao(connectionFactory);
            var raceDao              = new RaceDao(connectionFactory);
            var runDao               = new RunDao(connectionFactory);
            var sensorMeasurementDao = new SensorMeasurementDao(connectionFactory);
            var daoProvider          = new DaoProvider(countryDao, locationDao, raceDao, runDao, sensorMeasurementDao, skierDao);

            services.AddSingleton <IRaceService>(new RaceService(daoProvider));
            services.AddSingleton <ISkierService>(new SkierService(daoProvider));
            services.AddSingleton <ILocationService>(new LocationService(daoProvider));
            services.AddSingleton <IRunService>(new RunService(daoProvider, new SimulatorRaceClock()));
            services.AddSingleton <ICountryService>(new CountryService(daoProvider));
            services.AddCors(options => options.AddPolicy("CORS", builder =>
                                                          builder.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader()));
        }
예제 #22
0
        public async Task UpdateTest()
        {
            var skier    = (await SkierDao.FindAllAsync()).First();
            var race     = (await RaceDao.FindAllAsync()).First();
            var sensor   = (await SensorDao.FindAllAsync()).First();
            var timeData = await TimeDataDao.FindByIdAsync(skier.Id, race.Id, sensor.Id);

            if (timeData != null)
            {
                timeData.Time = 500;
                await TimeDataDao.UpdateAsync(timeData);

                timeData = await TimeDataDao.FindByIdAsync(skier.Id, race.Id, sensor.Id);

                Assert.AreEqual(500, timeData?.Time);
            }
            else
            {
                Assert.Fail("TimeData was null");
            }
        }
예제 #23
0
        public async Task InsertTest()
        {
            var skier        = (await SkierDao.FindAllAsync()).First();
            var race         = (await RaceDao.FindAllAsync()).First();
            var skierEventId = (await SkierEventDao.FindAllAsync()).First().Id;
            var newSensorId  =
                await SensorDao.InsertGetIdAsync(new Sensor { RaceId = race.Id, SensorNumber = 0 });

            await TimeDataDao.InsertAsync(new TimeData
            {
                SkierEventId = skierEventId,
                RaceId       = race.Id,
                SensorId     = newSensorId.Value,
                Time         = new DateTime(2019, 11, 6).Millisecond,
                SkierId      = skier.Id
            });

            var timeData = await TimeDataDao.FindByIdAsync(skier.Id, race.Id, newSensorId.Value);

            Assert.NotNull(timeData);
            Assert.AreEqual(new DateTime(2019, 11, 6).Millisecond, timeData?.Time);
        }
예제 #24
0
        public async Task GetRemainingStartListForRaceTest()
        {
            var race = (await RaceDao.FindAllAsync()).First();

            Assert.AreEqual(0, (await StartListDao.GetRemainingStartListForRace(race.Id)).Count());

            var skierId = await SkierDao.InsertGetIdAsync(new Skier
            {
                Retired     = false,
                FirstName   = "F",
                LastName    = "S",
                CountryId   = (await CountryDao.FindAllAsync()).First().Id,
                GenderId    = race.GenderId,
                DateOfBirth = DateTime.Now
            });

            await StartListDao.InsertAsync(new StartList
            {
                RaceId = race.Id, SkierId = skierId.Value, StartNumber = 99, StartStateId = (int)StartState.Upcoming
            });

            Assert.AreEqual(1, (await StartListDao.GetRemainingStartListForRace(race.Id)).Count());
        }
        public static async Task <Race> InsertRace(ConnectionFactory connectionFactory, Location location = null)
        {
            IRaceDao raceDao = new RaceDao(connectionFactory);

            location ??= await LocationDaoTests.InsertLocation(connectionFactory);

            Race race = new Race
            {
                Name            = "Kitzbühel Slalom",
                Date            = DateTime.Today,
                Location        = location,
                Gender          = Gender.Female,
                RaceType        = RaceType.Slalom,
                Description     = null,
                Website         = null,
                NumberOfSensors = 5,
                Status          = RaceStatus.Ready
            };

            race.Id = await raceDao.Insert(race);

            return(race);
        }
예제 #26
0
        public async Task GetRacesForSeason()
        {
            var season = (await SeasonDao.FindAllAsync()).First();

            Assert.AreEqual(2, (await RaceDao.GetRacesForSeasonId(season.Id)).Count());
        }
예제 #27
0
        public async Task CountTimeDataForRaceTest()
        {
            var race = (await RaceDao.FindAllAsync()).First();

            Assert.AreEqual(10, await TimeDataDao.CountTimeDataForRace(race.Id));
        }
예제 #28
0
 public async Task FindAllTest() => Assert.AreEqual(2, (await RaceDao.FindAllAsync()).Count());
예제 #29
0
        public async Task CountStartListForRaceTest()
        {
            var raceId = (await RaceDao.FindAllAsync()).First().Id;

            Assert.AreEqual(5, await StartListDao.CountStartListForRace(raceId));
        }
예제 #30
0
        public async Task GetLastSensorNumberTest()
        {
            var race = (await RaceDao.FindAllAsync()).First();

            Assert.AreEqual(1, await SensorDao.GetLastSensorNumber(race.Id));
        }