Пример #1
0
        public void EnsureTryApplyIsFalseForNonMatchingInvocationFunc()
        {
            // Given
            var type                = typeof(IFooFuncValueTypeParameterRef <int>);
            var methodName          = nameof(IFooFuncValueTypeParameterRef <int> .MethodWithOneParameter);
            var signature           = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName);
            var refParameterFeature = new ParameterRef(signature, new object?[] { 13 });
            var invocation          = new Invocation(signature, refParameterFeature);
            var arrangment          = new RefParameterArrangement <int>(signature, "WrongParameterName", 42);

            // When
            var wasApplied = arrangment.TryApplyTo(invocation);

            // Then
            Assert.False(wasApplied);
            Assert.True(invocation.HasFeature <IParameterRef>());
            var feature = invocation.GetFeature <IParameterRef>();

            Assert.Single(feature.RefParameterCollection);
            var parameter = feature.RefParameterCollection.Single();

            Assert.Equal("first", parameter.Name);
            Assert.Equal(typeof(int), parameter.Type);
            Assert.Equal(13, parameter.Value);
        }
Пример #2
0
        public void TryApplyReferenceTypeRefParameterArrangementFunc()
        {
            // Given
            var expectedValue       = new object();
            var type                = typeof(IFooFuncReferenceTypeParameterRef <object>);
            var methodName          = nameof(IFooFuncReferenceTypeParameterRef <object> .MethodWithOneParameter);
            var signature           = type.GetMethod(methodName) ?? throw new MethodInfoException(type, methodName);
            var refParameterFeature = new ParameterRef(signature, new object?[] { null });
            var invocation          = new Invocation(signature, refParameterFeature);
            var arrangment          = new RefParameterArrangement <object?>(signature, "first", expectedValue);

            // When
            var wasApplied = arrangment.TryApplyTo(invocation);

            // Then
            Assert.True(wasApplied);
            Assert.True(invocation.HasFeature <IParameterRef>());
            var feature = invocation.GetFeature <IParameterRef>();

            Assert.Single(feature.RefParameterCollection);
            var parameter = feature.RefParameterCollection.Single();

            Assert.Equal("first", parameter.Name);
            Assert.Equal(typeof(object), parameter.Type);
            Assert.Equal(expectedValue, parameter.Value);
        }