public void DefaultActivator_ThrowAnException_IfThereIsNoDefaultConstructor()
        {
            var activator = new JobActivator();

            Assert.Throws<MissingMethodException>(
                () => activator.ActivateJob(typeof (CustomConstructor)));
        }
        public void GetCurrent_ReturnsPreviouslySetValue()
        {
            var activator = new JobActivator();
            JobActivator.Current = activator;

            Assert.Same(activator, JobActivator.Current);
        }
Beispiel #3
0
        public object Perform(JobActivator activator, IJobCancellationToken cancellationToken)
        {
            if (activator == null) throw new ArgumentNullException("activator");
            if (cancellationToken == null) throw new ArgumentNullException("cancellationToken");

            object instance = null;

            object result;
            try
            {
                if (!Method.IsStatic)
                {
                    instance = Activate(activator);
                }

                var deserializedArguments = DeserializeArguments(cancellationToken);
                result = InvokeMethod(instance, deserializedArguments, cancellationToken.ShutdownToken);
            }
            finally
            {
                Dispose(instance);
            }

            return result;
        }
        public void DefaultActivator_CanCreateInstanceOfClassWithDefaultConstructor()
        {
            var activator = new JobActivator();

            var instance = activator.ActivateJob(typeof (DefaultConstructor));

            Assert.NotNull(instance);
        }
 internal DefaultJobPerformanceProcess(JobActivator activator, IEnumerable<object> filters)
     : this(activator)
 {
     if (filters != null)
     {
         _getFiltersThunk = jd => filters.Select(f => new JobFilter(f, JobFilterScope.Type, null));
     }
 }
Beispiel #6
0
        public void WhenICallTheActivateMethodWithTheTypeArgument(string type)
        {
            try
            {
                Type jobType = null;

                if (type == "TestJob") jobType = typeof (TestJob);
                else if (type == "CustomConstructorJob") jobType = typeof (CustomConstructorJob);

                var activator = new JobActivator();
                _jobInstance = activator.ActivateJob(jobType);
            }
            catch (Exception ex)
            {
                _exception = ex;
            }
        }
Beispiel #7
0
        private object Activate(JobActivator activator)
        {
            try
            {
                var instance = activator.ActivateJob(Type);

                if (instance == null)
                {
                    throw new InvalidOperationException($"JobActivator returned NULL instance of the '{Type}' type.");
                }

                return instance;
            }
            catch (Exception ex)
            {
                throw new JobPerformanceException(
                    "An exception occurred during job activation.",
                    ex);
            }
        }
        internal SharedWorkerContext(
            string serverId,
            string[] queues,
            JobStorage storage,
            IJobPerformanceProcess performanceProcess,
            JobActivator activator,
            IStateMachineFactory stateMachineFactory)
        {
            if (serverId == null) throw new ArgumentNullException("serverId");
            if (queues == null) throw new ArgumentNullException("queues");
            if (storage == null) throw new ArgumentNullException("storage");
            if (performanceProcess == null) throw new ArgumentNullException("performanceProcess");
            if (activator == null) throw new ArgumentNullException("activator");
            if (stateMachineFactory == null) throw new ArgumentNullException("stateMachineFactory");

            ServerId = serverId;
            Queues = queues;
            Storage = storage;
            PerformanceProcess = performanceProcess;
            Activator = activator;
            StateMachineFactory = stateMachineFactory;
        }
 public CoreBackgroundJobPerformer([NotNull] JobActivator activator)
 {
     if (activator == null) throw new ArgumentNullException("activator");
     _activator = activator;
 }
 public DefaultJobPerformanceProcess([NotNull] JobActivator activator)
 {
     if (activator == null) throw new ArgumentNullException("activator");
     _activator = activator;
 }