public async Task GetConversationGroupAsync_UsesTransaction()
        {
            // Arrange
            await InitializeDatabaseAsync();
            var provider1 = new SqlServerServiceBroker(connection);
            var provider2 = new SqlServerServiceBroker(new SqlConnection(connection.ConnectionString));
            var handle = await BeginDialogAsync();
            IEnumerable<ReceivedMessage> beforeRollback;
            IEnumerable<ReceivedMessage> afterRollback;
            await connection.ExecuteAsync("SEND ON CONVERSATION @handle;", new { handle });

            // Act
            using (var transaction = await provider1.BeginTransactionAsync())
            {
                var arguments = new GetConversationGroupArguments("TargetQueue");
                var groupId = await provider1.GetConversationGroupAsync(arguments);
                var receiveArgs = new ReceiveArguments("TargetQueue")
                {
                    Predicate = groupId.Value,
                    WaitFor = TimeSpan.FromSeconds(1),
                };

                beforeRollback = await provider2.ReceiveAsync(receiveArgs);
                transaction.Rollback();
                afterRollback = await provider2.ReceiveAsync(receiveArgs);
            }

            // Assert
            Assert.Empty(beforeRollback);
            Assert.NotEmpty(afterRollback);
        }
        public async Task GetConversationGroupAsync_RespectsQueue()
        {
            // Arrange
            await InitializeDatabaseAsync();
            var provider = new SqlServerServiceBroker(connection);
            var handle = await BeginDialogAsync();
            await connection.ExecuteAsync("SEND ON CONVERSATION @handle;", new { handle });

            // Act
            var groupId = await provider.GetConversationGroupAsync(new GetConversationGroupArguments("TargetQueue")
            {
            });

            // Assert
            Assert.True(groupId.HasValue);
            Assert.NotEqual(Guid.Empty, groupId.GetValueOrDefault().Value);
        }
        public async Task GetConversationGroupAsync_RespectsWaitFor()
        {
            // Arrange
            await InitializeDatabaseAsync();
            var provider = new SqlServerServiceBroker(connection);
            var handle = await BeginDialogAsync();

            // Act
            var groupId = provider.GetConversationGroupAsync(new GetConversationGroupArguments("TargetQueue")
            {
                WaitFor = MillisecondTimeout.Unlimited,
            });
            Thread.Sleep(1000);

            // Assert
            Assert.False(groupId.IsCompleted);
        }
        public async Task GetConversationGroupAsync_ArgumentsCannotBeNull()
        {
            // Arrange
            var provider = new SqlServerServiceBroker(connection);

            // Act
            Func<Task> call = async () => await provider.GetConversationGroupAsync(null);

            // Assert
            await Assert.ThrowsAsync<ArgumentNullException>("arguments", call);
        }