public void ShouldConvertStringToUri() { // Arrange const string InputString = "http://www.superdev.ch/"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, Uri>(() => new StringToUriConverter()); converterRegistry.RegisterConverter<Uri, string>(() => new StringToUriConverter()); // Act var outputUri = converterRegistry.Convert<string, Uri>(InputString); // Assert outputUri.Should().NotBeNull(); outputUri.AbsoluteUri.Should().Be(InputString); }
//------------------------------------------------------------------------------ static public object ConvertUsingTypeConverter(Type destinationType, object value) { if (s_ConverterRegistry == null) { IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <object, bool>(() => new ObjectToBoolConverter()); converterRegistry.RegisterConverter <object, DateTime>(() => new ObjectToDateTimeConverter()); s_ConverterRegistry = converterRegistry; } object result = s_ConverterRegistry.Convert(destinationType, value); return(result); }
public void ShouldConvertStringToUri() { // Arrange const string InputString = "http://www.superdev.ch/"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, Uri>(() => new StringToUriConverter()); converterRegistry.RegisterConverter <Uri, string>(() => new StringToUriConverter()); // Act var outputUri = converterRegistry.Convert <string, Uri>(InputString); // Assert outputUri.Should().NotBeNull(); outputUri.AbsoluteUri.Should().Be(InputString); }
public void ShouldConvertBothWays() { // Arrange const string InputString = "999"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, int>(() => new StringToIntegerConverter()); converterRegistry.RegisterConverter<int, string>(() => new StringToIntegerConverter()); // Act var convertedObject = converterRegistry.Convert<string, int>(InputString); var outputString = converterRegistry.Convert<int, string>(convertedObject); // Assert convertedObject.Should().Be(999); outputString.Should().NotBeNullOrEmpty(); outputString.Should().Be(InputString); }
public void ShouldConvertBothWays() { // Arrange const string InputString = "True"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, bool>(() => new StringToBoolConverter()); converterRegistry.RegisterConverter<bool, string>(() => new StringToBoolConverter()); // Act var convertedObject = converterRegistry.Convert<string, bool>(InputString); var outputString = converterRegistry.Convert<bool, string>(convertedObject); // Assert convertedObject.Should().BeTrue(); outputString.Should().NotBeNullOrEmpty(); outputString.Should().Be(InputString); }
public void ShouldConvertBothWays() { // Arrange const string InputString = "999"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, int>(() => new StringToIntegerConverter()); converterRegistry.RegisterConverter <int, string>(() => new StringToIntegerConverter()); // Act var convertedObject = converterRegistry.Convert <string, int>(InputString); var outputString = converterRegistry.Convert <int, string>(convertedObject); // Assert convertedObject.Should().Be(999); outputString.Should().NotBeNullOrEmpty(); outputString.Should().Be(InputString); }
public void ShouldConvertBothWays() { // Arrange const string InputString = "True"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, bool>(() => new StringToBoolConverter()); converterRegistry.RegisterConverter <bool, string>(() => new StringToBoolConverter()); // Act var convertedObject = converterRegistry.Convert <string, bool>(InputString); var outputString = converterRegistry.Convert <bool, string>(convertedObject); // Assert convertedObject.Should().BeTrue(); outputString.Should().NotBeNullOrEmpty(); outputString.Should().Be(InputString); }
public void ShouldConvertEnumsExplicitly() { // Arrange string inputString = MyEnum.TestValue.ToString(); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, MyEnum>(() => new MyEnumConverter()); converterRegistry.RegisterConverter <MyEnum, string>(() => new MyEnumConverter()); // Act var convertedObject = (MyEnum)converterRegistry.Convert <MyEnum>(inputString); var outputString = converterRegistry.Convert <string>(convertedObject); // Assert convertedObject.Should().NotBeNull(); convertedObject.Should().BeOfType <MyEnum>(); convertedObject.Should().Be(MyEnum.TestValue); outputString.Should().NotBeNull(); outputString.Should().Be(inputString); }
public void ShouldConvertFloatMinValueToString() { // Arrange float inputFloat = float.MinValue; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<float, string>(() => new StringToFloatConverter()); // Act var outputString = converterRegistry.Convert<float, string>(inputFloat); // Assert outputString.Should().Be("-3.40282347E+38"); }
public void ShouldConvertStringToFloatMinValue() { // Arrange const string InputString = "-3.40282347E+38"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, float>(() => new StringToFloatConverter()); // Act var outputFloat = converterRegistry.Convert<string, float>(InputString); // Assert outputFloat.Should().Be(float.MinValue); }
public void ShouldConvertUsingConverterType() { // Arrange const string InputString = "http://www.superdev.ch/"; Type converterType = typeof(StringToUriConverter); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, Uri>(converterType); converterRegistry.RegisterConverter <Uri, string>(converterType); // Act var convertedObject = converterRegistry.Convert <string, Uri>(InputString); var outputString = converterRegistry.Convert <Uri, string>(convertedObject); // Assert convertedObject.Should().NotBeNull(); convertedObject.Should().BeOfType <Uri>(); convertedObject.As <Uri>().AbsoluteUri.Should().Be(InputString); outputString.Should().NotBeNullOrEmpty(); outputString.Should().Be(InputString); }
public void ShouldConvertFormatBStringToGuid() { // Arrange const string InputString = "{1E20D9BB-D64C-4449-AC1B-36CB690601ED}"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, Guid>(() => new StringToGuidConverter()); // Act var outputGuid = converterRegistry.Convert<string, Guid>(InputString); // Assert outputGuid.Should().Be(new Guid(InputString)); }
public void ShouldConvertDoubleMinValueToString() { // Arrange double inputDouble = double.MinValue; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<double, string>(() => new StringToDoubleConverter()); // Act var outputString = converterRegistry.Convert<double, string>(inputDouble); // Assert outputString.Should().Be("-1.7976931348623157E+308"); }
public void ShouldConvertUriToString() { // Arrange var inputUri = new Uri("http://www.superdev.ch/"); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<Uri, string>(() => new StringToUriConverter()); // Act var outputString = converterRegistry.Convert<Uri, string>(inputUri); // Assert outputString.Should().Be(inputUri.AbsoluteUri); }
public void ShouldConvertDateTimeToString_Universal() { // Arrange DateTime intputDateTime = new DateTime(1999, 12, 31, 23, 59, 59, DateTimeKind.Utc); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<DateTime, string>(() => new StringToDateTimeConverter()); // Act var outputString = converterRegistry.Convert<DateTime, string>(intputDateTime); // Assert outputString.Should().Be("1999-12-31T23:59:59.0000000Z"); }
public void ShouldConvertUsingGenericSourceTypeAndNongenericTargetType() { // Arrange const string InputString = "http://www.superdev.ch/"; Type converterType = typeof(StringToUriConverter); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, Uri>(converterType); converterRegistry.RegisterConverter <Uri, string>(converterType); // Act var convertedObject = (Uri)converterRegistry.Convert(typeof(Uri), InputString); var outputString = converterRegistry.Convert(typeof(string), convertedObject); // Assert convertedObject.Should().NotBeNull(); convertedObject.Should().BeOfType <Uri>(); convertedObject.As <Uri>().AbsoluteUri.Should().Be(InputString); outputString.Should().NotBeNull(); outputString.Should().Be(InputString); }
public void ShouldConvertDecimalMinValueToString() { // Arrange decimal inputDecimal = decimal.MinValue; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<decimal, string>(() => new StringToDecimalConverter()); // Act var outputString = converterRegistry.Convert<decimal, string>(inputDecimal); // Assert outputString.Should().Be("-79228162514264337593543950335"); }
public void ShouldConvertDateTimeToString_Local() { // Arrange DateTimeOffset intputDateTime = new DateTimeOffset(new DateTime(1999, 12, 31, 23, 59, 59), new TimeSpan(-7, 0, 0)); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<DateTimeOffset, string>(() => new StringToDateTimeOffsetConverter()); // Act var outputString = converterRegistry.Convert<DateTimeOffset, string>(intputDateTime); // Assert outputString.Should().Be("1999-12-31T23:59:59.0000000-07:00"); }
public void ShouldConvertFormatNStringToGuid() { // Arrange const string InputString = "4568CA6400E742BAAA41E76916DE7118"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, Guid>(() => new StringToGuidConverter()); // Act var outputGuid = converterRegistry.Convert<string, Guid>(InputString); // Assert outputGuid.Should().Be(new Guid(InputString)); }
public void ShouldConvertStringToDateTime_Universal() { // Arrange const string InputString = "1999-12-31T23:59:59.0000000+00:00"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, DateTimeOffset>(() => new StringToDateTimeOffsetConverter()); // Act var outputDateTime = converterRegistry.Convert<string, DateTimeOffset>(InputString); // Assert outputDateTime.Should().Be(new DateTimeOffset(new DateTime(1999, 12, 31, 23, 59, 59, DateTimeKind.Utc))); }
public void ShouldConvertStringToDecimalMinValue() { // Arrange const string InputString = "-79228162514264337593543950335"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, decimal>(() => new StringToDecimalConverter()); // Act var outputDecimal = converterRegistry.Convert<string, decimal>(InputString); // Assert outputDecimal.Should().Be(decimal.MinValue); }
public void ShouldConvertGuidToBFormatString() { // Arrange var inputGuid = new Guid("83EDDA8A-4538-4BA8-8D40-E82C561CD745"); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<Guid,string>(() => new StringToGuidConverter()); // Act var outputString = converterRegistry.Convert<Guid, string>(inputGuid); // Assert outputString.Should().Be("{83edda8a-4538-4ba8-8d40-e82c561cd745}"); }
public void ShouldConvertStringToDoubleMinValue() { // Arrange const string InputString = "-1.7976931348623157E+308"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, double>(() => new StringToDoubleConverter()); // Act var outputDouble = converterRegistry.Convert<string, double>(InputString); // Assert outputDouble.Should().Be(double.MinValue); }
public void ShouldConvertStringToFloatMinValue() { // Arrange const string InputString = "-3.40282347E+38"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, float>(() => new StringToFloatConverter()); // Act var outputFloat = converterRegistry.Convert <string, float>(InputString); // Assert outputFloat.Should().Be(float.MinValue); }
public void ShouldConvertFloatMinValueToString() { // Arrange float inputFloat = float.MinValue; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <float, string>(() => new StringToFloatConverter()); // Act var outputString = converterRegistry.Convert <float, string>(inputFloat); // Assert outputString.Should().Be("-3.40282347E+38"); }
public void ShouldConvertFormatBStringToGuid() { // Arrange const string InputString = "{1E20D9BB-D64C-4449-AC1B-36CB690601ED}"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, Guid>(() => new StringToGuidConverter()); // Act var outputGuid = converterRegistry.Convert <string, Guid>(InputString); // Assert outputGuid.Should().Be(new Guid(InputString)); }
public void ShouldThrowConversionNotSupportedExceptionWhenWrongConversionWayIsConfigured() { // Arrange const string InputString = "http://www.superdev.ch/"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <Uri, string>(() => new StringToUriConverter()); // Act Action action = () => converterRegistry.Convert(typeof(string), typeof(Uri), InputString); // Assert Assert.Throws <ConversionNotSupportedException>(action); }
public void ShouldConvertDecimalMinValueToString() { // Arrange decimal inputDecimal = decimal.MinValue; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <decimal, string>(() => new StringToDecimalConverter()); // Act var outputString = converterRegistry.Convert <decimal, string>(inputDecimal); // Assert outputString.Should().Be("-79228162514264337593543950335"); }
public void ShouldConvertStringToDoubleMinValue() { // Arrange const string InputString = "-1.7976931348623157E+308"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, double>(() => new StringToDoubleConverter()); // Act var outputDouble = converterRegistry.Convert <string, double>(InputString); // Assert outputDouble.Should().Be(double.MinValue); }
public void ShouldConvertDoubleMinValueToString() { // Arrange double inputDouble = double.MinValue; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <double, string>(() => new StringToDoubleConverter()); // Act var outputString = converterRegistry.Convert <double, string>(inputDouble); // Assert outputString.Should().Be("-1.7976931348623157E+308"); }
public void ShouldConvertGuidToBFormatString() { // Arrange var inputGuid = new Guid("83EDDA8A-4538-4BA8-8D40-E82C561CD745"); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <Guid, string>(() => new StringToGuidConverter()); // Act var outputString = converterRegistry.Convert <Guid, string>(inputGuid); // Assert outputString.Should().Be("{83edda8a-4538-4ba8-8d40-e82c561cd745}"); }
public void ShouldConvertFormatNStringToGuid() { // Arrange const string InputString = "4568CA6400E742BAAA41E76916DE7118"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, Guid>(() => new StringToGuidConverter()); // Act var outputGuid = converterRegistry.Convert <string, Guid>(InputString); // Assert outputGuid.Should().Be(new Guid(InputString)); }
public void ShouldConvertStringToDateTime_Local() { // Arrange const string InputString = "1999-12-31T23:59:59.0000000-07:00"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, DateTimeOffset>(() => new StringToDateTimeOffsetConverter()); // Act var outputDateTime = converterRegistry.Convert <string, DateTimeOffset>(InputString); // Assert outputDateTime.Should().Be(new DateTimeOffset(new DateTime(1999, 12, 31, 23, 59, 59), new TimeSpan(-7, 0, 0))); }
public void ShouldConvertDateTimeToString_Local() { // Arrange DateTimeOffset intputDateTime = new DateTimeOffset(new DateTime(1999, 12, 31, 23, 59, 59), new TimeSpan(-7, 0, 0)); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <DateTimeOffset, string>(() => new StringToDateTimeOffsetConverter()); // Act var outputString = converterRegistry.Convert <DateTimeOffset, string>(intputDateTime); // Assert outputString.Should().Be("1999-12-31T23:59:59.0000000-07:00"); }
public void ShouldConvertStringToDecimalMinValue() { // Arrange const string InputString = "-79228162514264337593543950335"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, decimal>(() => new StringToDecimalConverter()); // Act var outputDecimal = converterRegistry.Convert <string, decimal>(InputString); // Assert outputDecimal.Should().Be(decimal.MinValue); }
public void ShouldConvertDateTimeToString_Universal() { // Arrange DateTimeOffset intputDateTime = new DateTimeOffset(new DateTime(1999, 12, 31, 23, 59, 59, DateTimeKind.Utc)); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <DateTimeOffset, string>(() => new StringToDateTimeOffsetConverter()); // Act var outputString = converterRegistry.Convert <DateTimeOffset, string>(intputDateTime); // Assert outputString.Should().Be("1999-12-31T23:59:59.0000000+00:00"); }
public void ShouldConvertUriToString() { // Arrange var inputUri = new Uri("http://www.superdev.ch/"); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <Uri, string>(() => new StringToUriConverter()); // Act var outputString = converterRegistry.Convert <Uri, string>(inputUri); // Assert outputString.Should().Be(inputUri.AbsoluteUri); }
public void ShouldConvertStringToDateTime_Local() { // Arrange const string InputString = "1999-12-31T23:59:59.0000000+01:00"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter<string, DateTime>(() => new StringToDateTimeConverter()); // Act var outputDateTime = converterRegistry.Convert<string, DateTime>(InputString); // Assert outputDateTime.Should().Be(new DateTime(1999, 12, 31, 23, 59, 59, DateTimeKind.Local)); outputDateTime.Kind.Should().Be(DateTimeKind.Local); }
public void ShouldConvertStringToDateTime_Local() { // Arrange const string InputString = "1999-12-31T23:59:59.0000000+01:00"; IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <string, DateTime>(() => new StringToDateTimeConverter()); // Act var outputDateTime = converterRegistry.Convert <string, DateTime>(InputString); // Assert outputDateTime.Should().Be(new DateTime(1999, 12, 31, 23, 59, 59, DateTimeKind.Local)); outputDateTime.Kind.Should().Be(DateTimeKind.Local); }
public void ShouldResetRegistrations() { // Arrange const string InputString = "http://www.thomasgalliker.ch"; int numberOfConvertCalls = 0; IConverterRegistry converterRegistry = new ConverterRegistry(); var converter = new TestConverter(() => { numberOfConvertCalls++; }); converterRegistry.RegisterConverter <string, Uri>(() => converter); // Act var convertedInputStringBeforeReset = converterRegistry.TryConvert <string, Uri>(InputString, null); converterRegistry.Reset(); var convertedInputStringAfterReset = converterRegistry.TryConvert <string, Uri>(InputString, null); // Assert numberOfConvertCalls.Should().Be(1); convertedInputStringBeforeReset.Should().Be(InputString); convertedInputStringAfterReset.Should().BeNull(); }