コード例 #1
0
        public void ShouldBindIfFullyBoundOrErrorIfNot(Type targetType, Type testType, Type implementingType = null)
        {
            // similar test to above, but this checks the interaction between SupportsType and Bind -
            // in that some types are supported, but, when bound, will yield an exception because the mapping
            // cannot be fully bound.
            Output.WriteLine($"Testing target bound for type { targetType } supports { implementingType ?? testType }...");

            // Arrange
            var target  = new GenericConstructorTarget(targetType);
            var mapping = target.MapType(testType);

            // Assert (with some 'Act' thrown in too :$)
            Assert.True(mapping.Success);

            var context = GetCompileContext(target, targetType: testType);

            if (mapping.IsFullyBound)
            {
                var boundTarget = target.Bind(context);
                Assert.NotNull(boundTarget);
            }
            else
            {
                //not specifying the type of exception we want - only that it should throw one.
                Assert.ThrowsAny <Exception>(() => target.Bind(context));
            }
        }
コード例 #2
0
        public void ShouldMapMultipleParametersThroughNonGenericBase()
        {
            var target = new GenericConstructorTarget(typeof(DoubleGeneric <,>));

            var result = target.MapType(typeof(ISingleGeneric <IDoubleGeneric <int, float> >));

            Assert.True(result.Success);
            Assert.True(result.IsFullyBound);

            Assert.Equal(typeof(DoubleGeneric <int, float>), result.Type);
        }
コード例 #3
0
        public void ShouldSupportTypeIfMappingIsSuccessful(Type targetType, Type testType, Type implementingType = null)
        {
            Output.WriteLine($"Testing target for type { targetType } supports { testType }...");
            // Arrange
            var target = new GenericConstructorTarget(targetType);

            // Act
            var mapping = target.MapType(testType);

            // Assert
            Assert.True(mapping.Success);
            Assert.Equal(implementingType ?? testType, mapping.Type);
            Assert.True(target.SupportsType(testType));
        }