public async Task ShouldQueueNewMessageWhenRescheduleRequired()
        {
            // Arrange
            DateTime         newScheduleDateTimeUtc = new DateTime(2019, 8, 1, 17, 31, 0);
            const string     testId  = "1234";
            ScheduledMessage message = new SimpleSchedulableCommand().CreateScheduledMessage(testId);

            _cancelledCommandRepository.TryRemoveCancelFlag(testId).Returns(false);
            _dateCalculator.NextScheduledAtUtc(DateTime.UtcNow, ScheduledMessageRecurrenceEnum.Daily)
            .ReturnsForAnyArgs(newScheduleDateTimeUtc);
            Message sentServiceBusMessage = null;
            await _queueClient.SendAsync(Arg.Do <Message>(x => sentServiceBusMessage = x));

            // Act
            bool didReschedule = await _testSubject.Reschedule(message);

            ScheduledMessage sentMessage =
                JsonConvert.DeserializeObject <ScheduledMessage>(Encoding.UTF8.GetString(sentServiceBusMessage.Body));

            // Assert
            Assert.Equal(testId, sentServiceBusMessage.MessageId);
            Assert.Equal(newScheduleDateTimeUtc, sentServiceBusMessage.ScheduledEnqueueTimeUtc);

            Assert.Equal(message.Id, sentMessage.Id);
            Assert.Equal(message.Recurrence, sentMessage.Recurrence);
            Assert.Equal(message.ScheduledAtUtc, sentMessage.LastScheduledAtUtc);
            Assert.Equal(newScheduleDateTimeUtc, sentMessage.ScheduledAtUtc);
            Assert.Equal(message.WrappedCommandFullTypeName, sentMessage.WrappedCommandFullTypeName);
            Assert.Equal(message.WrappedCommandJson, sentMessage.WrappedCommandJson);
        }
Exemple #2
0
        public async Task ShouldThrowExceptionIfInitialDateLessThanNow()
        {
            // Arrange
            DateTime scheduleDate            = DateTime.UtcNow.AddDays(-1);
            SimpleSchedulableCommand command = new SimpleSchedulableCommand();

            // Act
            await Assert.ThrowsAsync <ArgumentException>(() => _testSubject.ScheduleCommand(ScheduledMessageRecurrenceEnum.Daily, command, scheduleDate));
        }
Exemple #3
0
        public async Task ShouldRecheduleCommandThatReturnsTrue()
        {
            // Arrange
            _registrationCatalogue.GetRegisteredCommands().Returns(new Type[] { typeof(SimpleSchedulableCommand) });
            SimpleSchedulableCommand command = new SimpleSchedulableCommand();

            _commandDispatcher.DispatchAsync(command).ReturnsForAnyArgs(new CommandResult <bool>(true, false));

            // Act
            await _testSubject.ExecuteAsync(new SimpleSchedulableCommand().CreateScheduledMessage());

            // Assert
            await _commandRescheduler.ReceivedWithAnyArgs().Reschedule(null);
        }
        public async Task ShouldNotRequeueWhenCommandMarkedAsCancelled()
        {
            // Arrange
            const string     testId  = "1234";
            ScheduledMessage message = new SimpleSchedulableCommand().CreateScheduledMessage(testId);

            _cancelledCommandRepository.TryRemoveCancelFlag(testId).Returns(true);

            // Act
            bool didReschedule = await _testSubject.Reschedule(message);

            // Assert
            Assert.False(didReschedule);
            await _queueClient.DidNotReceiveWithAnyArgs().SendAsync(new Message());
        }
Exemple #5
0
        public async Task ShouldSetCustomMessageId()
        {
            // Arrange
            const string             customMessageId = "1234";
            Message                  capturedMessage = null;
            SimpleSchedulableCommand command         = new SimpleSchedulableCommand();
            await _queueClient.SendAsync(Arg.Do <Message>(m => capturedMessage = m));

            // Act
            string messageId = await _testSubject.ScheduleCommand(ScheduledMessageRecurrenceEnum.Daily, command, null, customMessageId);

            // Assert
            Assert.Equal(customMessageId, messageId);
            Assert.Equal(customMessageId, capturedMessage.MessageId);
        }
Exemple #6
0
        public async Task ShouldPostMessageAtInitialExecutionDate()
        {
            // Arrange
            Message  capturedMessage         = null;
            DateTime scheduleDate            = DateTime.UtcNow.AddDays(1);
            SimpleSchedulableCommand command = new SimpleSchedulableCommand();
            await _queueClient.SendAsync(Arg.Do <Message>(m => capturedMessage = m));

            // Act
            string messageId = await _testSubject.ScheduleCommand(ScheduledMessageRecurrenceEnum.Daily, command, scheduleDate);

            // Assert
            Assert.NotEmpty(messageId);
            Assert.Equal(scheduleDate, capturedMessage.ScheduledEnqueueTimeUtc);
            Assert.Equal(messageId, capturedMessage.MessageId);
        }