public void WHEN_Localized_Value_Is_Not_Found_SHOULD_Render_Formatted_Key_Hint() { //Arrange var localisationProvider = LocalizationProviderFactory.CreateKnowsNothing(); var helpers = new HandleBarsHelpers(localisationProvider.Object); Handlebars.RegisterHelper(HandleBarsHelpers.LocalizeTagName, helpers.Localize); string categoryName = GetRandom.String(32); string keyName = GetRandom.String(32); var template = Handlebars.Compile("{{localize CategoryName KeyName}}"); //Act var result = template.Invoke(new { CategoryName = categoryName, KeyName = keyName }); result.Should().Be(String.Format("[{0}.{1}]", categoryName, keyName), "Because this is the formatted key hint"); }
public void WHEN_Using_The_Helper_The_Culture_From_The_UIThread_SHOULD_Be_Used(string expectedCultureName) { //Arrange var localisationProvider = LocalizationProviderFactory.CreateKnowsItAll(); var helpers = new HandleBarsHelpers(localisationProvider.Object); Handlebars.RegisterHelper(HandleBarsHelpers.LocalizeTagName, helpers.Localize); string categoryName = GetRandom.String(32); string keyName = GetRandom.String(32); var template = Handlebars.Compile("{{localize CategoryName KeyName}}"); //Act Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(expectedCultureName); var result = template.Invoke(new { CategoryName = categoryName, KeyName = keyName }); //Assert result.Should().Be(String.Format("{0}:{1}.{2}", expectedCultureName, categoryName, keyName), "Because no better solution was available at this time"); }
public void WHEN_Localized_Value_Is_Found_SHOULD_Render_LocalizedValue() { //Arrange var localisationProvider = LocalizationProviderFactory.CreateKnowsItAll(); var helpers = new HandleBarsHelpers(localisationProvider.Object); Handlebars.RegisterHelper(HandleBarsHelpers.LocalizeTagName, helpers.Localize); string cultureName = "en-CA"; string categoryName = GetRandom.String(32); string keyName = GetRandom.String(32); var template = Handlebars.Compile("{{localize CategoryName KeyName}}"); //Act Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(cultureName); var result = template.Invoke(new { CategoryName = categoryName, KeyName = keyName }); result.Should().Be(String.Format("{0}:{1}.{2}", cultureName, categoryName, keyName), "Because this is the mocked value"); }
public void WHEN_Called_With_Variables_SHOULD_Render_Same_As_With_Literals() { //Arrange var localisationProvider = LocalizationProviderFactory.CreateKnowsItAll(); var helpers = new HandleBarsHelpers(localisationProvider.Object); Handlebars.RegisterHelper(HandleBarsHelpers.LocalizeTagName, helpers.Localize); string categoryName = GetRandom.String(32); string keyName = GetRandom.String(32); var templateVariables = Handlebars.Compile("{{localize CategoryName KeyName}}"); var templateLiteral = Handlebars.Compile("{{localize '" + categoryName + "' '" + keyName + "'}}"); //Act var resultFromVariables = templateVariables.Invoke(new { CategoryName = categoryName, KeyName = keyName }); var resultFromLiteral = templateLiteral.Invoke(null); //Assert resultFromVariables.Should().BeEquivalentTo(resultFromLiteral); }
/// <summary> /// Constructor to instantiate a new Custom Tab Page /// </summary> public CustomTabPage(string classification, string notes, Dictionary <string, VDW_DataObjectMappingList> itemList) { // Register the Handlebars helpers (extensions), these are maintained in the DataWarehouseAutomation class library. HandleBarsHelpers.RegisterHandleBarsHelpers(); this.ItemList = itemList; _inputNiceName = Regex.Replace(classification, "(\\B[A-Z])", " $1"); DisplayJsonFlag = true; GenerateInDatabaseFlag = true; SaveOutputFileFlag = true; #region Main Tab Page // Base properties of the custom tab page Name = $"{classification}"; Text = _inputNiceName; BackColor = Color.Transparent; BorderStyle = BorderStyle.None; UseVisualStyleBackColor = true; Size = new Size(1330, 601); AutoSizeMode = AutoSizeMode.GrowOnly; AutoSize = true; // Add Panel to facilitate docking var localPanel = new Panel(); Controls.Add(localPanel); localPanel.Dock = DockStyle.Fill; localPanel.AutoSize = true; // Add 'Generate' Button var localButtonGenerate = new Button(); localPanel.Controls.Add(localButtonGenerate); localButtonGenerate.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left); localButtonGenerate.Location = new Point(17, 542); localButtonGenerate.Name = $"Generate{classification}"; localButtonGenerate.Size = new Size(170, 40); localButtonGenerate.Text = $"Generate {_inputNiceName}"; localButtonGenerate.Click += new EventHandler(Generate); // Add 'Processing' Label var localLabelProcessing = new Label(); localPanel.Controls.Add(localLabelProcessing); localLabelProcessing.Anchor = (AnchorStyles.Top | AnchorStyles.Left); localLabelProcessing.Location = new Point(14, 12); localLabelProcessing.Size = new Size(280, 13); localLabelProcessing.Name = $"label{classification}Processing"; localLabelProcessing.Text = $"{_inputNiceName} Processing"; // Add 'Select All' CheckBox _localCheckBoxSelectAll = new CheckBox(); localPanel.Controls.Add(_localCheckBoxSelectAll); _localCheckBoxSelectAll.Anchor = (AnchorStyles.Top | AnchorStyles.Left); _localCheckBoxSelectAll.Location = new Point(346, 11); _localCheckBoxSelectAll.Size = new Size(69, 17); _localCheckBoxSelectAll.Name = "checkBoxSelectAll"; _localCheckBoxSelectAll.Checked = true; _localCheckBoxSelectAll.Text = "Select all"; _localCheckBoxSelectAll.CheckedChanged += new EventHandler(SelectAllCheckBoxItems); // Add Checked List Box _localCheckedListBox = new CheckedListBox(); localPanel.Controls.Add(_localCheckedListBox); _localCheckedListBox.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left); _localCheckedListBox.Location = new Point(17, 31); _localCheckedListBox.Size = new Size(393, 377); _localCheckedListBox.BorderStyle = BorderStyle.FixedSingle; _localCheckedListBox.CheckOnClick = true; _localCheckedListBox.Name = $"checkedListBox{classification}"; // Add User feedback RichTextBox (left hand side of form) _localRichTextBox = new RichTextBox(); localPanel.Controls.Add(_localRichTextBox); _localRichTextBox.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left); _localRichTextBox.Location = new Point(17, 402); _localRichTextBox.Size = new Size(393, 120); _localRichTextBox.BorderStyle = BorderStyle.None; _localRichTextBox.BackColor = SystemColors.Window; _localRichTextBox.TextChanged += new EventHandler(ScrollToCaret); // Add 'Filter' Group Box var localGroupBoxFilter = new GroupBox(); localPanel.Controls.Add(localGroupBoxFilter); localGroupBoxFilter.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left); localGroupBoxFilter.Location = new Point(247, 539); localGroupBoxFilter.Size = new Size(163, 43); localGroupBoxFilter.Text = "Filter Criterion"; localGroupBoxFilter.Name = $"groupBoxFilter{_inputNiceName}"; // Add 'Filter' Text Box _localTextBoxFilter = new TextBox(); localGroupBoxFilter.Controls.Add(_localTextBoxFilter); _localTextBoxFilter.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left); _localTextBoxFilter.Location = new Point(6, 15); _localTextBoxFilter.Size = new Size(151, 20); _localTextBoxFilter.Name = $"textBoxFilterCriterion{_inputNiceName}"; _localTextBoxFilter.TextChanged += new EventHandler(FilterItemList); #endregion #region Sub Tab Pages // Add Sub Tab Control localTabControl = new TabControl(); localPanel.Controls.Add(localTabControl); localTabControl.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right); localTabControl.Location = new Point(416, 9); localTabControl.Size = new Size(896, 573); localTabControl.Name = $"tabControl{classification}"; localTabControl.BackColor = Color.White; //localTabControl.SelectedIndexChanged += new EventHandler(SyntaxHighlightsHandlebars); localTabControl.SelectedIndexChanged += new EventHandler(SubTabClick); // Add 'Generation Output' Tab Page on Sub Tab tabPageGenerationOutput = new TabPage($"{_inputNiceName} Generation Output"); localTabControl.TabPages.Add(tabPageGenerationOutput); tabPageGenerationOutput.BackColor = Color.Transparent; tabPageGenerationOutput.Name = $"{_inputNiceName} Generation Output"; tabPageGenerationOutput.BorderStyle = BorderStyle.None; tabPageGenerationOutput.UseVisualStyleBackColor = true; // Add 'Generation Output' RichTextBox to Generation Output tab localRichTextBoxGenerationOutput = new RichTextBox(); tabPageGenerationOutput.Controls.Add(localRichTextBoxGenerationOutput); localRichTextBoxGenerationOutput.Dock = DockStyle.Fill; localRichTextBoxGenerationOutput.Text = $"No {_inputNiceName} logic has been generated at the moment."; localRichTextBoxGenerationOutput.Location = new Point(3, 6); localRichTextBoxGenerationOutput.Size = new Size(882, 535); localRichTextBoxGenerationOutput.BorderStyle = BorderStyle.None; // Add 'Pattern' Tab Page to on Sub Tab tabPageGenerationPattern = new TabPage($"{_inputNiceName} Pattern"); localTabControl.TabPages.Add(tabPageGenerationPattern); tabPageGenerationPattern.BackColor = Color.Transparent; tabPageGenerationPattern.Name = $"{_inputNiceName} Pattern"; tabPageGenerationPattern.BorderStyle = BorderStyle.None; tabPageGenerationPattern.UseVisualStyleBackColor = true; // Add 'Pattern ComboBox' to Pattern tab localComboBoxGenerationPattern = new ComboBox(); tabPageGenerationPattern.Controls.Add(localComboBoxGenerationPattern); localComboBoxGenerationPattern.Anchor = (AnchorStyles.Top | AnchorStyles.Left); localComboBoxGenerationPattern.Location = new Point(108, 8); localComboBoxGenerationPattern.Size = new Size(496, 21); localComboBoxGenerationPattern.Name = $"comboBox{classification}Pattern"; localComboBoxGenerationPattern.SelectedIndexChanged += new EventHandler(DisplayPattern); // Add 'Active Pattern' Label localLabelActivePattern = new Label(); tabPageGenerationPattern.Controls.Add(localLabelActivePattern); localLabelActivePattern.Anchor = (AnchorStyles.Top | AnchorStyles.Left); localLabelActivePattern.Location = new Point(2, 11); localLabelActivePattern.Size = new Size(77, 13); localLabelActivePattern.Name = $"label{classification}ActivePattern"; localLabelActivePattern.Text = "Active Pattern:"; // Add 'File Path' Label localLabelFilePath = new Label(); tabPageGenerationPattern.Controls.Add(localLabelFilePath); localLabelFilePath.Anchor = (AnchorStyles.Top | AnchorStyles.Left); localLabelFilePath.Location = new Point(2, 34); localLabelFilePath.Size = new Size(60, 13); localLabelFilePath.Name = $"label{classification}FilePath"; localLabelFilePath.Text = @"File Path:"; // Add 'Full Path' Label localLabelFullFilePath = new Label(); tabPageGenerationPattern.Controls.Add(localLabelFullFilePath); localLabelFullFilePath.Anchor = (AnchorStyles.Top | AnchorStyles.Left); localLabelFullFilePath.Location = new Point(105, 34); localLabelFullFilePath.Size = new Size(750, 13); localLabelFullFilePath.Name = $"label{classification}FullFilePath"; localLabelFullFilePath.Text = @"<path>"; // Add 'Active Connection Key' Label localLabelActiveConnectionKey = new Label(); tabPageGenerationPattern.Controls.Add(localLabelActiveConnectionKey); localLabelActiveConnectionKey.Anchor = (AnchorStyles.Top | AnchorStyles.Left); localLabelActiveConnectionKey.Location = new Point(2, 57); localLabelActiveConnectionKey.Size = new Size(100, 13); localLabelActiveConnectionKey.Name = $"label{classification}ConnectionKey"; localLabelActiveConnectionKey.Text = @"Connection Key:"; // Add 'Active Connection Key Value' Label localLabelActiveConnectionKeyValue = new Label(); tabPageGenerationPattern.Controls.Add(localLabelActiveConnectionKeyValue); localLabelActiveConnectionKeyValue.Anchor = (AnchorStyles.Top | AnchorStyles.Left); localLabelActiveConnectionKeyValue.Location = new Point(105, 57); localLabelActiveConnectionKeyValue.Size = new Size(650, 13); localLabelActiveConnectionKeyValue.Name = $"label{classification}ConnectionKeyValue"; localLabelActiveConnectionKeyValue.Text = @"<connection key>"; // Add 'Save Pattern' Button localSavePattern = new Button(); tabPageGenerationPattern.Controls.Add(localSavePattern); localSavePattern.Anchor = (AnchorStyles.Top | AnchorStyles.Left); localSavePattern.Location = new Point(610, 7); localSavePattern.Size = new Size(101, 23); localSavePattern.Text = $"Save updates"; localSavePattern.Name = $"Save{classification}"; localSavePattern.Click += (SavePattern); // Add 'Generation Pattern' RichTextBox to Pattern tab localRichTextBoxGenerationPattern = new RichTextBox(); tabPageGenerationPattern.Controls.Add(localRichTextBoxGenerationPattern); localRichTextBoxGenerationPattern.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right); localRichTextBoxGenerationPattern.Location = new Point(3, 82); localRichTextBoxGenerationPattern.Size = new Size(195, 30); localRichTextBoxGenerationPattern.BorderStyle = BorderStyle.None; localRichTextBoxGenerationPattern.TextChanged += new EventHandler(CommitPatternToMemory); #endregion #region Constructor Methods // Populate the Combo Box LoadTabPageComboBox(classification); // Populate the Checked List Box SetItemList(itemList); // Report back to the user if there is not metadata available if (itemList == null || itemList.Count == 0) { _localRichTextBox.Text = $"There was no metadata available to display {_inputNiceName} content. Please check the associated metadata schema (are there any {_inputNiceName} records available?) or the database connection.\r\n\r\n"; } // Initial documentation as per the definition notes if (notes != null) { _localRichTextBox.AppendText(notes); } // Set the tab pages back to what they were before reload var currentSubTab = FormBase.VdwConfigurationSettings.SelectedSubTab; if (currentSubTab != null) { var localTabPage = localTabControl.TabPages[currentSubTab]; if (localTabPage != null) // The control we're looking for has to exist, otherwise no need to continue { if (localTabControl.TabPages.Contains(localTabControl.TabPages[currentSubTab])) { localTabControl.SelectTab(localTabControl.TabPages[currentSubTab]); try { localTabControl.SelectedTab.Controls[7].Text = FormBase.VdwConfigurationSettings.SelectedPatternText; } catch { // Do nothing } ApplySyntaxHighlightingForHandlebars(); } } } // Prevention of double hitting of some event handlers StartUpIndicator = false; #endregion }