public async Task ScheduleMessageAsync(T payload, DateTimeOffset scheduleEnqueueTimeUtc) { string data = JsonSerializer.Serialize <T>(payload); var message = new Message(Encoding.UTF8.GetBytes(data)); await sender.ScheduleMessageAsync(message, scheduleEnqueueTimeUtc).ConfigureAwait(false); }
public async Task CallsScheduleMessageAsync() { var(sender, clientMock) = await ComposeServiceBusAndGetSender(); var message = new Message(); var scheduleEnqueueTimeUtc = new DateTimeOffset(); await sender.ScheduleMessageAsync(message, scheduleEnqueueTimeUtc); clientMock.Mock.Verify(o => o.ScheduleMessageAsync(message, scheduleEnqueueTimeUtc), Times.Once); }
internal async Task CancelScheduledMessagesAsyncTestCase(IMessageSender messageSender, IMessageReceiver messageReceiver, int messageCount) { var scheduleTime = new DateTimeOffset(DateTime.UtcNow).AddSeconds(30); var brokeredMessage = new Message(Encoding.UTF8.GetBytes("Test1")) { MessageId = Guid.NewGuid().ToString() }; TestUtility.Log( $"Sending message with schedule time: {scheduleTime.UtcDateTime} and messageID {brokeredMessage.MessageId}"); var sequenceNumber = await messageSender.ScheduleMessageAsync(brokeredMessage, scheduleTime); TestUtility.Log($"Received sequence number: {sequenceNumber}"); Assert.True(sequenceNumber > 0); TestUtility.Log("Cancelling scheduled message"); await messageSender.CancelScheduledMessageAsync(sequenceNumber); TestUtility.Log("Sleeping for 30 seconds..."); await Task.Delay(TimeSpan.FromSeconds(30)); // Sending a dummy message so that ReceiveAsync(2) returns immediately after getting 1 message // instead of waiting for connection timeout on a single message. await messageSender.SendAsync(new Message(Encoding.UTF8.GetBytes(("Dummy"))) { MessageId = "Dummy" }); IList <Message> messages = null; var retryCount = 5; while (messages == null && --retryCount > 0) { messages = await messageReceiver.ReceiveAsync(2); } Assert.NotNull(messages); Assert.True(messages.Count == 1); Assert.True(messages.First().MessageId == "Dummy"); }
internal async Task ScheduleMessagesAppearAfterScheduledTimeAsyncTestCase(IMessageSender messageSender, IMessageReceiver messageReceiver, int messageCount) { var startTime = DateTime.UtcNow; var scheduleTime = new DateTimeOffset(DateTime.UtcNow).AddSeconds(5); TestUtility.Log($"Sending message with schedule time: {scheduleTime.UtcDateTime}"); var sequenceNumber = await messageSender.ScheduleMessageAsync( new Message(Encoding.UTF8.GetBytes("Test")) { MessageId = "randomId", Label = "randomLabel" }, scheduleTime); TestUtility.Log($"Received sequence number: {sequenceNumber}"); Assert.True(sequenceNumber > 0); TestUtility.Log("Sleeping for 5 seconds..."); await Task.Delay(TimeSpan.FromSeconds(5)); var message = await messageReceiver.ReceiveAsync(); // Asserting using Math.Ceiling since TotalSeconds usually ends up being around 4.999 due to precision of // the scheduleTime in requestMessage and responseMessage. Assert.True(Math.Ceiling(message.ScheduledEnqueueTimeUtc.Subtract(startTime).TotalSeconds) >= 5); }
public Task <long> ScheduleSend(Message message, DateTime scheduleEnqueueTimeUtc) { return(_client.ScheduleMessageAsync(message, scheduleEnqueueTimeUtc)); }