Exemple #1
0
        public void ChangeStartNumber()
        {
            string dbFilename = TestUtilities.CreateWorkingFileFrom(testContextInstance.TestDeploymentDir, @"TestDB_LessParticipants_MultipleRacesNoStartnumber.mdb");

            RaceHorologyLib.Database db = new RaceHorologyLib.Database();
            db.Connect(dbFilename);

            AppDataModel model = new AppDataModel(db);
            var          rps   = model.GetRace(0).GetParticipants().ToList();

            // Assign startnumber from scratch
            rps.Sort(Comparer <RaceParticipant> .Create((x, y) => x.Name.CompareTo(y.Name)));
            for (int i = 0; i < rps.Count; i++)
            {
                Assert.AreEqual(0U, rps[i].StartNumber, "pre-condition check of unassigned startnumber");
                rps[i].StartNumber = (uint)i + 1;
            }

            // TEST 1: Test whether startnumber is remembered
            for (int i = 0; i < rps.Count; i++)
            {
                Assert.AreEqual((uint)i + 1, rps[i].StartNumber);
            }

            db.Close();
            model = null;

            // TEST 2: Cross-Check whether the startnumbers have been stored in DataBase
            RaceHorologyLib.Database db2 = new RaceHorologyLib.Database();
            db2.Connect(dbFilename);
            AppDataModel model2 = new AppDataModel(db2);
            var          rps2   = model2.GetRace(0).GetParticipants().ToList();

            Assert.AreEqual(rps.Count, rps2.Count);

            rps2.Sort(Comparer <RaceParticipant> .Create((x, y) => x.Name.CompareTo(y.Name)));
            for (int i = 0; i < rps2.Count; i++)
            {
                Assert.AreEqual((uint)i + 1, rps2[i].StartNumber);
            }
        }
        public void RaceParticpant1()
        {
            string dbFilename = TestUtilities.CreateWorkingFileFrom(testContextInstance.TestDeploymentDir, @"TestDB_LessParticipants_MultipleRacesNoStartnumber.mdb");

            RaceHorologyLib.Database db = new RaceHorologyLib.Database();
            db.Connect(dbFilename);

            AppDataModel model = new AppDataModel(db);
            var          race  = model.GetRace(0);

            Assert.AreEqual(Race.ERaceType.DownHill, race.RaceType); // Check that the correct race has been selected

            var rps = race.GetParticipants().ToList();

            rps.Sort(Comparer <RaceParticipant> .Create((x, y) => x.Name.CompareTo(y.Name)));

            // TEST: Remove particpant
            race.GetParticipants().Remove(rps[0]); // "Nachname 1"
            Assert.IsNull(race.GetParticipants().FirstOrDefault(p => p.Name == "Nachname 1"));

            // TEST: Add particpant
            var p7 = model.GetParticipants().First(p => p.Name == "Nachname 7");

            race.AddParticipant(p7);
            Assert.IsNotNull(race.GetParticipants().FirstOrDefault(p => p.Name == "Nachname 7"));

            model = null;
            db.Close();


            // TEST: Cross-Check whether the startnumbers have been stored in DataBase
            RaceHorologyLib.Database db2 = new RaceHorologyLib.Database();
            db2.Connect(dbFilename);
            AppDataModel model2 = new AppDataModel(db2);

            Assert.IsNull(model2.GetRace(0).GetParticipants().FirstOrDefault(p => p.Name == "Nachname 1"));
            Assert.IsNotNull(model2.GetRace(0).GetParticipants().FirstOrDefault(p => p.Name == "Nachname 7"));
            return;
        }