public void ImportParticpantsWithClassAssignment() { string dbFilename = TestUtilities.CreateWorkingFileFrom(testContextInstance.TestDeploymentDir, @"TestDB_EmptyManyClasses.mdb"); RaceHorologyLib.Database db = new RaceHorologyLib.Database(); db.Connect(dbFilename); AppDataModel dm = new AppDataModel(db); var ir = new ImportReader(@"Teilnehmer_V1_202001301844.csv"); RaceMapping mapping = new RaceMapping(ir.Columns); ClassAssignment cla = new ClassAssignment(dm.GetParticipantClasses()); RaceImport im = new RaceImport(dm.GetRace(0), mapping, cla); var impRes = im.DoImport(ir.Data); Assert.AreEqual(153, impRes.SuccessCount); Assert.AreEqual(0, impRes.ErrorCount); for (int i = 0; i < 153; i++) { Participant p = dm.GetParticipants()[i]; RaceParticipant rp = dm.GetRace(0).GetParticipants()[i]; Assert.AreEqual(string.Format("Name {0}", i + 1), p.Name); Assert.AreEqual(string.Format("Name {0}", i + 1), rp.Name); Assert.IsTrue(rp.Participant == p); Assert.AreSame(cla.DetermineClass(p), p.Class); Assert.IsNotNull(p.Class); } }
public void ImportParticpantsForRaceWithPoints() { TestDataGenerator tg = new TestDataGenerator(); var ir = new ImportReader(@"Teilnehmer_Import_Race.xlsx"); RaceMapping mapping = new RaceMapping(ir.Columns); RaceImport im = new RaceImport(tg.Model.GetRace(0), mapping); var impRes = im.DoImport(ir.Data); Assert.AreEqual(20, impRes.SuccessCount); Assert.AreEqual(0, impRes.ErrorCount); for (int i = 0; i < 20; i++) { Participant p = tg.Model.GetParticipants()[i]; RaceParticipant rp = tg.Model.GetRace(0).GetParticipants()[i]; Assert.AreEqual(string.Format("Name {0}", i + 1), p.Name); Assert.AreEqual(string.Format("Name {0}", i + 1), rp.Name); if (i == 0) { Assert.AreEqual((double)(1), rp.Points); } else if (i == 1) { Assert.AreEqual((double)(2), rp.Points); } else if (i == 2) { Assert.AreEqual((double)(3.3), rp.Points); } else if (i == 3) { Assert.AreEqual((double)(-1), rp.Points); } else { Assert.AreEqual((double)(i + 1), rp.Points); } if (i == 3) { Assert.AreEqual((uint)(0), rp.StartNumber); } else { Assert.AreEqual((uint)(20 - i), rp.StartNumber); } Assert.IsTrue(rp.Participant == p); } }
public void ImportParticpantsForRaceViaZip() { string[] columnShall = { "id", "nachname", "vorname", "geschlecht", "verein", "verbandskürzel", "jg", "punkte", "adr_str", "adr_plz", "adr_ort" }; void checkColumns(List <string> columns) { for (int i = 0; i < columnShall.Length; i++) { Assert.AreEqual(columnShall[i], columns[i]); } } TestDataGenerator tg = new TestDataGenerator(); var ir = new ImportZipReader(@"1557MRBR.zip"); checkColumns(ir.Columns); RaceMapping mapping = new RaceMapping(ir.Columns); RaceImport im = new RaceImport(tg.Model.GetRace(0), mapping); var impRes = im.DoImport(ir.Data); Assert.AreEqual(3, impRes.SuccessCount); Assert.AreEqual(0, impRes.ErrorCount); Assert.AreEqual(3, ir.Data.Tables[0].Rows.Count); for (int i = 0; i < 2; i++) { Participant p = tg.Model.GetParticipants()[i]; RaceParticipant rp = tg.Model.GetRace(0).GetParticipants()[i]; Assert.AreEqual(string.Format("NACHNAME{0}", i + 1), p.Name); Assert.AreEqual(string.Format("Vorname{0}", i + 1), rp.Firstname); Assert.IsTrue(rp.Participant == p); } }
public void ImportRace() { var db = new RaceHorologyLib.Database(); string dbFilename = db.CreateDatabase("new.mdb"); db.Connect(dbFilename); //RaceHorologyLib.IAppDataModelDataBase db = new RaceHorologyLib.DatabaseDummy("./"); AppDataModel dm = new AppDataModel(db); // Create a Race dm.AddRace(new Race.RaceProperties { RaceType = Race.ERaceType.GiantSlalom, Runs = 2 }); ImportResults impRes = new ImportResults(); TimeSpan time = TestUtilities.Time(() => { var ir = new ImportReader(@"Teilnehmer_V1_202001301844.csv"); RaceMapping mapping = new RaceMapping(ir.Columns); RaceImport im = new RaceImport(dm.GetRace(0), mapping); impRes = im.DoImport(ir.Data); }); Assert.AreEqual(153, impRes.SuccessCount); Assert.AreEqual(0, impRes.ErrorCount); Assert.IsTrue(dm.GetParticipants().Count() == 153); Assert.IsTrue(dm.GetRace(0).GetParticipants().Count() == 153); TestContext.WriteLine(string.Format("Import took: {0:0.00} sec", time.TotalSeconds)); Assert.IsTrue(time.TotalSeconds < 4); //db.Close(); }
private void addSelectedItemsToDataModel() { foreach (var item in dgList.SelectedItems) { if (item is DataRowView rowView) { DataRow row = rowView.Row; if (_dm.GetRaces().Count > 0) { foreach (var r in _dm.GetRaces()) { RaceImport imp = new RaceImport(r, _importData.GetMapping(r), new ClassAssignment(_dm.GetParticipantClasses())); RaceParticipant rp = imp.ImportRow(row); } } else { ParticipantImport partImp = new ParticipantImport(_dm.GetParticipants(), _importData.GetMapping(null), _dm.GetParticipantCategories(), new ClassAssignment(_dm.GetParticipantClasses())); partImp.ImportRow(row); } } } }
private void btnImport_Click(object sender, RoutedEventArgs e) { string messageTextDetails = ""; if (lbRaces.SelectedItems.Count > 0) { foreach (var r in lbRaces.SelectedItems) { Race race = r as Race; if (race != null) { RaceImport imp = new RaceImport(race, _importMapping, new ClassAssignment(_dm.GetParticipantClasses())); ImportResults results = imp.DoImport(_importReader.Data); messageTextDetails += string.Format( "Zusammenfassung für das Rennen {0}:\n" + "- Erfolgreich importierte Teilnehmer: {1}\n" + "- Nicht importierte Teilnehmer: {2}\n\n", race.ToString(), results.SuccessCount, results.ErrorCount); } } } else { ParticipantImport imp = new ParticipantImport(_dm.GetParticipants(), _importMapping, _dm.GetParticipantCategories(), new ClassAssignment(_dm.GetParticipantClasses())); ImportResults results = imp.DoImport(_importReader.Data); messageTextDetails += string.Format( "Zusammenfassung für den allgemeinen Teilnehmerimport:\n" + "- Erfolgreich importierte Teilnehmer: {0}\n" + "- Nicht importierte Teilnehmer: {1}\n\n", results.SuccessCount, results.ErrorCount); } MessageBox.Show("Der Importvorgang wurde abgeschlossen: \n\n" + messageTextDetails, "Importvorgang", MessageBoxButton.OK, MessageBoxImage.Information); DialogResult = true; }
public void ImportParticpantsForRace() { TestDataGenerator tg = new TestDataGenerator(); var ir = new ImportReader(@"Teilnehmer_V1_202001301844.csv"); RaceMapping mapping = new RaceMapping(ir.Columns); RaceImport im = new RaceImport(tg.Model.GetRace(0), mapping); var impRes = im.DoImport(ir.Data); Assert.AreEqual(153, impRes.SuccessCount); Assert.AreEqual(0, impRes.ErrorCount); for (int i = 0; i < 153; i++) { Participant p = tg.Model.GetParticipants()[i]; RaceParticipant rp = tg.Model.GetRace(0).GetParticipants()[i]; Assert.AreEqual(string.Format("Name {0}", i + 1), p.Name); Assert.AreEqual(string.Format("Name {0}", i + 1), rp.Name); Assert.IsTrue(rp.Participant == p); } }
public void ImportFISParticipant() { TestDataGenerator tg = new TestDataGenerator(); tg.Model.AddRace(new Race.RaceProperties { RaceType = Race.ERaceType.DownHill, Runs = 1 }); var reader = new FISImportReader(@"FIS-points-list-AL-2022-330.xlsx"); { RaceImport imp = new RaceImport( tg.Model.GetRace(0), reader.GetMapping(tg.Model.GetRace(0)), new ClassAssignment(tg.Model.GetParticipantClasses())); var row = reader.Data.Tables[0].Rows[0]; RaceParticipant rp = imp.ImportRow(row); Assert.AreEqual("10000001", rp.Code); Assert.AreEqual("FERRETTI", rp.Name); Assert.AreEqual("Jacopo", rp.Firstname); Assert.AreEqual(2004U, rp.Year); Assert.AreEqual("SKIING A.S.D.", rp.Club); Assert.AreEqual("ITA", rp.Nation); Assert.AreEqual('M', rp.Sex.Name); Assert.AreEqual(66.48, rp.Points); // GSpoints } { RaceImport imp = new RaceImport( tg.Model.GetRace(1), reader.GetMapping(tg.Model.GetRace(1)), new ClassAssignment(tg.Model.GetParticipantClasses())); var row = reader.Data.Tables[0].Rows[0]; RaceParticipant rp = imp.ImportRow(row); Assert.AreEqual("10000001", rp.Code); Assert.AreEqual("FERRETTI", rp.Name); Assert.AreEqual("Jacopo", rp.Firstname); Assert.AreEqual(2004U, rp.Year); Assert.AreEqual("SKIING A.S.D.", rp.Club); Assert.AreEqual("ITA", rp.Nation); Assert.AreEqual('M', rp.Sex.Name); Assert.AreEqual(145.06, rp.Points); // DHpoints } /////////////////////////////////////////////////////////////////// /// FISUpdatePoints.UpdatePoints /////////////////////////////////////////////////////////////////// tg.Model.GetRace(0).GetParticipants()[0].Points = -1; tg.Model.GetRace(1).GetParticipants()[0].Points = -1; Assert.AreEqual(-1.0, tg.Model.GetRace(0).GetParticipants()[0].Points); // DHpoints Assert.AreEqual(-1.0, tg.Model.GetRace(1).GetParticipants()[0].Points); // DHpoints FISInterfaceModel fisImp = new FISInterfaceModel(tg.Model); fisImp.UpdateFISList(reader); FISUpdatePoints.UpdatePoints(tg.Model, fisImp); Assert.AreEqual(66.48, tg.Model.GetRace(0).GetParticipants()[0].Points); // DHpoints Assert.AreEqual(145.06, tg.Model.GetRace(1).GetParticipants()[0].Points); // DHpoints }