Example #1
0
        public void NoJobsAreEnqueuedIfQueryReturnsEmptySet()
        {
            _repo.Setup(r => r.List(It.IsAny <int>())).ReturnsAsync(new List <Resource>());

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

            job.Enqueue(new DummyMapperJob.State());

            _batchClient.VerifyNoOtherCalls();
        }
Example #2
0
        public void QueryIsCalledWithInitialState()
        {
            var initialPage = 1;

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

            job.Enqueue(new DummyMapperJob.State {
                Page = initialPage
            });

            _repo.Verify(r => r.List(initialPage), Times.Once);
        }
Example #3
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>();
            });
        }
Example #4
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 => { });
        }
Example #5
0
        public void InitialBatchIsEnqueuedWithIndividualChildJobs()
        {
            var initialPage = 1;

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

            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(new DummyMapperJob.State {
                Page = initialPage
            });

            var batchAction = new Mock <IBatchAction>();

            action(batchAction.Object);

            batchAction.Invocations.Should().SatisfyRespectively(
                markJobAsStartedJob => { },
                sendJobStartedEmailNotificationJob => { },
                jobA =>
            {
                var enqueuedJob = jobA.Arguments[0] as Job;

                Assert.NotNull(enqueuedJob);

                enqueuedJob.Args[0].Should().BeEquivalentTo(_res1);
                enqueuedJob.Method.Name.Should().Be("Next");

                jobA.Arguments[1].Should().BeOfType <EnqueuedState>();
            },
                jobB =>
            {
                var enqueuedJob = jobB.Arguments[0] as Job;

                Assert.NotNull(enqueuedJob);

                enqueuedJob.Args[0].Should().BeEquivalentTo(_res2);
                enqueuedJob.Method.Name.Should().Be("Next");

                jobB.Arguments[1].Should().BeOfType <EnqueuedState>();
            },
                jobC =>
            {
                var enqueuedJob = jobC.Arguments[0] as Job;

                Assert.NotNull(enqueuedJob);

                enqueuedJob.Args[0].Should().BeEquivalentTo(_res3);
                enqueuedJob.Method.Name.Should().Be("Next");

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