Skip to content

Commit 5fa6848

Browse files
committed
More tests
1 parent 732d4d6 commit 5fa6848

File tree

10 files changed

+51
-30
lines changed

10 files changed

+51
-30
lines changed

playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.ApiService/Program.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
// Add service defaults & Aspire client integrations.
1616
builder.AddServiceDefaults();
17-
builder.AddAzureQueueClient("queue");
18-
builder.AddAzureBlobClient("blob");
17+
builder.AddAzureQueueClient("queues");
18+
builder.AddAzureBlobClient("blobs");
1919
builder.AddAzureEventHubProducerClient("myhub");
2020
#if !SKIP_UNSTABLE_EMULATORS
2121
builder.AddAzureServiceBusClient("messaging");
@@ -26,8 +26,8 @@
2626

2727
app.MapGet("/publish/asq", async (QueueServiceClient client, CancellationToken cancellationToken) =>
2828
{
29-
var queue = client.GetQueueClient("queue");
30-
await queue.CreateIfNotExistsAsync(cancellationToken: cancellationToken);
29+
var queue = client.GetQueueClient("myqueue");
30+
3131
var data = Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello, World!"));
3232
await queue.SendMessageAsync(data, cancellationToken: cancellationToken);
3333
return Results.Ok("Message sent to Azure Storage Queue.");
@@ -41,15 +41,14 @@ static string RandomString(int length)
4141

4242
app.MapGet("/publish/blob", async (BlobServiceClient client, CancellationToken cancellationToken, int length = 20) =>
4343
{
44-
var container = client.GetBlobContainerClient("blobs");
45-
await container.CreateIfNotExistsAsync(cancellationToken: cancellationToken);
44+
var container = client.GetBlobContainerClient("myblobcontainer");
4645

4746
var entry = new { Id = Guid.NewGuid(), Text = RandomString(length) };
4847
var blob = container.GetBlobClient(entry.Id.ToString());
4948

5049
await blob.UploadAsync(new BinaryData(entry));
5150

52-
return Results.Ok("String uploaded to Azure Storage Blobs.");
51+
return Results.Ok($"String uploaded to Azure Storage Blobs {container.Uri}.");
5352
});
5453

5554
app.MapGet("/publish/eventhubs", async (EventHubProducerClient client, CancellationToken cancellationToken, int length = 20) =>

playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/Program.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
var builder = DistributedApplication.CreateBuilder(args);
22

33
var storage = builder.AddAzureStorage("storage").RunAsEmulator();
4-
var queue = storage.AddQueues("queue");
5-
var blob = storage.AddBlobs("blob");
6-
var myBlobContainer = blob.AddBlobContainer("myblobcontainer");
4+
5+
var queues = storage.AddQueues("queues");
6+
var myQueue = queues.AddQueue("myqueue");
7+
8+
var blobs = storage.AddBlobs("blobs");
9+
var myBlobContainer = blobs.AddBlobContainer("myblobcontainer");
710

811
var eventHub = builder.AddAzureEventHubs("eventhubs")
912
.RunAsEmulator()
@@ -22,22 +25,23 @@
2225
var funcApp = builder.AddAzureFunctionsProject<Projects.AzureFunctionsEndToEnd_Functions>("funcapp")
2326
.WithExternalHttpEndpoints()
2427
.WithReference(eventHub).WaitFor(eventHub)
25-
.WithReference(myBlobContainer).WaitFor(myBlobContainer)
2628
#if !SKIP_UNSTABLE_EMULATORS
2729
.WithReference(serviceBus).WaitFor(serviceBus)
2830
.WithReference(cosmosDb).WaitFor(cosmosDb)
2931
#endif
30-
.WithReference(blob)
31-
.WithReference(queue);
32+
.WithReference(blobs)
33+
.WithReference(myBlobContainer).WaitFor(myBlobContainer)
34+
.WithReference(queues)
35+
.WithReference(myQueue).WaitFor(myQueue);
3236

3337
builder.AddProject<Projects.AzureFunctionsEndToEnd_ApiService>("apiservice")
3438
.WithReference(eventHub).WaitFor(eventHub)
3539
#if !SKIP_UNSTABLE_EMULATORS
3640
.WithReference(serviceBus).WaitFor(serviceBus)
3741
.WithReference(cosmosDb).WaitFor(cosmosDb)
3842
#endif
39-
.WithReference(queue)
40-
.WithReference(blob)
43+
.WithReference(queues)
44+
.WithReference(blobs)
4145
.WithReference(funcApp);
4246

4347
builder.Build().Run();

playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyAzureBlobTrigger.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
namespace AzureFunctionsEndToEnd.Functions;
66

7-
public class MyAzureBlobTrigger(ILogger<MyAzureBlobTrigger> logger, BlobContainerClient containerClient)
7+
public class MyAzureBlobTrigger(BlobContainerClient containerClient, ILogger<MyAzureBlobTrigger> logger)
88
{
99
[Function(nameof(MyAzureBlobTrigger))]
10-
[BlobOutput("test-files/{name}.txt", Connection = "blob")]
11-
public async Task<string> RunAsync([BlobTrigger("blobs/{name}", Connection = "blob")] string triggerString, FunctionContext context)
10+
[BlobOutput("test-files/{name}.txt", Connection = "blobs")]
11+
public async Task<string> RunAsync([BlobTrigger("myblobcontainer/{name}", Connection = "blobs")] string triggerString, FunctionContext context)
1212
{
1313
var blobName = (string)context.BindingContext.BindingData["name"]!;
14-
await containerClient.UploadBlobAsync(blobName, new BinaryData(triggerString));
14+
var accountInfo = await containerClient.GetAccountInfoAsync();
1515

16-
logger.LogInformation("C# blob trigger function invoked for 'blobs/{source}' with {message}...", blobName, triggerString);
16+
logger.LogInformation("C# blob trigger function invoked for 'myblobcontainer/{source}' with {message}...", blobName, triggerString);
1717
return triggerString.ToUpper();
1818
}
1919
}

playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyAzureQueueTrigger.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
using Azure.Storage.Queues;
12
using Azure.Storage.Queues.Models;
23
using Microsoft.Azure.Functions.Worker;
34
using Microsoft.Extensions.Logging;
45

56
namespace AzureFunctionsEndToEnd.Functions;
67

7-
public class MyAzureQueueTrigger(ILogger<MyAzureQueueTrigger> logger)
8+
public class MyAzureQueueTrigger(QueueClient queueClient, ILogger<MyAzureQueueTrigger> logger)
89
{
910
[Function(nameof(MyAzureQueueTrigger))]
10-
public void Run([QueueTrigger("queue", Connection = "queue")] QueueMessage message)
11+
public void Run([QueueTrigger("myqueue", Connection = "queues")] QueueMessage message)
1112
{
13+
var props = queueClient.GetProperties();
14+
1215
logger.LogInformation("C# Queue trigger function processed: {Text}", message.MessageText);
1316
}
1417
}

playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/MyHttpTrigger.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class MyHttpTrigger(
2222
#endif
2323
EventHubProducerClient eventHubProducerClient,
2424
QueueServiceClient queueServiceClient,
25+
QueueClient queueClient,
2526
BlobServiceClient blobServiceClient,
2627
BlobContainerClient blobContainerClient)
2728
{
@@ -35,6 +36,7 @@ public IResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] Ht
3536
#endif
3637
stringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Aspire-injected EventHubProducerClient namespace: {eventHubProducerClient.FullyQualifiedNamespace}");
3738
stringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Aspire-injected QueueServiceClient URI: {queueServiceClient.Uri}");
39+
stringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Aspire-injected QueueClient URI: {queueClient.Uri}");
3840
stringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Aspire-injected BlobServiceClient URI: {blobServiceClient.Uri}");
3941
stringBuilder.AppendLine(CultureInfo.InvariantCulture, $"Aspire-injected BlobContainerClient URI: {blobContainerClient.Uri}");
4042
return Results.Text(stringBuilder.ToString());

playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/Program.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
var builder = FunctionsApplication.CreateBuilder(args);
55

66
builder.AddServiceDefaults();
7-
builder.AddAzureQueueClient("queue");
8-
builder.AddAzureBlobClient("blob");
7+
8+
builder.AddAzureQueueClient("queues");
9+
builder.AddAzureQueue("myqueue");
10+
11+
builder.AddAzureBlobClient("blobs");
912
builder.AddAzureBlobContainerClient("myblobcontainer");
13+
1014
builder.AddAzureEventHubProducerClient("myhub");
1115
#if !SKIP_UNSTABLE_EMULATORS
1216
builder.AddAzureServiceBusClient("messaging");

playground/AzureStorageEndToEnd/AzureStorageEndToEnd.ApiService/Program.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,29 @@
1212
builder.AddKeyedAzureBlobContainerClient("foocontainer");
1313

1414
builder.AddAzureQueueClient("queues");
15+
builder.AddKeyedAzureQueueClient("myqueue");
1516

1617
var app = builder.Build();
1718

1819
app.MapDefaultEndpoints();
1920

20-
app.MapGet("/", async (BlobServiceClient bsc, QueueServiceClient qsc, [FromKeyedServices("foocontainer")] BlobContainerClient keyedContainerClient1) =>
21+
app.MapGet("/", async (BlobServiceClient bsc, QueueServiceClient qsc, [FromKeyedServices("foocontainer")] BlobContainerClient bcc, [FromKeyedServices("myqueue")] QueueClient qc) =>
2122
{
2223
var blobNames = new List<string>();
2324
var blobNameAndContent = Guid.NewGuid().ToString();
2425

25-
await keyedContainerClient1.UploadBlobAsync(blobNameAndContent, new BinaryData(blobNameAndContent));
26+
await bcc.UploadBlobAsync(blobNameAndContent, new BinaryData(blobNameAndContent));
2627

2728
var directContainerClient = bsc.GetBlobContainerClient(blobContainerName: "test-container-1");
2829
await directContainerClient.UploadBlobAsync(blobNameAndContent, new BinaryData(blobNameAndContent));
2930

3031
await ReadBlobsAsync(directContainerClient, blobNames);
31-
await ReadBlobsAsync(keyedContainerClient1, blobNames);
32+
await ReadBlobsAsync(bcc, blobNames);
3233

34+
// This will check the queue exists.
3335
var queue = qsc.GetQueueClient("myqueue");
34-
await queue.CreateIfNotExistsAsync();
35-
await queue.SendMessageAsync("Hello, world!");
36+
37+
await qc.SendMessageAsync("Hello, world!");
3638

3739
return blobNames;
3840
});

playground/AzureStorageEndToEnd/AzureStorageEndToEnd.AppHost/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
blobs.AddBlobContainer("mycontainer2", blobContainerName: "test-container-2");
1414

1515
var queues = storage.AddQueues("queues");
16+
var myqueue = queues.AddQueue("myqueue", queueName: "my-queue");
1617

1718
var storage2 = builder.AddAzureStorage("storage2").RunAsEmulator(container =>
1819
{
@@ -25,7 +26,8 @@
2526
.WithExternalHttpEndpoints()
2627
.WithReference(blobs).WaitFor(blobs)
2728
.WithReference(blobContainer2).WaitFor(blobContainer2)
28-
.WithReference(queues).WaitFor(queues);
29+
.WithReference(queues).WaitFor(queues)
30+
.WithReference(myqueue).WaitFor(myqueue);
2931

3032
#if !SKIP_DASHBOARD_REFERENCE
3133
// This project is only added in playground projects to support development/debugging

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureStorageExtensionsTests.ResourceNamesBicepValid.verified.bicep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ resource blobs 'Microsoft.Storage/storageAccounts/blobServices@2024-01-01' = {
2626
parent: storage
2727
}
2828

29+
resource queues 'Microsoft.Storage/storageAccounts/queueServices@2024-01-01' = {
30+
parent: storage
31+
}
32+
2933
resource myContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2024-01-01' = {
3034
name: 'my-blob-container'
3135
parent: blobs

tests/Aspire.Playground.Tests/ProjectSpecificTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ await WaitForAllTextAsync(app,
9191
{
9292
"Aspire-injected EventHubProducerClient namespace: localhost",
9393
"Aspire-injected QueueServiceClient URI: http://127.0.0.1:*/devstoreaccount1",
94+
"Aspire-injected QueueClient URI: http://127.0.0.1:*/devstoreaccount1/myqueue",
9495
"Aspire-injected BlobServiceClient URI: http://127.0.0.1:*/devstoreaccount1",
9596
"Aspire-injected BlobContainerClient URI: http://127.0.0.1:*/devstoreaccount1/myblobcontainer"
9697
};

0 commit comments

Comments
 (0)