public void Translator_AffectNext_Import_Test() { // SETUP the SUT List<string> val = new List<string> { "First Value, 1 ,N", "Second Value, 16","Third Item, 1" }; StreamReader testBed = TestHelper.prepareTestDouble(val); NormalItemFactory normalItemFactory = new NormalItemFactory(testBed); ItemParser itemParser = new ItemParser(); itemParser.setFactory(normalItemFactory); List<Item> expected = new List<Item>(); var affectorItem = new ItemValueAffectedNextItemLength() { Name = "First Value", Length = 1, Value = "01" }; var affectedItem = new RegularItem() { Name = "Second Value", Length = 2, Value = "0403" }; affectorItem.setAffectedItem(affectedItem); expected.Add(affectorItem); expected.Add(affectedItem); expected.Add(new RegularItem() { Name = "Third Item", Length = 1, Value = "02" }); // Exercise StringTranslator ST = new StringTranslator(); itemParser.setTranslator(ST); ST.setValue("02040302"); ST.Import(); // Verify TestHelper.Compare(expected, itemParser.Items); }
void currentParserBtn_CheckedChanged(object sender, EventArgs e) { int counter = 0; foreach (RadioButton radioButton in ListOfRadioButton) { if (radioButton.Checked) { ActiveDefinition = ListOfAvailableDefinition[counter]; } counter++; } generateItemInPanel(ActiveDefinition); }
public void Translator_Normal_Export_Test() { List<string> val = new List<string> { "First Value, 1 ,R,03", "Second Value, 1,R,04" }; StreamReader testBed = TestHelper.prepareTestDouble(val); NormalItemFactory normalItemFactory = new NormalItemFactory(testBed); ItemParser itemParser = new ItemParser(); itemParser.setFactory(normalItemFactory); List<Item> expected = new List<Item>(); expected.Add(new RegularItem() { Name = "First Value", Length = 1, Value = "03" }); expected.Add(new RegularItem() { Name = "Second Value", Length = 1, Value = "04" }); TestHelper.Compare(expected, itemParser.Items); // compare the itemTranslator StringTranslator ST = new StringTranslator(); itemParser.setTranslator(ST); ST.Export(); Assert.AreEqual("0304", ST.getValue()); Assert.AreEqual(string.Empty, ST.getValue()); }
public void Translator_AffectNext_Export_Test() { List<string> val = new List<string> { "First Value, 1 ,N,02", "Second Value, 2,R,0403", "Third Item, 1,R, 02" }; StreamReader testBed = TestHelper.prepareTestDouble(val); NormalItemFactory normalItemFactory = new NormalItemFactory(testBed); ItemParser itemParser = new ItemParser(); itemParser.setFactory(normalItemFactory); List<Item> expected = new List<Item>(); var affectorItem = new ItemValueAffectedNextItemLength() { Name = "First Value", Length = 1, Value = "02" }; var affectedItem = new RegularItem() { Name = "Second Value", Length = 2, Value = "0403" }; affectorItem.setAffectedItem(affectedItem); expected.Add(affectorItem); expected.Add(affectedItem); expected.Add(new RegularItem() { Name = "Third Item", Length = 1, Value = "02" }); StringTranslator ST = new StringTranslator(); itemParser.setTranslator(ST); ST.Export(); Assert.AreEqual("02040302", ST.getValue()); Assert.AreEqual(string.Empty, ST.getValue()); }
public void Translator_OtherNotNull_Import_Test() { // SETUP the SUT List<string> val = new List<string> { "First Value, 1 , R,00", "Second Value, 2", "Third Item, 1 , RP ,First Value" }; StreamReader testBed = TestHelper.prepareTestDouble(val); NormalItemFactory normalItemFactory = new NormalItemFactory(testBed); ItemParser itemParser = new ItemParser(); itemParser.setFactory(normalItemFactory); List<Item> expected = new List<Item>(); var item1 = new RegularItem() { Name = "First Value", Length = 1, Value = "02" }; var item2 = new RegularItem() { Name = "Second Value", Length = 2,Value = "0403" }; var item3 = new OtherItemNotNull_Decorator( new RegularItem() { Name = "Third Item", Length = 1,Value= "02" }, item1 ); expected.Add(item1); expected.Add(item2); expected.Add(item3); // Exercise StringTranslator ST = new StringTranslator(); itemParser.setTranslator(ST); ST.setValue("02040302"); ST.Import(); // Verify TestHelper.Compare(expected, itemParser.Items); }
public void Translator_OtherNotNull_Export_Test() { List<string> val = new List<string> { "First Value, 1 ,R,00", "Second Value, 2,R,0403", "Third Item, 1,RP,First Value,02" }; StreamReader testBed = TestHelper.prepareTestDouble(val); NormalItemFactory normalItemFactory = new NormalItemFactory(testBed); ItemParser itemParser = new ItemParser(); itemParser.setFactory(normalItemFactory); List<Item> expected = new List<Item>(); var item1 = new RegularItem() { Name = "First Value", Length = 1, Value = "00" }; var item2 = new RegularItem() { Name = "Second Value", Length = 2, Value = "0403" }; var item3 = new OtherItemNotNull_Decorator( new RegularItem() { Name = "Third Item", Length = 1, Value = "02" }, item1 ); expected.Add(item1); expected.Add(item2); expected.Add(item3); StringTranslator ST = new StringTranslator(); itemParser.setTranslator(ST); ST.Export(); // verify the 00 first value Assert.AreEqual("000403", ST.getValue()); Assert.AreEqual(string.Empty, ST.getValue()); // verify the 02 first value itemParser.Items[0].Value = "02"; ST.Export(); Assert.AreEqual("02040302", ST.getValue()); Assert.AreEqual(string.Empty, ST.getValue()); }
private void ExtractDefinition() { try { string[] DefFiles = System.IO.Directory.GetFiles( System.IO.Directory.GetCurrentDirectory() + "\\ParamDef\\", "*.param"); if (DefFiles.Length > 0) { ListOfAvailableDefinition = new ItemParser[DefFiles.Length]; ListOfRadioButton = new RadioButton[DefFiles.Length]; int count = 0; foreach (string defFile in DefFiles) { RadioButton currentParserBtn = new RadioButton(); currentParserBtn.CheckedChanged += currentParserBtn_CheckedChanged; currentParserBtn.Text = Path.GetFileNameWithoutExtension(defFile); currentParserBtn.Location = new System.Drawing.Point(0, (count * 20)); currentParserBtn.Size = new System.Drawing.Size(400, 17); this.ParserType.Controls.Add(currentParserBtn); ListOfRadioButton[count] = currentParserBtn; ItemParser currentParser = new ItemParser(); currentParser.setFactory(new NormalItemFactory(new StreamReader(defFile))); ListOfAvailableDefinition[count] = currentParser; count++; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void TranslateButton_Click(object sender, EventArgs e) { try { int counter = 0; foreach (RadioButton radioButton in ListOfRadioButton) { if (radioButton.Checked) { ActiveDefinition = ListOfAvailableDefinition[counter]; } counter++; } ActiveDefinition.setTranslator(DefaultStringTranslator); DefaultStringTranslator.setValue(textBox1.Text); DefaultStringTranslator.Import(); counter = 0; foreach (var IT in ActiveDefinition.Items) { ParserLibrary.ItemObject.Item basicForm = IT; if (basicForm is ItemDecorator) { basicForm = (IT as ItemDecorator).getBaseClass(); } if (basicForm is RegularItem) { ListOfTextBox[IT.Name].Text = IT.Value; } if (basicForm is ItemComposite) { CompositeInput CI = (CompositeInput)ListOfTextBox[IT.Name]; CI.SetValue(IT.Value); } counter++; } } catch (Exception ex) { MessageBox.Show(ex.Data.ToString()); } }
private void generateItemInPanel(ItemParser pass) { int counter_Y = 0; int counter_X = 0; int startingOffset_Y = 20; int startingOffset_X = 250; ContainerPanel.Controls.Clear(); //ListOfTextBox.Clear(); List<ParserLibrary.ItemObject.Item> items = pass.Items; //clear up the items inside text box ListOfTextBox = new Dictionary<string, Control>(); //foreach (var item in items) for (int i = 0; i < items.Count; i++) { Point dividerLocation = new Point(); ParserLibrary.ItemObject.Item item = items[i]; if (!item.canBeDisplayed()) { continue; } // Label Label lbl = new Label(); int numOfLines = 0; lbl.Text = GuiHelper.GuiHelper.chopToLines(item.Name, out numOfLines); lbl.Size = new System.Drawing.Size(20, numOfLines * 20); lbl.Location = new System.Drawing.Point((counter_X * 400) + 10, startingOffset_Y); lbl.AutoSize = true; ContainerPanel.Controls.Add(lbl); ParserLibrary.ItemObject.Item basicForm = item; if (basicForm is ItemDecorator) { basicForm = (item as ItemDecorator).getBaseClass(); } // Text box if (basicForm is RegularItem) { TextBox TB = new TextBox(); if (item.Length > 0) { TB.MaxLength = item.Length* 2; TB.Size = new System.Drawing.Size(TB.MaxLength * 9, 23); } else { TB.Size = new System.Drawing.Size(200, 23); } TB.DataBindings.Add("Text", item, "Value"); TB.DataBindings.Add("Name", item, "Name"); TB.Location = new System.Drawing.Point(lbl.Location.X + startingOffset_X, lbl.Location.Y - 5); ContainerPanel.Controls.Add(TB); ListOfTextBox.Add(item.Name,TB); TB.TextAlign = HorizontalAlignment.Left; // setting of the next items offset startingOffset_Y += lbl.Size.Height + 15; dividerLocation = new Point(lbl.Location.X, lbl.Location.Y + lbl.Size.Height + 7); } if (basicForm is ItemComposite) { ItemComposite currentItem = (item as ItemComposite); CompositeInput CI = new CompositeInput(currentItem); CI.Location = new System.Drawing.Point(lbl.Location.X + startingOffset_X, lbl.Location.Y - 5); CI.Size = new System.Drawing.Size(200, currentItem.getItems().Count * 20); ContainerPanel.Controls.Add(CI); ListOfTextBox.Add(item.Name,CI); // setting of the next items offset startingOffset_Y += CI.Size.Height + 15; dividerLocation = new System.Drawing.Point(lbl.Location.X, lbl.Location.Y + CI.Size.Height); } Label Label_HorizontalLine = new Label(); Label_HorizontalLine.Text = ""; Label_HorizontalLine.BorderStyle = BorderStyle.Fixed3D; Label_HorizontalLine.AutoSize = false; Label_HorizontalLine.Height = 2; Label_HorizontalLine.Width = lbl.Location.X + ContainerPanel.Width; Label_HorizontalLine.Location = dividerLocation; ContainerPanel.Controls.Add(Label_HorizontalLine); counter_Y++; } }
public void setParser(ItemParser parser) { this.parser = parser; }