public async Task Should_receive_it()
        {
            var payload       = "payload";
            var bytes         = Encoding.UTF8.GetBytes(payload);
            var message       = new Message(bytes);
            var configuration = new AzureStorageAttachmentConfiguration(
                connectionStringProvider: AzureStorageEmulatorFixture.ConnectionStringProvider, containerName: "attachments", messagePropertyToIdentifyAttachmentBlob: "attachment-id");

            var plugin = new AzureStorageAttachment(configuration);
            await plugin.BeforeMessageSend(message);

            Assert.Null(message.Body);

            var receivedMessage = await plugin.AfterMessageReceive(message);

            Assert.Equal(payload, Encoding.UTF8.GetString(receivedMessage.Body));
        }
Ejemplo n.º 2
0
        public async Task Should_receive_it_using_container_sas()
        {
            var payload       = "payload";
            var bytes         = Encoding.UTF8.GetBytes(payload);
            var message       = new Message(bytes);
            var credentials   = new StorageCredentials(await fixture.GetContainerSas("attachments"));
            var configuration = new AzureStorageAttachmentConfiguration(credentials, fixture.GetBlobEndpoint(), messagePropertyToIdentifyAttachmentBlob: "attachment-id");

            var plugin = new AzureStorageAttachment(configuration);
            await plugin.BeforeMessageSend(message);

            Assert.Null(message.Body);

            var receivedMessage = await plugin.AfterMessageReceive(message);

            Assert.Equal(payload, Encoding.UTF8.GetString(receivedMessage.Body));
        }
        public async Task Should_be_able_to_send_if_container_was_not_found()
        {
            await fixture.DeleteContainer("attachments-that-didnt-exist");

            var payload       = "payload";
            var bytes         = Encoding.UTF8.GetBytes(payload);
            var message       = new Message(bytes);
            var configuration = new AzureStorageAttachmentConfiguration(
                connectionStringProvider: AzureStorageEmulatorFixture.ConnectionStringProvider, containerName: "attachments-that-didnt-exist", messagePropertyToIdentifyAttachmentBlob: "attachment-id");

            var plugin = new AzureStorageAttachment(configuration);
            await plugin.BeforeMessageSend(message);

            Assert.Null(message.Body);

            var receivedMessage = await plugin.AfterMessageReceive(message);

            Assert.Equal(payload, Encoding.UTF8.GetString(receivedMessage.Body));
        }
        public async Task Should_throw_exception_with_blob_path_for_blob_that_cant_be_found()
        {
            var payload = "payload";
            var bytes   = Encoding.UTF8.GetBytes(payload);
            var message = new Message(bytes)
            {
                MessageId = Guid.NewGuid().ToString(),
            };

            var sendingPlugin = new AzureStorageAttachment(new AzureStorageAttachmentConfiguration(
                                                               connectionStringProvider: AzureStorageEmulatorFixture.ConnectionStringProvider, containerName: "attachments"));
            await sendingPlugin.BeforeMessageSend(message);

            var receivingPlugin = new AzureStorageAttachment(new AzureStorageAttachmentConfiguration(
                                                                 connectionStringProvider: AzureStorageEmulatorFixture.ConnectionStringProvider, containerName: "attachments-wrong-containers"));

            var exception = await Assert.ThrowsAsync <Exception>(() => receivingPlugin.AfterMessageReceive(message));

            Assert.Contains("attachments-wrong-containers", actualString: exception.Message);
            Assert.Contains(message.UserProperties["$attachment.blob"].ToString(), actualString: exception.Message);
        }
Ejemplo n.º 5
0
        /// <summary>Download attachment from Azure Storage blob without registering plugin, using configuration object.</summary>
        /// <param name="message"><see cref="Message"/></param>
        /// <param name="configuration"><see cref="AzureStorageAttachmentConfiguration"/> object.</param>
        /// <returns><see cref="Message"/> with body downloaded from Azure Storage blob.</returns>
        public static async Task <Message> DownloadAzureStorageAttachment(this Message message, AzureStorageAttachmentConfiguration configuration)
        {
            var plugin = new AzureStorageAttachment(configuration);

            return(await plugin.AfterMessageReceive(message).ConfigureAwait(false));
        }