File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Threading . Tasks ;
3+ using Azure . Storage . Blobs ;
4+ using Testcontainers . Azurite ;
5+ using Xunit ;
6+
7+ namespace Api . Test ;
8+
9+ public class TestAzuriteStorage : IAsyncLifetime
10+ {
11+ private AzuriteContainer _container = null ! ;
12+ private string _connectionString = null ! ;
13+
14+ public async ValueTask InitializeAsync ( )
15+ {
16+ ( _container , _connectionString ) = await TestSetupHelpers . ConfigureAzuriteStorage ( ) ;
17+ }
18+
19+ public async ValueTask DisposeAsync ( )
20+ {
21+ await _container . DisposeAsync ( ) ;
22+ GC . SuppressFinalize ( this ) ;
23+ }
24+
25+ [ Fact ]
26+ public async Task CheckThatJsonFileCanBeStored ( )
27+ {
28+ var clientOptions = new BlobClientOptions ( BlobClientOptions . ServiceVersion . V2025_11_05 ) ;
29+ var serviceClient = new BlobServiceClient ( _connectionString , clientOptions ) ;
30+ var containerClient = serviceClient . GetBlobContainerClient ( "test-container" ) ;
31+ await containerClient . CreateAsync ( cancellationToken : TestContext . Current . CancellationToken ) ;
32+
33+ var blobClient = containerClient . GetBlobClient ( "test.json" ) ;
34+ await blobClient . UploadAsync (
35+ BinaryData . FromString ( "{\" message\" :\" hello\" }" ) ,
36+ TestContext . Current . CancellationToken
37+ ) ;
38+
39+ Assert . True ( await blobClient . ExistsAsync ( TestContext . Current . CancellationToken ) ) ;
40+ }
41+ }
Original file line number Diff line number Diff line change 1515using Microsoft . EntityFrameworkCore ;
1616using Microsoft . Extensions . Logging ;
1717using Moq ;
18+ using Testcontainers . Azurite ;
1819using Testcontainers . PostgreSql ;
1920using Xunit . Sdk ;
2021
2122namespace Api . Test ;
2223
2324public static class TestSetupHelpers
2425{
26+ private const string AzuriteVersion = "mcr.microsoft.com/azure-storage/azurite:3.36.0" ;
2527 private const string PostgresVersion = "postgres:17.10" ;
2628
29+ public static async Task < ( AzuriteContainer , string ) > ConfigureAzuriteStorage ( )
30+ {
31+ var container = new AzuriteBuilder ( AzuriteVersion ) . Build ( ) ;
32+ await container . StartAsync ( ) ;
33+
34+ return ( container , container . GetConnectionString ( ) ) ;
35+ }
36+
2737 public static async Task < (
2838 PostgreSqlContainer ,
2939 string ,
Original file line number Diff line number Diff line change 1212 <PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 18.0.1" />
1313 <PackageReference Include =" Microsoft.AspNetCore.DataProtection" Version =" 10.0.10" />
1414 <PackageReference Include =" Microsoft.AspNetCore.Mvc.Testing" Version =" 10.0.10" />
15+ <PackageReference Include =" Azure.Storage.Blobs" Version =" 12.29.1" />
1516 <PackageReference Include =" Moq" Version =" 4.20.72" />
17+ <PackageReference Include =" Testcontainers.Azurite" Version =" 4.10.0" />
1618 <PackageReference Include =" Testcontainers.PostgreSql" Version =" 4.10.0" />
1719 <!-- Override transitive SSH.NET pulled in by Testcontainers to patch GHSA-q939-rpr3-3284 -->
1820 <PackageReference Include =" SSH.NET" Version =" 2026.0.0" />
You can’t perform that action at this time.
0 commit comments