public void CanAssignDoubleInDeCulture() { string parameterName = "p1Dbl"; const double doubleValue = 0.123d; const string stringValueInvariant = "0.123"; Type dataType = typeof(double); var testParameterValue = new ScalarTestParameterValue(parameterName, dataType); string stringValueDe = null; CultureInfoUtils.ExecuteUsing("de-DE", () => { stringValueDe = doubleValue.ToString( CultureInfo.CreateSpecificCulture("DE-de")); testParameterValue.StringValue = stringValueDe; }); Assert.AreEqual(stringValueInvariant, testParameterValue.PersistedStringValue); testParameterValue.SetValue(doubleValue); Assert.AreEqual(stringValueInvariant, testParameterValue.PersistedStringValue); CultureInfoUtils.ExecuteUsing("de-DE", () => { Assert.AreEqual(stringValueDe, testParameterValue.GetDisplayValue()); }); }
public void CanClone() { string parameterName = "p1Name"; const string stringValueInvariant = "0.123"; Type dataType = typeof(double); var testParameterValue = new ScalarTestParameterValue(parameterName, dataType); testParameterValue.SetStringValue(0.123d.ToString(CultureInfo.CurrentCulture)); ScalarTestParameterValue clone = (ScalarTestParameterValue)testParameterValue.Clone(); Assert.IsTrue(testParameterValue.Equals(clone)); Assert.IsTrue(testParameterValue.DataType == clone.DataType); Assert.AreEqual(parameterName, clone.TestParameterName); Assert.AreEqual(dataType, clone.DataType); Assert.AreEqual(stringValueInvariant, clone.StringValue); }
private static void EnsureDisplayValue(Type dataType, string stringValueCurrentCulture) { const string parameterName = "Test"; var testParameterValue = new ScalarTestParameterValue(parameterName, dataType); testParameterValue.SetStringValue(stringValueCurrentCulture); string valueWithKnownDatatype = testParameterValue.GetDisplayValue(); Assert.AreEqual(stringValueCurrentCulture, valueWithKnownDatatype); object value = testParameterValue.GetValue(); Assert.NotNull(value); string persistedValue = testParameterValue.PersistedStringValue; testParameterValue.DataType = null; string valueWithGuessedDatatype = testParameterValue.GetDisplayValue(); Assert.AreEqual(stringValueCurrentCulture, valueWithGuessedDatatype); // Now set the same value using InvariantCulture and try again: testParameterValue = new ScalarTestParameterValue(parameterName, dataType); testParameterValue.SetStringValue(persistedValue, CultureInfo.InvariantCulture); valueWithKnownDatatype = testParameterValue.GetDisplayValue(); Assert.AreEqual(stringValueCurrentCulture, valueWithKnownDatatype); testParameterValue.DataType = null; valueWithGuessedDatatype = testParameterValue.GetDisplayValue(); Assert.AreEqual(stringValueCurrentCulture, valueWithGuessedDatatype); }
private static void AddScalarParameterValue(QualityCondition qualityCondition, [NotNull] string parameterName, [CanBeNull] object value) { Assert.ArgumentNotNullOrEmpty(parameterName, nameof(parameterName)); TestFactory factory = TestFactoryUtils.GetTestFactory(qualityCondition.TestDescriptor); TestParameter parameter = Assert.NotNull(factory).GetParameter(parameterName); if (!parameter.IsConstructorParameter && parameter.Type.IsValueType && (value == null || value as string == string.Empty)) { return; } var parameterValue = new ScalarTestParameterValue(parameter, value); parameterValue.DataType = parameter.Type; qualityCondition.AddParameterValue(parameterValue); }