コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        public void ShouldConvertNullableTypeToValueType()
        {
            // Arrange
            bool?nullableValue = true;
            IConverterRegistry converterRegistry = new ConverterRegistry();

            // Act
            var valueType = converterRegistry.Convert <bool>(nullableValue);

            // Assert
            valueType.Should().Be(nullableValue.Value);
        }
コード例 #12
0
        public void ShouldConvertValueTypeToNullableType()
        {
            // Arrange
            const bool         ValueType         = true;
            IConverterRegistry converterRegistry = new ConverterRegistry();

            // Act
            var nullableValue = converterRegistry.Convert <bool?>(ValueType);

            // Assert
            nullableValue.Should().Be(ValueType);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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");
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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");
        }
コード例 #21
0
        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));
        }
コード例 #22
0
        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");
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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)));
        }
コード例 #26
0
        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");
        }
コード例 #27
0
        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);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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");
        }
コード例 #31
0
        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);
        }
コード例 #32
0
        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));
        }
コード例 #33
0
        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);
        }
コード例 #34
0
        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);
        }
コード例 #35
0
        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");
        }
コード例 #36
0
        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);
        }
コード例 #37
0
        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);
        }
コード例 #38
0
        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);
        }
コード例 #39
0
        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");
        }
コード例 #40
0
        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);
        }
コード例 #41
0
        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");
        }
コード例 #42
0
        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)));
        }
コード例 #43
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);
        }
コード例 #44
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");
        }
コード例 #45
0
        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");
        }
コード例 #46
0
        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);
        }
コード例 #47
0
        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);
        }
コード例 #48
0
        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);
        }