예제 #1
0
        public void ShouldRunAllDefaultCasts()
        {
            IConverterRegistry converterRegistry = new ConverterRegistry();

            CastTestRunner.RunTests((testCase) =>
            {
                // Arrange
                var value = CastTestRunner.GenerateValueForType(testCase.SourceType);
                var generatedTestSuccessful = CastTestRunner.CastValueWithGeneratedCode(value, testCase.SourceType, testCase.TargetType, testCase.CastFlag);

                // Act
                var convertedObject = converterRegistry.TryConvert(
                    sourceType: testCase.SourceType,
                    targetType: testCase.TargetType,
                    value: value,
                    defaultReturnValue: null);

                // Assert
                var castResult   = new CastResult(convertedObject, testCase.CastFlag);
                var isSuccessful = CastTestRunner.AreEqual(
                    this.testOutputHelper,
                    testCase.SourceType,
                    testCase.TargetType,
                    generatedTestSuccessful,
                    castResult,
                    testCase.CastFlag);

                return(isSuccessful);
            });
        }
예제 #2
0
        public void ShouldRunAllCasts()
        {
            CastTestRunner.RunTests(testCase =>
            {
                // Arrange
                var value = CastTestRunner.GenerateValueForType(testCase.SourceType);
                var generatedTestSuccessful = CastTestRunner.CastValueWithGeneratedCode(value, testCase.SourceType, testCase.TargetType, testCase.CastFlag);

                // Act
                var castResult = TypeHelper.CastTo(value, testCase.TargetType);

                // Assert
                var isSuccessful = CastTestRunner.AreEqual(
                    this.testOutputHelper,
                    testCase.SourceType,
                    testCase.TargetType,
                    generatedTestSuccessful,
                    castResult,
                    testCase.CastFlag);

                if (!isSuccessful)
                {
                    Debugger.Launch();
                }

                return(isSuccessful);
            });
        }
예제 #3
0
        public void ShouldSwollowInvalidProgramExceptionWhenNullableDecimalIsCastedToOperators2()
        {
            // Arrange
            var     castFlag = CastFlag.Explicit;
            decimal?value    = 1234m;

            // Act
            var castedValue = CastTestRunner.CastValueWithGeneratedCode(value, typeof(Nullable <decimal>), typeof(Operators2), castFlag);

            // Assert
            castedValue.IsSuccessful.Should().BeTrue();
        }
예제 #4
0
        public void ShouldCastTypeWhichIsSubclassOfAnotherType()
        {
            // Arrange
            var castFlag = CastFlag.Implicit;
            var testCase = new CompilerConversionTestCase(typeof(DerivedOperators), typeof(Operators), castFlag);
            var value    = CastTestRunner.GenerateValueForType(testCase.SourceType);
            var generatedTestSuccessful = CastTestRunner.CastValueWithGeneratedCode(value, testCase.SourceType, testCase.TargetType, castFlag);

            // Act
            var castResult = TypeHelper.CastTo(value, testCase.TargetType);

            // Assert
            var isSuccessful = CastTestRunner.AreEqual(this.testOutputHelper, testCase.SourceType, testCase.TargetType, generatedTestSuccessful, castResult, castFlag);

            isSuccessful.Should().BeTrue();
        }
예제 #5
0
        public void ShouldNotCastTypeWhichImplementsAGenericInterfaceWithNoGenericTypeArgumentsDefined()
        {
            // Arrange
            var castFlag = CastFlag.Implicit;
            var testCase = new CompilerConversionTestCase(typeof(Operators), typeof(IGenericOperators <>), castFlag);
            var value    = CastTestRunner.GenerateValueForType(testCase.SourceType);
            var generatedTestSuccessful = CastTestRunner.CastValueWithGeneratedCode(value, testCase.SourceType, testCase.TargetType, castFlag);

            // Act
            var castResult = TypeHelper.CastTo(value, testCase.TargetType);

            // Assert
            var isSuccessful = CastTestRunner.AreEqual(this.testOutputHelper, testCase.SourceType, testCase.TargetType, generatedTestSuccessful, castResult, castFlag);

            isSuccessful.Should().BeTrue();
        }