Ejemplo n.º 1
0
        // TODO - Test on started are scheduled only once
        // TODO - Test on completed are called once at the end
        // TODO - Test callNotificationMethod

        // TODO - Scan attrs and throw if signatures are invalid
        // TODO - Add correct licence

        private void AssertNotificationJobInvocationIsValid(
            IInvocation invocation,
            string expectedJobName,
            DummyMapperJob.State expectedState)
        {
            var enqueuedJob = invocation.Arguments[0] as Job;

            Assert.NotNull(enqueuedJob);

            invocation.Arguments[1].Should().BeOfType <EnqueuedState>();

            enqueuedJob.Args[0].Should().BeEquivalentTo(expectedJobName);
            enqueuedJob.Args[1].Should().BeEquivalentTo(expectedState);
            enqueuedJob.Method.Name.Should().Be("CallNotificationMethod");
        }
Ejemplo n.º 2
0
        public void NextBatchIsEnqueued()
        {
            var initialState = new DummyMapperJob.State {
                Page = 1
            };
            var nextState = new DummyMapperJob.State {
                Page = 2
            };

            _repo.Setup(r => r.List(initialState.Page)).ReturnsAsync(new[] { _res1, _res2, _res3 });

            var job = new DummyMapperJob(_batchClient.Object, _repo.Object, null);

            Action <IBatchAction> action = null;

            _batchClient.Setup(
                client => client.Create(
                    It.IsAny <Action <IBatchAction> >(), It.IsAny <BatchStartedState>(), It.IsAny <string>()))
            .Returns("initial-batch-id");

            _batchClient.Setup(
                client => client.Create(
                    It.IsAny <Action <IBatchAction> >(), It.IsAny <BatchAwaitingState>(), null))
            .Callback <Action <IBatchAction>, IBatchState, string>((a, state, d) => action = a);

            job.Enqueue(initialState);

            var batchAction = new Mock <IBatchAction>();

            action(batchAction.Object);

            batchAction.Invocations.Should().SatisfyRespectively(
                nextBatch =>
            {
                var enqueuedJob = nextBatch.Arguments[0] as Job;

                Assert.NotNull(enqueuedJob);

                // TODO - Check parent id
                enqueuedJob.Args[0].Should().BeEquivalentTo(nextState);
                nextBatch.Arguments[1].Should().BeOfType <EnqueuedState>();
            });
        }
Ejemplo n.º 3
0
        public void OnJobStartedJobsAreScheduled()
        {
            var initialState = new DummyMapperJob.State {
                Page = 1
            };

            _repo.Setup(r => r.List(initialState.Page)).ReturnsAsync(new[] { _res1 });

            Action <IBatchAction> action = null;

            _batchClient.Setup(
                client => client.Create(
                    It.IsAny <Action <IBatchAction> >(), It.IsAny <BatchStartedState>(), It.IsAny <string>()))
            .Callback <Action <IBatchAction>, IBatchState, string>((a, state, d) => action = a)
            .Returns("initial-batch-id");

            var job = new DummyMapperJob(_batchClient.Object, _repo.Object, null);

            job.Enqueue(initialState);

            var batchAction = new Mock <IBatchAction>();

            action(batchAction.Object);

            batchAction.Invocations.Should().SatisfyRespectively(
                markJobAsStartedJob =>
                AssertNotificationJobInvocationIsValid(
                    markJobAsStartedJob,
                    "MarkJobAsStarted",
                    initialState),
                sendJobStartedEmailNotificationJob =>
                AssertNotificationJobInvocationIsValid(
                    sendJobStartedEmailNotificationJob,
                    "SendJobStartedEmailNotification",
                    initialState),
                jobA => { });
        }