public void InitializeWithNullMethodInfoThrows()
        {
            var anonymousFactory = new DelegatingMethodFactory();

            Assert.Throws <ArgumentNullException>(() =>
                                                  new GenericMethod(null, anonymousFactory));
        }
        public void SutIsIMethod()
        {
            Action dummy            = delegate { };
            var    anonymousFactory = new DelegatingMethodFactory();
            var    sut = new GenericMethod(dummy.GetMethodInfo(), anonymousFactory);

            Assert.IsAssignableFrom <IMethod>(sut);
        }
        public void FactoryIsCorrect()
        {
            var anonymousMethod = ((Action) delegate { }).GetMethodInfo();
            var expectedFactory = new DelegatingMethodFactory();
            var sut             = new GenericMethod(anonymousMethod, expectedFactory);

            var result = sut.Factory;

            Assert.Equal(expectedFactory, result);
        }
        public void ParametersIsCorrect()
        {
            Action <int, double> dummy = delegate { };
            var anonymousFactory       = new DelegatingMethodFactory();
            var expectedParameters     = dummy.GetMethodInfo().GetParameters();
            var sut = new GenericMethod(dummy.GetMethodInfo(), anonymousFactory);

            var result = sut.Parameters;

            Assert.True(expectedParameters.SequenceEqual(result));
        }
Example #5
0
        public void MethodIsCorrect()
        {
            Action action           = () => { };
            var    expectedMethod   = action.GetMethodInfo();
            var    anonymousFactory = new DelegatingMethodFactory();
            var    sut = new GenericMethod(expectedMethod, anonymousFactory);

            var result = sut.Method;

            Assert.Equal(expectedMethod, result);
        }
        public void InvokeWithGenericMethodReturnsCorrectResult(Type targetType, int index, object values)
        {
            var method = (from mi in targetType
                          .GetMethods(BindingFlags.Static | BindingFlags.Public)
                          select mi).ElementAt(index);
            var factory = new DelegatingMethodFactory();

            factory.OnCreate = m => new StaticMethod(m);
            var sut = new GenericMethod(method, factory);

            var result = sut.Invoke((object[])values);

            Assert.IsAssignableFrom(targetType, result);
        }
        public void InvokeWithGenericMethodThatCannotBeInferredThrows(Type targetType, int index, object values)
        {
            var method = (from mi in targetType
                          .GetMethods(BindingFlags.Static | BindingFlags.Public)
                          select mi).ElementAt(index);
            var factory = new DelegatingMethodFactory();

            factory.OnCreate = m => new StaticMethod(m);
            var sut = new GenericMethod(method, factory);

            var exception = Assert.Throws <TypeArgumentsCannotBeInferredException>(
                () => sut.Invoke((object[])values));

            Assert.Contains(method.Name, exception.Message);
        }