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(); }
public ConversionResult TryConvert(object value, Type sourceType, Type targetType) { var castedValue = TypeHelper.CastTo(value, targetType); return(castedValue); }