コード例 #1
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();
        }
コード例 #2
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();
        }