public void Parse_ValidStringInEnglishCulture_ReturnsExpectedOutput(string value, double expectedProbability) { // Call double parsedProbability = ProbabilityParsingHelper.Parse(value); // Assert Assert.AreEqual(expectedProbability, parsedProbability); }
public void Parse_ValueTooLargeToStoreInDouble_ThrowsProbabilityParsingException() { // Setup string invalidValue = "1" + double.MaxValue.ToString(CultureInfo.CurrentCulture); // Call TestDelegate call = () => ProbabilityParsingHelper.Parse(invalidValue); // Assert var exception = Assert.Throws <ProbabilityParsingException>(call); Assert.IsInstanceOf <OverflowException>(exception.InnerException); Assert.AreEqual("De waarde is te groot of te klein.", exception.Message); }
public void Parse_ValueDoesNotRepresentProbability_ThrowsProbabilityParsingException() { // Setup const string invalidValue = "I'm not a number!"; // Call TestDelegate call = () => ProbabilityParsingHelper.Parse(invalidValue); // Assert var exception = Assert.Throws <ProbabilityParsingException>(call); Assert.IsInstanceOf <FormatException>(exception.InnerException); Assert.AreEqual("De waarde kon niet geïnterpreteerd worden als een kans.", exception.Message); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var text = value as string; if (text != null) { try { return(ProbabilityParsingHelper.Parse(text)); } catch (ProbabilityParsingException exception) { throw new NotSupportedException(exception.Message, exception); } } return(base.ConvertFrom(context, culture, value)); }
private void ProcessFailureMechanismAssemblyProbabilityTextBox() { FailureMechanismAssemblyResult assemblyResult = FailureMechanism.AssemblyResult; if (!assemblyResult.IsManualProbability()) { return; } try { double probability = ProbabilityParsingHelper.Parse(failureMechanismAssemblyProbabilityTextBox.Text); assemblyResult.ManualFailureMechanismAssemblyProbability = probability; assemblyResult.NotifyObservers(); SetTextBoxValue(probability); } catch (Exception exception) when(exception is ArgumentOutOfRangeException || exception is ProbabilityParsingException) { SetErrorMessage(exception.Message); failureMechanismAssemblyProbabilityTextBox.Focus(); } }