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 ImportParticpants() { TestDataGenerator tg = new TestDataGenerator(); var ir = new ImportReader(@"Teilnehmer_V1_202001301844.csv"); ParticipantMapping mapping = new ParticipantMapping(ir.Columns); List <Participant> participants = new List <Participant>(); ParticipantImport im = new ParticipantImport(participants, mapping, tg.createCategories()); var impRes = im.DoImport(ir.Data); Assert.AreEqual(153, impRes.SuccessCount); Assert.AreEqual(0, impRes.ErrorCount); for (int i = 0; i < 153; i++) { Assert.AreEqual(string.Format("Name {0}", i + 1), participants[i].Name); Assert.IsNull(participants[i].Class); } Assert.AreEqual('W', participants[0].Sex.Name); Assert.AreEqual('W', participants[1].Sex.Name); Assert.AreEqual('M', participants[2].Sex.Name); Assert.AreEqual('M', participants[3].Sex.Name); // Check synonyms Assert.AreEqual('M', participants[4].Sex.Name); //h Assert.AreEqual('M', participants[6].Sex.Name); //H Assert.AreEqual('M', participants[7].Sex.Name); //x Assert.AreEqual('M', participants[10].Sex.Name); //X }
/// <summary> /// Checks an import list against the configured ordering and spacing. /// </summary> /// <param name="holder">The import list container - either a file, or a namespace /// declaration block.</param> /// <param name="highlights">If the import does not meet the configured requirements, /// we allocate a list containing a highlight describing the problem and return /// it via this argument. (We allocate the list on demand to avoid allocations /// in the happy path in which all the import lists are correctly ordered and /// spaced.)</param> private void CheckImports( ICSharpTypeAndNamespaceHolderDeclaration holder, ref List <HighlightingInfo> highlights) { List <UsingDirectiveOrSpace> items = ImportReader.ReadImports(holder); List <UsingDirective> imports; List <List <UsingDirective> > requiredOrderByGroups; ImportInspector.FlattenImportsAndDetermineOrderAndSpacing( _config, items, out imports, out requiredOrderByGroups); bool orderIsCorrect = true; if (requiredOrderByGroups != null) { Relocation nextChange = ImportInspector.GetNextUsingToMove(requiredOrderByGroups, imports); if (nextChange != null) { orderIsCorrect = false; AddHighlight(holder, ref highlights, new UsingOrderHighlighting(holder, _config)); } } // If (and only if) the order is correct, we go on to check the spacing. if (orderIsCorrect) { SpaceChange nextChange = ImportInspector.GetNextSpacingModification(requiredOrderByGroups, items); if (nextChange != null) { AddHighlight(holder, ref highlights, new UsingSpacingHighlighting(holder, _config)); } } }
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); } }
/// <summary> /// Fixes the order of the using directives in a given file or namespace block /// to match the specified configuration. /// </summary> /// <param name="holder">The file or namespace block in which to fix the order /// of using directives (if any are present).</param> /// <param name="configuration">The configuration determining the correct order.</param> public static void FixOrder( ICSharpTypeAndNamespaceHolderDeclaration holder, OrderUsingsConfiguration configuration) { // The reordering proceeds one item at a time, so we just keep reapplying it // until there's nothing left to do. // To avoid hanging VS in the event that an error in the logic causes the // sequence of modifications not to terminate, we ensure we don't try to // apply more changes than there are using directives. int tries = 0; int itemCount = 0; while (tries == 0 || tries <= itemCount) { List <UsingDirectiveOrSpace> items = ImportReader.ReadImports(holder); List <UsingDirective> imports; List <List <UsingDirective> > requiredOrderByGroups; ImportInspector.FlattenImportsAndDetermineOrderAndSpacing( configuration, items, out imports, out requiredOrderByGroups); if (requiredOrderByGroups == null) { break; } itemCount = imports.Count; Relocation nextChange = ImportInspector.GetNextUsingToMove(requiredOrderByGroups, imports); if (nextChange != null) { IUsingDirective toMove = holder.Imports[nextChange.From]; IUsingDirective before = holder.Imports[nextChange.To]; holder.RemoveImport(toMove); holder.AddImportBefore(toMove, before); tries += 1; } else { break; } } }
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(); }
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); } }
/// <summary> /// Fixes the spacing of the using directives in a given file or namespace block /// to match the specified configuration. (The directives must already be in /// the correct order.) /// </summary> /// <param name="holder">The file or namespace block in which to fix the spacing /// of using directives (if any are present).</param> /// <param name="configuration">The configuration determining the correct spacing.</param> public static void FixSpacing( ICSharpTypeAndNamespaceHolderDeclaration holder, OrderUsingsConfiguration configuration) { // The reordering proceeds one item at a time, so we just keep reapplying it // until there's nothing left to do. // To avoid hanging VS in the event that an error in the logic causes the // sequence of modifications not to terminate, we ensure we don't try to // apply more changes than there are either using directives or blank // lines in the usings list. int tries = 0; int itemCount = 0; while (tries == 0 || tries <= itemCount) { List <UsingDirectiveOrSpace> items = ImportReader.ReadImports(holder); if (items == null) { return; } itemCount = items.Count; List <UsingDirective> imports; List <List <UsingDirective> > requiredOrderByGroups; ImportInspector.FlattenImportsAndDetermineOrderAndSpacing( configuration, items, out imports, out requiredOrderByGroups); SpaceChange nextChange = ImportInspector.GetNextSpacingModification(requiredOrderByGroups, items); if (nextChange != null) { IUsingDirective usingBeforeSpace = holder.Imports[nextChange.Index - 1]; if (nextChange.ShouldInsert) { using (WriteLockCookie.Create()) { var newLineText = new StringBuffer("\r\n"); LeafElementBase newLine = TreeElementFactory.CreateLeafElement( CSharpTokenType.NEW_LINE, newLineText, 0, newLineText.Length); LowLevelModificationUtil.AddChildAfter(usingBeforeSpace, newLine); } } else { var syb = usingBeforeSpace.NextSibling; for (; syb != null && !(syb is IUsingDirective); syb = syb.NextSibling) { if (syb.NodeType == CSharpTokenType.NEW_LINE) { LowLevelModificationUtil.DeleteChild(syb); } } } } else { break; } tries += 1; } }
public void DetectColumns() { string[] columnShall = { "FIS-Code-Nr.", "Name", "Vorname", "Verband", "Verein", "Jahrgang", "Geschlecht", "FIS-Distanzpunkte", "FIS-Sprintpunkte", "Startnummer", "Gruppe", "DSV-Id", "Startpass", "Leer", "Nation", "Transponder", "Melder-Name", "Melder-Adresse", "Melder-Telefon", "Melder-Mobil", "Melder-Email", "Nachname Vorname" }; void checkColumns(List <string> columns) { for (int i = 0; i < columnShall.Length; i++) { Assert.AreEqual(columnShall[i], columns[i]); } } { var ir = new ImportReader(@"Teilnehmer_V1_202001301844.xls"); checkColumns(ir.Columns); } { var ir = new ImportReader(@"Teilnehmer_V1_202001301844.xlsx"); checkColumns(ir.Columns); } { var ir = new ImportReader(@"Teilnehmer_V1_202001301844.csv"); checkColumns(ir.Columns); } { var ir = new ImportReader(@"Teilnehmer_V1_202001301844.txt"); checkColumns(ir.Columns); } { var ir = new ImportReader(@"Teilnehmer_V1_202001301844.tsv"); checkColumns(ir.Columns); } { var ir = new ImportReader(@"Teilnehmer_V1_202001301844_comma.csv"); checkColumns(ir.Columns); } }