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 ShouldRegisterMultipleConvertables() { // Arrange const string InputUriString = "http://www.superdev.ch/"; const string InputBoolString = "True"; IConverterRegistry converterRegistry = new ConverterRegistry(); IConvertable[] converters = { new StringToUriConverter(), new StringToBoolConverter() }; converterRegistry.RegisterConverters(converters); // Act var outputUri = converterRegistry.Convert<string, Uri>(InputUriString); var outputUriString = converterRegistry.Convert<Uri, string>(outputUri); var outputBool = converterRegistry.Convert<string, bool>(InputBoolString); var outputBoolString = converterRegistry.Convert<bool, string>(outputBool); // Assert outputUriString.Should().Be(InputUriString); outputBoolString.Should().Be(InputBoolString); }
public void ShouldConvertIfSourceTypeIsEqualToTargetType() { // Arrange const string InputString = "999"; IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var convertedObject = (string)converterRegistry.Convert(typeof(string), typeof(string), InputString); // Assert convertedObject.Should().Be(InputString); }
public void ShouldThrowConversionNotSupportedExceptionWhenTryingToConvertToOpenGenericType() { // Arrange IGenericOperators <string> value = new Operators(); IConverterRegistry converterRegistry = new ConverterRegistry(); // Act Action action = () => converterRegistry.Convert(typeof(IGenericOperators <string>), typeof(IGenericOperators <>), value); // Assert Assert.Throws <ConversionNotSupportedException>(action); }
public void ShouldConvertFromOpenGenericTypeToGenericType() { // Arrange IGenericOperators <string> inputValue = new Operators(); IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var convertedValue = converterRegistry.Convert(typeof(IGenericOperators <>), typeof(IGenericOperators <string>), inputValue); // Assert convertedValue.Should().Be(inputValue); }
public void ShouldRegisterConverterImplicitly() { // Arrange const string InputString = "http://www.superdev.ch/"; var stringToUriConverter = new StringToUriConverter(); IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter(stringToUriConverter); // 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 ShouldConvertDoubleToIntegerExplicitly() { // Arrange const double DoubleValue = 999.99d; IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var convertedValue = converterRegistry.Convert <int>(DoubleValue); // Assert convertedValue.Should().Be((int)DoubleValue); }
public void ShouldConvertULongToDecimalImplicitly() { // Arrange const ulong UlongValue = 999UL; IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var convertedValue = converterRegistry.Convert <decimal>(UlongValue); // Assert convertedValue.Should().Be(Convert.ToDecimal(UlongValue)); }
public void ShouldConvertNullableTypeToValueType() { // Arrange bool?nullableValue = true; IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var valueType = converterRegistry.Convert <bool>(nullableValue); // Assert valueType.Should().Be(nullableValue.Value); }
public void ShouldConvertValueTypeToNullableType() { // Arrange const bool ValueType = true; IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var nullableValue = converterRegistry.Convert <bool?>(ValueType); // Assert nullableValue.Should().Be(ValueType); }
public void ShouldConvertEnumerableToArray() { // Arrange string[] stringArray = { "a", "b", "c" }; IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var convertedList = (IEnumerable <string>)converterRegistry.Convert(typeof(IEnumerable <string>), stringArray); // Assert convertedList.Should().BeEquivalentTo(stringArray); }
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 ShouldThrowConversionNotSupportedExceptionWhenTryingToConvertGenericWithoutValidRegistration() { // Arrange const string InputString = "http://www.superdev.ch/"; IConverterRegistry converterRegistry = new ConverterRegistry(); // Act Action action = () => converterRegistry.Convert <string, Uri>(InputString); // Assert Assert.Throws <ConversionNotSupportedException>(action); }
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 ShouldConvertUsingGenericTargetTypeAndObjectSourceType() { // 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 <Uri>(InputString); var outputString = converterRegistry.Convert <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 ShouldConvertIfSourceTypeEqualsTargetType() { // Arrange var inputUri = new Uri("http://www.superdev.ch/"); IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var outputUri = (Uri)converterRegistry.Convert(typeof(Uri), typeof(Uri), inputUri); // Assert outputUri.Should().NotBeNull(); outputUri.Should().Be(inputUri); }
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 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 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 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 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 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 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 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 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 ShouldConvertUsingChangeType() { // Arrange bool? nullableBool = true; string valueTypeString = nullableBool.ToString(); IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var nullableValue = converterRegistry.Convert <bool?>(valueTypeString); // Assert nullableValue.Should().Be(nullableBool.Value); }
public void ShouldRegisterMultipleConvertables() { // Arrange const string InputUriString = "http://www.superdev.ch/"; const string InputBoolString = "True"; IConverterRegistry converterRegistry = new ConverterRegistry(); IConvertable[] converters = { new StringToUriConverter(), new StringToBoolConverter() }; converterRegistry.RegisterConverters(converters); // Act var outputUri = converterRegistry.Convert <string, Uri>(InputUriString); var outputUriString = converterRegistry.Convert <Uri, string>(outputUri); var outputBool = converterRegistry.Convert <string, bool>(InputBoolString); var outputBoolString = converterRegistry.Convert <bool, string>(outputBool); // Assert outputUriString.Should().Be(InputUriString); outputBoolString.Should().Be(InputBoolString); }
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 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 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 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 ShouldConvertIfTargetTypeIsAssignableFromSourceType() { // Arrange List <string> stringList = new List <string> { "a", "b", "c" }; IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var convertedList = (IEnumerable <string>)converterRegistry.Convert(typeof(IEnumerable <string>), stringList); // Assert convertedList.Should().BeEquivalentTo(stringList); }
public void ShouldConvertUsingStringParse() { // Arrange const string InputString = "http://www.thomasgalliker.ch/"; Uri inputUri = new Uri(InputString); IConverterRegistry converterRegistry = new ConverterRegistry(); // Act var uriAsString = converterRegistry.Convert <Uri, string>(inputUri); // Assert uriAsString.Should().Be(InputString); }
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 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 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 ShouldThrowConversionNotSupportedExceptionWhenTryingToConvertArrayToEnumerable() { // Arrange List <string> stringList = new List <string> { "a", "b", "c" }; IConverterRegistry converterRegistry = new ConverterRegistry(); // Act Action action = () => converterRegistry.Convert(typeof(string[]), stringList); // Assert Assert.Throws <ConversionNotSupportedException>(action); }
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 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 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); }