Best Testcontainers-dotnet code snippet using DotNet.Testcontainers.Tests.Fixtures.AzuriteDefaultFixture
AzuriteTestcontainerTest.cs
Source:AzuriteTestcontainerTest.cs
...47 }48 [UsedImplicitly]49 public sealed class AllServicesEnabled50 {51 private static async Task EstablishConnection(AzuriteFixture.AzuriteDefaultFixture azurite)52 {53 // Given54 var blobServiceClient = new BlobServiceClient(azurite.Container.ConnectionString);55 var queueServiceClient = new QueueServiceClient(azurite.Container.ConnectionString);56 var tableServiceClient = new TableServiceClient(azurite.Container.ConnectionString);57 // When58 var blobProperties = await blobServiceClient.GetPropertiesAsync()59 .ConfigureAwait(false);60 var queueProperties = await queueServiceClient.GetPropertiesAsync()61 .ConfigureAwait(false);62 var tableProperties = await tableServiceClient.GetPropertiesAsync()63 .ConfigureAwait(false);64 var execResult = await azurite.Container.ExecAsync(new List<string> { "ls", AzuriteTestcontainerConfiguration.DefaultWorkspaceDirectoryPath })65 .ConfigureAwait(false);66 // Then67 Assert.False(HasError(blobProperties));68 Assert.False(HasError(queueProperties));69 Assert.False(HasError(tableProperties));70 Assert.Equal(0, execResult.ExitCode);71 Assert.Equal(azurite.Configuration.BlobContainerPort, azurite.Container.BlobContainerPort);72 Assert.Equal(azurite.Configuration.QueueContainerPort, azurite.Container.QueueContainerPort);73 Assert.Equal(azurite.Configuration.TableContainerPort, azurite.Container.TableContainerPort);74 Assert.Contains(BlobServiceDataFileName, execResult.Stdout);75 Assert.Contains(QueueServiceDataFileName, execResult.Stdout);76 Assert.Contains(TableServiceDataFileName, execResult.Stdout);77 }78 [Collection(nameof(Testcontainers))]79 public sealed class CommonContainerPorts : IClassFixture<AzuriteFixture.AzuriteDefaultFixture>80 {81 private readonly AzuriteFixture.AzuriteDefaultFixture commonContainerPorts;82 public CommonContainerPorts(AzuriteFixture.AzuriteDefaultFixture commonContainerPorts)83 {84 this.commonContainerPorts = commonContainerPorts;85 }86 [Fact]87 public async Task ConnectionEstablished()88 {89 Assert.Null(await Record.ExceptionAsync(() => EstablishConnection(this.commonContainerPorts))90 .ConfigureAwait(false));91 }92 }93 [Collection(nameof(Testcontainers))]94 public sealed class CustomContainerPorts : IClassFixture<AzuriteFixture.AzuriteWithCustomContainerPortsFixture>95 {96 private readonly AzuriteFixture.AzuriteDefaultFixture customContainerPorts;97 public CustomContainerPorts(AzuriteFixture.AzuriteWithCustomContainerPortsFixture customContainerPorts)98 {99 this.customContainerPorts = customContainerPorts;100 }101 [Fact]102 public async Task ConnectionEstablished()103 {104 Assert.Null(await Record.ExceptionAsync(() => EstablishConnection(this.customContainerPorts))105 .ConfigureAwait(false));106 }107 }108 }109 [Collection(nameof(Testcontainers))]110 public sealed class BlobServiceEnabled : IClassFixture<AzuriteFixture.AzuriteWithBlobOnlyFixture>111 {112 private readonly AzuriteFixture.AzuriteDefaultFixture azurite;113 public BlobServiceEnabled(AzuriteFixture.AzuriteWithBlobOnlyFixture azurite)114 {115 this.azurite = azurite;116 }117 [Fact]118 public async Task ConnectionEstablished()119 {120 // Given121 var blobServiceClient = new BlobServiceClient(this.azurite.Container.ConnectionString);122 var queueServiceClient = new QueueServiceClient(this.azurite.Container.ConnectionString);123 var tableServiceClient = new TableServiceClient(this.azurite.Container.ConnectionString);124 // When125 var blobProperties = await blobServiceClient.GetPropertiesAsync()126 .ConfigureAwait(false);127 var execResult = await this.azurite.Container.ExecAsync(new List<string> { "ls", AzuriteTestcontainerConfiguration.DefaultWorkspaceDirectoryPath })128 .ConfigureAwait(false);129 // Then130 Assert.False(HasError(blobProperties));131 Assert.Equal(0, execResult.ExitCode);132 Assert.Contains(BlobServiceDataFileName, execResult.Stdout);133 Assert.DoesNotContain(QueueServiceDataFileName, execResult.Stdout);134 Assert.DoesNotContain(TableServiceDataFileName, execResult.Stdout);135 await Assert.ThrowsAsync<RequestFailedException>(() => queueServiceClient.GetPropertiesAsync())136 .ConfigureAwait(false);137 await Assert.ThrowsAsync<RequestFailedException>(() => tableServiceClient.GetPropertiesAsync())138 .ConfigureAwait(false);139 }140 }141 [Collection(nameof(Testcontainers))]142 public sealed class QueueServiceEnabled : IClassFixture<AzuriteFixture.AzuriteWithQueueOnlyFixture>143 {144 private readonly AzuriteFixture.AzuriteDefaultFixture azurite;145 public QueueServiceEnabled(AzuriteFixture.AzuriteWithQueueOnlyFixture azurite)146 {147 this.azurite = azurite;148 }149 [Fact]150 public async Task ConnectionEstablished()151 {152 // Given153 var blobServiceClient = new BlobServiceClient(this.azurite.Container.ConnectionString);154 var queueServiceClient = new QueueServiceClient(this.azurite.Container.ConnectionString);155 var tableServiceClient = new TableServiceClient(this.azurite.Container.ConnectionString);156 // When157 var queueProperties = await queueServiceClient.GetPropertiesAsync()158 .ConfigureAwait(false);159 var execResult = await this.azurite.Container.ExecAsync(new List<string> { "ls", AzuriteTestcontainerConfiguration.DefaultWorkspaceDirectoryPath })160 .ConfigureAwait(false);161 // Then162 Assert.False(HasError(queueProperties));163 Assert.Equal(0, execResult.ExitCode);164 Assert.Contains(QueueServiceDataFileName, execResult.Stdout);165 Assert.DoesNotContain(BlobServiceDataFileName, execResult.Stdout);166 Assert.DoesNotContain(TableServiceDataFileName, execResult.Stdout);167 await Assert.ThrowsAsync<RequestFailedException>(() => blobServiceClient.GetPropertiesAsync())168 .ConfigureAwait(false);169 await Assert.ThrowsAsync<RequestFailedException>(() => tableServiceClient.GetPropertiesAsync())170 .ConfigureAwait(false);171 }172 }173 [Collection(nameof(Testcontainers))]174 public sealed class TableServiceEnabled : IClassFixture<AzuriteFixture.AzuriteWithTableOnlyFixture>175 {176 private readonly AzuriteFixture.AzuriteDefaultFixture azurite;177 public TableServiceEnabled(AzuriteFixture.AzuriteWithTableOnlyFixture azurite)178 {179 this.azurite = azurite;180 }181 [Fact]182 public async Task ConnectionEstablished()183 {184 // Given185 var blobServiceClient = new BlobServiceClient(this.azurite.Container.ConnectionString);186 var queueServiceClient = new QueueServiceClient(this.azurite.Container.ConnectionString);187 var tableServiceClient = new TableServiceClient(this.azurite.Container.ConnectionString);188 // When189 var tableProperties = await tableServiceClient.GetPropertiesAsync()190 .ConfigureAwait(false);...
AzuriteFixture.cs
Source:AzuriteFixture.cs
...10 using Xunit;11 public static class AzuriteFixture12 {13 [UsedImplicitly]14 public class AzuriteDefaultFixture : IAsyncLifetime15 {16 public AzuriteDefaultFixture()17 : this(new AzuriteTestcontainerConfiguration())18 {19 }20 protected AzuriteDefaultFixture(AzuriteTestcontainerConfiguration configuration)21 {22 this.Configuration = configuration;23 this.Container = new TestcontainersBuilder<AzuriteTestcontainer>()24 .WithAzurite(configuration)25 .Build();26 }27 public AzuriteTestcontainerConfiguration Configuration { get; }28 public AzuriteTestcontainer Container { get; }29 public Task InitializeAsync()30 {31 return this.Container.StartAsync();32 }33 public Task DisposeAsync()34 {35 return this.Container.DisposeAsync().AsTask();36 }37 }38 [UsedImplicitly]39 public sealed class AzuriteWithBlobOnlyFixture : AzuriteDefaultFixture40 {41 public AzuriteWithBlobOnlyFixture()42 : base(new AzuriteTestcontainerConfiguration { BlobServiceOnlyEnabled = true })43 {44 }45 }46 [UsedImplicitly]47 public sealed class AzuriteWithQueueOnlyFixture : AzuriteDefaultFixture48 {49 public AzuriteWithQueueOnlyFixture()50 : base(new AzuriteTestcontainerConfiguration { QueueServiceOnlyEnabled = true })51 {52 }53 }54 [UsedImplicitly]55 public sealed class AzuriteWithTableOnlyFixture : AzuriteDefaultFixture56 {57 public AzuriteWithTableOnlyFixture()58 : base(new AzuriteTestcontainerConfiguration { TableServiceOnlyEnabled = true })59 {60 }61 }62 [UsedImplicitly]63 public sealed class AzuriteWithCustomContainerPortsFixture : AzuriteDefaultFixture64 {65 public AzuriteWithCustomContainerPortsFixture()66 : base(new AzuriteTestcontainerConfiguration67 {68 BlobContainerPort = 65501,69 QueueContainerPort = 65502,70 TableContainerPort = 65503,71 })72 {73 }74 }75 [UsedImplicitly]76 public sealed class AzuriteWithCustomWorkspaceFixture : AzuriteDefaultFixture, IDisposable77 {78 public AzuriteWithCustomWorkspaceFixture()79 : base(new AzuriteTestcontainerConfiguration80 {81 Location = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("D")),82 })83 {84 if (this.Configuration.Location != null)85 {86 Directory.CreateDirectory(this.Configuration.Location);87 }88 }89 public void Dispose()90 {...
AzuriteDefaultFixture
Using AI Code Generation
1using DotNet.Testcontainers.Tests.Fixtures;2using Xunit;3{4 {5 public void Test()6 {7 }8 }9}10using DotNet.Testcontainers.Tests.Fixtures;11using Xunit;12{13 {14 public void Test()15 {16 }17 }18}19using DotNet.Testcontainers.Tests.Fixtures;20using Xunit;21{22 {23 public void Test()24 {25 }26 }27}28using DotNet.Testcontainers.Tests.Fixtures;29using Xunit;30{31 {32 public void Test()33 {34 }35 }36}
AzuriteDefaultFixture
Using AI Code Generation
1using DotNet.Testcontainers.Tests.Fixtures;2using Xunit;3{4 {5 private readonly AzuriteDefaultFixture fixture;6 public AzuriteDefaultFixtureTest(AzuriteDefaultFixture fixture)7 {8 this.fixture = fixture;9 }10 public void ShouldHaveValidEndpoint()11 {12 Assert.NotNull(this.fixture.Endpoint);13 }14 }15}16using DotNet.Testcontainers.Tests.Fixtures;17using Xunit;18{19 {20 private readonly AzuriteDefaultFixture fixture;21 public AzuriteDefaultFixtureTest(AzuriteDefaultFixture fixture)22 {23 this.fixture = fixture;24 }25 public void ShouldHaveValidEndpoint()26 {27 Assert.NotNull(this.fixture.Endpoint);28 }29 }30}31using DotNet.Testcontainers.Tests.Fixtures;32using Xunit;33{34 {35 private readonly AzuriteDefaultFixture fixture;36 public AzuriteDefaultFixtureTest(AzuriteDefaultFixture fixture)37 {38 this.fixture = fixture;39 }40 public void ShouldHaveValidEndpoint()41 {42 Assert.NotNull(this.fixture.Endpoint);43 }44 }45}46using DotNet.Testcontainers.Tests.Fixtures;47using Xunit;48{49 {50 private readonly AzuriteDefaultFixture fixture;51 public AzuriteDefaultFixtureTest(AzuriteDefaultFixture fixture)52 {53 this.fixture = fixture;54 }
AzuriteDefaultFixture
Using AI Code Generation
1using DotNet.Testcontainers.Tests.Fixtures;2using Xunit;3{4 {5 public AzuriteDefaultFixture() : base(new TestcontainersBuilder<AzuriteTestcontainer>()6 .WithImage("mcr.microsoft.com/azure-storage/azurite")7 .WithPortBinding(10000, 10000)8 .WithPortBinding(10001, 10001)9 .WithPortBinding(10002, 10002)10 .Build())11 {12 }13 }14 [CollectionDefinition("Azurite collection")]15 {16 }17}18using DotNet.Testcontainers.Tests.Fixtures;19using Xunit;20{21 [Collection("Azurite collection")]22 {23 private readonly AzuriteFixture azuriteFixture;24 public AzuriteTest(AzuriteFixture azuriteFixture)25 {26 this.azuriteFixture = azuriteFixture;27 }28 public async Task IsRunning()29 {30 Assert.True(await this.azuriteFixture.Container.IsRunningAsync());31 }32 }33}34using DotNet.Testcontainers.Tests.Fixtures;35using Xunit;36{37 [Collection("Azurite collection")]38 {39 private readonly AzuriteFixture azuriteFixture;40 public AzuriteTest(AzuriteFixture azuriteFixture)41 {42 this.azuriteFixture = azuriteFixture;43 }44 public async Task IsRunning()45 {46 Assert.True(await this.azuriteFixture.Container.IsRunningAsync());47 }48 }49}
AzuriteDefaultFixture
Using AI Code Generation
1using DotNet.Testcontainers.Tests.Fixtures;2using Xunit;3{4 {5 private readonly AzuriteDefaultFixture azuriteDefaultFixture;6 public AzuriteDefaultFixtureTest(AzuriteDefaultFixture azuriteDefaultFixture) => this.azuriteDefaultFixture = azuriteDefaultFixture;7 public void AzuriteContainerIsRunning() => Assert.True(this.azuriteDefaultFixture.Container.IsRunning);8 public void AzuriteContainerIsNotDisposed() => Assert.False(this.azuriteDefaultFixture.Container.IsDisposed);9 }10}11using DotNet.Testcontainers.Tests.Fixtures;12using Xunit;13{14 {15 private readonly AzuriteDefaultFixture azuriteDefaultFixture;16 public AzuriteDefaultFixtureTest(AzuriteDefaultFixture azuriteDefaultFixture) => this.azuriteDefaultFixture = azuriteDefaultFixture;17 public void AzuriteContainerIsRunning() => Assert.True(this.azuriteDefaultFixture.Container.IsRunning);18 public void AzuriteContainerIsNotDisposed() => Assert.False(this.azuriteDefaultFixture.Container.IsDisposed);19 }20}21using DotNet.Testcontainers.Tests.Fixtures;22using Xunit;23{24 {25 private readonly AzuriteDefaultFixture azuriteDefaultFixture;26 public AzuriteDefaultFixtureTest(AzuriteDefaultFixture azuriteDefaultFixture) => this.azuriteDefaultFixture = azuriteDefaultFixture;27 public void AzuriteContainerIsRunning() => Assert.True(this.azuriteDefaultFixture.Container.IsRunning);
AzuriteDefaultFixture
Using AI Code Generation
1using DotNet.Testcontainers.Tests.Fixtures;2using Xunit;3{4 {5 public AzuriteDefaultFixture() : base("mcr.microsoft.com/azure-storage/azurite", "3.9.0", "azurite")6 {7 }8 }9 {10 public AzuriteDefaultTest(AzuriteDefaultFixture fixture) : base(fixture)11 {12 }13 }14}15using DotNet.Testcontainers.Tests.Fixtures;16using Xunit;17{18 {19 public AzuriteDefaultFixture() : base("mcr.microsoft.com/azure-storage/azurite", "3.9.0", "azurite")20 {21 }22 }23 {24 public AzuriteDefaultTest(AzuriteDefaultFixture fixture) : base(fixture)25 {26 }27 }28}29using DotNet.Testcontainers.Tests.Fixtures;30using Xunit;31{32 {33 public AzuriteDefaultFixture() : base("mcr.microsoft.com/azure-storage/azurite", "3.9.0", "azurite")34 {35 }36 }37 {38 public AzuriteDefaultTest(AzuriteDefaultFixture fixture) : base(fixture)39 {40 }41 }42}
AzuriteDefaultFixture
Using AI Code Generation
1using DotNet.Testcontainers.Tests.Fixtures;2using Xunit;3{4 {5 private readonly AzuriteDefaultFixture fixture;6 public AzuriteTest(AzuriteDefaultFixture fixture)7 {8 this.fixture = fixture;9 }10 public void Test()11 {12 }13 }14}15using DotNet.Testcontainers.Tests.Fixtures;16using Xunit;17{18 {19 private readonly AzuriteDefaultFixture fixture;20 public AzuriteTest(AzuriteDefaultFixture fixture)21 {22 this.fixture = fixture;23 }24 public void Test()25 {26 }27 }28}
AzuriteDefaultFixture
Using AI Code Generation
1using DotNet.Testcontainers.Tests.Fixtures;2using Xunit;3{4 {5 public void Test()6 {7 var connectionString = this.ConnectionString;8 }9 }10}11using DotNet.Testcontainers.Tests.Fixtures;12using Xunit;13{14 {15 public void Test()16 {17 var connectionString = this.ConnectionString;18 }19 }20}21using DotNet.Testcontainers.Tests.Fixtures;22using Xunit;23{24 {25 public void Test()
AzuriteDefaultFixture
Using AI Code Generation
1public async Task TestMethod2()2{3 var container = new AzuriteDefaultFixture();4 await container.StartAsync();5 var blobServiceClient = new BlobServiceClient(container.ConnectionString);6 var containerClient = blobServiceClient.GetBlobContainerClient("mycontainer");7 await containerClient.CreateIfNotExistsAsync();8 var blobClient = containerClient.GetBlobClient("myblob");9 await blobClient.UploadAsync(new MemoryStream(Encoding.UTF8.GetBytes("Hello World!")));10 var blobDownloadInfo = await blobClient.DownloadAsync();11 var content = await new StreamReader(blobDownloadInfo.Value.Content).ReadToEndAsync();12 Assert.Equal("Hello World!", content);13}14Contributions are always welcome! Please read the [contribution guidelines](
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!