Ejemplo n.º 1
0
        public void ShouldTryConvertEnumImplicitlyWithNonGenericMethod()
        {
            // Arrange
            object             sourceObject      = MyEnum.TestValue;
            const MyEnum       DefaultValue      = default(MyEnum);
            IConverterRegistry converterRegistry = new ConverterRegistry();

            // Act
            object convertedObject = converterRegistry.TryConvert(typeof(object), typeof(MyEnum), sourceObject, DefaultValue);

            // Assert
            convertedObject.Should().Be(sourceObject);
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        public void ShouldReturnDefaultValueWhenTryConvertToValueTypeFails()
        {
            // Arrange
            TestStruct1 testStruct1 = new TestStruct1 {
                TestString = Guid.NewGuid().ToString()
            };
            IConverterRegistry converterRegistry = new ConverterRegistry();

            // Act
            var convertedObject = converterRegistry.TryConvert <Guid>(testStruct1, default(Guid));

            // Assert
            convertedObject.Should().Be(Guid.Empty);
        }