public void TestConvertBoolToString() { AttributeType test = new AttributeType("test", typeof(Boolean)); Assert.AreEqual("true", test.Convert(true)); Assert.AreEqual("false", test.Convert(false)); }
public void TestConvertUriToString() { AttributeType test = new AttributeType("test", typeof(Uri)); Uri uri = new Uri("foo", UriKind.Relative); Assert.AreEqual(uri.ToString(), test.Convert(uri)); }
private void TestConvertFromStringScalar <T>(T value) where T : IFormattable { AttributeType test = new AttributeType("test", typeof(T)); object converted = test.Convert(value.ToString(null, CultureInfo.InvariantCulture)); Assert.AreEqual(converted, value); }
private void TestConvertToStringScalar <T>(T value) where T : IFormattable { AttributeType test = new AttributeType("test", typeof(T)); string expected = value.ToString(null, CultureInfo.InvariantCulture); string actual = test.Convert(value); Assert.AreEqual(expected, actual); }
private void TestConvertFromString <T>(T value1, T value2) where T : IFormattable { TestConvertFromStringScalar <T>(value1); AttributeType arrayTest = new AttributeType("test", typeof(T[]), 2); string valueString1 = value1.ToString(null, CultureInfo.InvariantCulture); string valueString2 = value2.ToString(null, CultureInfo.InvariantCulture); object converted = arrayTest.Convert(valueString1 + " " + valueString2); Assert.AreEqual(converted, new T[] { value1, value2 }); }
public void TestConvertRelativeUriContainingSpacesToString() { var test = new AttributeType("test", typeof(Uri)); var baseUri = new Uri("C:\\base\\path"); var relPath = "rel\\path\\with spaces\\in it\\file.txt"; var absUri = new Uri(baseUri, relPath); var relUri = baseUri.MakeRelativeUri(absUri); var uriToString = relUri.ToString(); var uriConverted = test.Convert(relUri); Assert.AreEqual(uriToString, uriConverted); }
public void TestDateTimeConversion() { var test = new AttributeType("test", typeof(DateTime)); var original = new DateTime(2015, 3, 10, 4, 32, 59, DateTimeKind.Local); string written = test.Convert(original); var roundTrip = (DateTime)test.Convert(written); Assert.IsTrue(AreEqual(original, roundTrip)); original = new DateTime(2015, 3, 10, 4, 32, 59, DateTimeKind.Utc); written = test.Convert(original); roundTrip = (DateTime)test.Convert(written); Assert.IsTrue(AreEqual(original, roundTrip)); original = new DateTime(2015, 3, 10, 4, 32, 59, DateTimeKind.Unspecified); written = test.Convert(original); roundTrip = (DateTime)test.Convert(written); Assert.IsTrue(AreEqual(original, roundTrip)); //The following tests the output (DateTime to string) of ATF 3.2 to 3.9, // which used the following code: //result = ((DateTime)value).ToString(@"yyyy-MM-ddTHH:mm:ss.fffffffZ"); // Note the appended 'Z' which is not a custom format specifier character. // The 'Z' indicates UTC time even though the DateTimeobject may not be in // UTC time. original = new DateTime(2015, 3, 10, 16, 32, 00, DateTimeKind.Utc); written = "2015-03-10T16:32:00.0000000Z"; roundTrip = (DateTime)test.Convert(written); Assert.IsTrue(AreEqual(original, roundTrip)); //original = new DateTime(2015, 3, 10, 16, 32, 00, DateTimeKind.Unspecified); //written = "2015-03-10T16:32:00.0000000Z"; //roundTrip = (DateTime)test.Convert(written); //Assert.IsTrue(AreEqual(original, roundTrip)); //original = new DateTime(2015, 3, 10, 16, 32, 00, DateTimeKind.Local); //written = "2015-03-10T16:32:00.0000000Z"; //roundTrip = (DateTime)test.Convert(written); //Assert.IsTrue(AreEqual(original, roundTrip)); }
// Test that arrays of strings are converted to and from the 'object' type correctly. private void TestStringArray(AttributeType stringArrayType) { // Test without spaces, like in ATF 3.1 when spaces were not handled correctly. { string[] array = { "e1", "e2", "e3", "e4" }; string toString = stringArrayType.Convert(array); object toObject = stringArrayType.Convert(toString); Assert.IsTrue(stringArrayType.AreEqual(array, toObject)); } // Test elements that have spaces and quotes ('"') and other special characters. { string[] array = { "first", "second with spaces", "third with \\@##\\\\$#%%!\"~~~ possible escape __ characters\n", "\"fourth\"" }; string toString = stringArrayType.Convert(array); object toObject = stringArrayType.Convert(toString); Assert.IsTrue(stringArrayType.AreEqual(array, toObject)); } // Test that empty strings and null strings are encoded correctly. { string[] array = { "first element", "", "\"", "" }; string toString = stringArrayType.Convert(array); object toObject = stringArrayType.Convert(toString); Assert.IsTrue(stringArrayType.AreEqual(array, toObject)); } }
public void TestConvertBoolArrayToString() { AttributeType test = new AttributeType("test", typeof(Boolean[]), 2); Assert.AreEqual("true false", test.Convert(new Boolean[] { true, false })); }
public void TestConvertStringArrayToString() { AttributeType test = new AttributeType("test", typeof(string[]), 2); Assert.AreEqual("foo bar", test.Convert(new string[] { "foo", "bar" })); }
public void TestConvertStringToString() { AttributeType test = new AttributeType("test", typeof(string)); Assert.AreEqual("foo", test.Convert((object)"foo")); }