示例#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);
            });
        }
        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);
            });
        }
        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();
        }
        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();
        }