public void ErrorProvider_GetIconPadding_InvokeWithoutError_ReturnsZero() { var provider = new ErrorProvider(); var control = new Control(); Assert.Equal(0, provider.GetIconPadding(control)); // Call again. Assert.Equal(0, provider.GetIconPadding(control)); }
public void ErrorProvider_SetIconPadding_Invoke_GetIconPaddingReturnsExpected(int value) { var provider = new ErrorProvider(); var control = new Control(); provider.SetIconPadding(control, value); Assert.Equal(value, provider.GetIconPadding(control)); // Call again. provider.SetIconPadding(control, value); Assert.Equal(value, provider.GetIconPadding(control)); }
public void GivenFormWithAssemblyResultPerSectionView_WithOrWithoutErrorSetAndObserverNotified_ThenWarningSetWithPadding(bool withError, int expectedPadding) { // Given AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults( new Random(21).NextEnumValue <AssessmentSectionComposition>()); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; AssessmentSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator; calculator.ThrowExceptionOnCalculate = withError; using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection)) { // Precondition ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); Button button = buttonTester.Properties; Assert.IsFalse(button.Enabled); ErrorProvider errorProvider = GetErrorProvider(view); Assert.AreEqual(withError, !string.IsNullOrEmpty(errorProvider.GetError(button))); ErrorProvider warningProvider = GetWarningProvider(view); Assert.IsEmpty(warningProvider.GetError(button)); // When assessmentSection.NotifyObservers(); // Then Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button)); Assert.AreEqual(expectedPadding, warningProvider.GetIconPadding(button)); } } }
public void GetandSetIconPaddingTest() { Form myForm = new Form(); myForm.ShowInTaskbar = false; ErrorProvider myErrorProvider = new ErrorProvider(); myErrorProvider.SetIconPadding(myForm, 2); Assert.AreEqual(2, myErrorProvider.GetIconPadding(myForm), "#getset3"); myForm.Dispose(); }
public void Constructor_WithAssessmentSection_ExpectedValues() { // Setup var random = new Random(21); var assessmentSection = new AssessmentSection(random.NextEnumValue <AssessmentSectionComposition>()); // Call using (var view = new AssemblyResultTotalView(assessmentSection)) { testForm.Controls.Add(view); testForm.Show(); // Assert Assert.AreEqual(4, view.Controls.Count); Button button = GetRefreshAssemblyResultButtonTester().Properties; Assert.AreEqual("Resultaten verversen", button.Text); Assert.IsFalse(button.Enabled); var assemblyResultControl = (AssessmentSectionAssemblyResultControl) new ControlTester("assessmentSectionAssemblyControl").TheObject; Assert.AreEqual(DockStyle.Top, assemblyResultControl.Dock); var label = (Label) new ControlTester("label").TheObject; Assert.AreEqual("Samenvatting resultaten per faalmechanisme:", label.Text); var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl").TheObject; Assert.AreEqual(DockStyle.Fill, dataGridViewControl.Dock); ErrorProvider warningProvider = GetWarningProvider(view); TestHelper.AssertImagesAreEqual(CoreGuiResources.warning.ToBitmap(), warningProvider.Icon.ToBitmap()); Assert.AreEqual(ErrorBlinkStyle.NeverBlink, warningProvider.BlinkStyle); Assert.IsEmpty(warningProvider.GetError(button)); Assert.AreEqual(4, warningProvider.GetIconPadding(button)); Assert.IsInstanceOf <IView>(view); Assert.IsInstanceOf <UserControl>(view); Assert.IsNull(view.Data); Assert.AreEqual(new Size(350, 250), view.AutoScrollMinSize); Assert.AreSame(assessmentSection, view.AssessmentSection); } }
public void Constructor_WithAssessmentSection_ExpectedValues() { // Setup AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults( new Random(21).NextEnumValue <AssessmentSectionComposition>()); // Call using (new AssemblyToolCalculatorFactoryConfig()) using (var view = new AssemblyResultPerSectionView(assessmentSection)) { testForm.Controls.Add(view); testForm.Show(); // Assert Assert.AreEqual(2, view.Controls.Count); var button = (Button)GetRefreshAssemblyResultButtonTester().TheObject; Assert.AreEqual("Resultaten verversen", button.Text); Assert.IsFalse(button.Enabled); ErrorProvider errorProvider = GetErrorProvider(view); TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ErrorIcon.ToBitmap(), errorProvider.Icon.ToBitmap()); Assert.AreEqual(ErrorBlinkStyle.NeverBlink, errorProvider.BlinkStyle); Assert.IsEmpty(errorProvider.GetError(button)); Assert.AreEqual(4, errorProvider.GetIconPadding(button)); ErrorProvider warningProvider = GetWarningProvider(view); TestHelper.AssertImagesAreEqual(CoreGuiResources.warning.ToBitmap(), warningProvider.Icon.ToBitmap()); Assert.AreEqual(ErrorBlinkStyle.NeverBlink, warningProvider.BlinkStyle); Assert.IsEmpty(warningProvider.GetError(button)); Assert.AreEqual(4, warningProvider.GetIconPadding(button)); Assert.IsInstanceOf <IView>(view); Assert.IsInstanceOf <UserControl>(view); Assert.IsNull(view.Data); Assert.AreEqual(new Size(300, 250), view.AutoScrollMinSize); Assert.AreSame(assessmentSection, view.AssessmentSection); } }
public void ErrorProvider_GetIconPadding_NullControl_ThrowsArgumentNullException() { var provider = new ErrorProvider(); Assert.Throws <ArgumentNullException>("control", () => provider.GetIconPadding(null)); }
public Control Add <T> (string label, T value, Action <T> save, Func <T, bool> validate = null, string invalidMessage = "Invalid value") { var row = ++layout.RowCount; var ctrl = ControlFactory.CreateControl(value); var lbl = ControlFactory.CreateLabel(label); lbl.Click += (o, e) => ctrl.Focus(); layout.Controls.Add(lbl, 0, row); layout.Controls.Add(ctrl, 1, row); showErrors.SetIconPadding(ctrl, 3); ctrl.Margin = new Padding(0, 0, showErrors.Icon.Width + showErrors.GetIconPadding(ctrl) * 2, 0); ctrl.Dock = DockStyle.Fill; Func <object, T> getValue = obj => (T)Convert.ChangeType(obj, typeof(T)); if (ctrl.GetType() == typeof(ComboBox)) { getValue = obj => (T)Enum.Parse(typeof(T), obj.ToString()); } Action <object, bool> validateAndSave = (newValue, saveValue) => { var isValid = validate == null || validate(getValue(newValue)); showErrors.SetError(ctrl, isValid ? string.Empty : invalidMessage); if (saveValue) { save(getValue(newValue)); } }; Action <bool> valueUpdated = (saveValue) => { if (ctrl.GetType() == typeof(TextBox)) { validateAndSave(((TextBox)ctrl).Text, saveValue); } else if (ctrl.GetType() == typeof(NumericUpDown)) { validateAndSave(((NumericUpDown)ctrl).Value, saveValue); } else if (ctrl.GetType() == typeof(CheckBox)) { validateAndSave(((CheckBox)ctrl).Checked, saveValue); } else if (ctrl.GetType() == typeof(ComboBox)) { validateAndSave(((ComboBox)ctrl).SelectedItem, saveValue); } else if (ctrl.GetType() == typeof(DateTimePicker)) { validateAndSave(((DateTimePicker)ctrl).Value, saveValue); } }; if (validate != null) { Action <object, EventArgs> checkEvent = (o, e) => valueUpdated(false); EventHandler handler = checkEvent.Invoke; ctrl.LostFocus += handler; if (ctrl.GetType() == typeof(TextBox)) { ((TextBox)ctrl).TextChanged += handler; } else if (ctrl.GetType() == typeof(NumericUpDown)) { ((NumericUpDown)ctrl).ValueChanged += handler; } else if (ctrl.GetType() == typeof(CheckBox)) { ((CheckBox)ctrl).CheckedChanged += handler; } else if (ctrl.GetType() == typeof(ComboBox)) { ((ComboBox)ctrl).SelectedIndexChanged += handler; } else if (ctrl.GetType() == typeof(DateTimePicker)) { ((DateTimePicker)ctrl).ValueChanged += handler; } valueUpdated(false); } ctrl.Tag = valueUpdated; return(ctrl); }