Esempio n. 1
0
        public void InvokeAsync_DelegatesToInstanceFactoryAndMethodInvoker()
        {
            // Arrange
            object expectedInstance = new object();

            object[] expectedArguments = new object[0];

            IFunctionInstanceEx functionInstance = new Mock <IFunctionInstanceEx>().Object;
            Mock <IJobInstanceFactory <object> > instanceFactoryMock = new Mock <IJobInstanceFactory <object> >(MockBehavior.Strict);

            instanceFactoryMock.Setup(f => f.Create(It.IsAny <IFunctionInstanceEx>()))
            .Returns(expectedInstance)
            .Verifiable();
            IJobInstanceFactory <object> instanceFactory = instanceFactoryMock.Object;

            Mock <IMethodInvoker <object, object> > methodInvokerMock = new Mock <IMethodInvoker <object, object> >(MockBehavior.Strict);

            methodInvokerMock.Setup(i => i.InvokeAsync(expectedInstance, expectedArguments))
            .Returns(Task.FromResult <object>(null))
            .Verifiable();
            IMethodInvoker <object, object> methodInvoker = methodInvokerMock.Object;

            IFunctionInvokerEx product = CreateProductUnderTest(instanceFactory, methodInvoker);

            // Act
            var instance = product.CreateInstance(functionInstance);

            product.InvokeAsync(instance, expectedArguments).GetAwaiter().GetResult();

            // Assert
            instanceFactoryMock.VerifyAll();
            methodInvokerMock.VerifyAll();
        }
Esempio n. 2
0
 private static FunctionInvoker <TReflected, TReturnValue> CreateProductUnderTest <TReflected, TReturnValue>(
     IReadOnlyList <string> parameterNames,
     IJobInstanceFactory <TReflected> instanceFactory,
     IMethodInvoker <TReflected, TReturnValue> methodInvoker)
 {
     return(new FunctionInvoker <TReflected, TReturnValue>(parameterNames, instanceFactory, methodInvoker));
 }
Esempio n. 3
0
 public FunctionInvoker(
     IReadOnlyList <string> parameterNames,
     IJobInstanceFactory <TReflected> instanceFactory,
     IMethodInvoker <TReflected, TReturnValue> methodInvoker)
 {
     _parameterNames  = parameterNames ?? throw new ArgumentNullException(nameof(parameterNames));
     _instanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
     _methodInvoker   = methodInvoker ?? throw new ArgumentNullException(nameof(methodInvoker));
 }
        public void Create_ReturnsNull()
        {
            // Arrange
            IJobInstanceFactory <object> product = CreateProductUnderTest <object>();
            var functionInstanceMock             = new Mock <IFunctionInstanceEx>();

            // Act
            object instance = product.Create(functionInstanceMock.Object);

            // Assert
            Assert.Null(instance);
        }
Esempio n. 5
0
        private static IFunctionInvoker CreateGeneric <TReflected, TReturnValue>(
            MethodInfo method,
            IJobActivator activator)
        {
            Debug.Assert(method != null);

            List <string> parameterNames = method.GetParameters().Select(p => p.Name).ToList();

            IMethodInvoker <TReflected, TReturnValue> methodInvoker = MethodInvokerFactory.Create <TReflected, TReturnValue>(method);

            IJobInstanceFactory <TReflected> instanceFactory = CreateInstanceFactory <TReflected>(method, activator);

            return(new FunctionInvoker <TReflected, TReturnValue>(parameterNames, instanceFactory, methodInvoker));
        }
        public void Create_DelegatesToJobActivator()
        {
            // Arrange
            object expectedInstance = new object();
            Mock<IJobActivator> activatorMock = new Mock<IJobActivator>(MockBehavior.Strict);
            activatorMock.Setup(a => a.CreateInstance<object>())
                         .Returns(expectedInstance)
                         .Verifiable();
            IJobActivator activator = activatorMock.Object;

            IJobInstanceFactory<object> product = CreateProductUnderTest<object>(activator);

            var functionInstanceMock = new Mock<IFunctionInstanceEx>();

            // Act
            object instance = product.Create(functionInstanceMock.Object);

            // Assert
            Assert.Same(expectedInstance, instance);
            activatorMock.Verify();
        }
Esempio n. 7
0
 private static FunctionInvoker <object, object> CreateProductUnderTest(IJobInstanceFactory <object> instanceFactory,
                                                                        IMethodInvoker <object, object> methodInvoker)
 {
     return(CreateProductUnderTest <object, object>(new string[0], instanceFactory, methodInvoker));
 }