forked from testcontainers/testcontainers-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08e7fa5
commit af9043e
Showing
4 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...ntainers.Tests/Unit/Containers/Unix/Modules/Databases/MySqlTestcontainerNormalUserTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
namespace DotNet.Testcontainers.Tests.Unit | ||
{ | ||
using System.Data; | ||
using System.Threading.Tasks; | ||
using DotNet.Testcontainers.Tests.Fixtures; | ||
using Xunit; | ||
|
||
[Collection(nameof(Testcontainers))] | ||
public sealed class MySqlTestcontainerNormalUserTest : IClassFixture<MySqlNormalUserFixture> | ||
{ | ||
private readonly MySqlNormalUserFixture mySqlFixture; | ||
|
||
public MySqlTestcontainerNormalUserTest(MySqlNormalUserFixture mySqlFixture) | ||
{ | ||
this.mySqlFixture = mySqlFixture; | ||
} | ||
|
||
[Fact] | ||
public async Task ConnectionEstablished() | ||
{ | ||
// Given | ||
var connection = this.mySqlFixture.Connection; | ||
|
||
// When | ||
await connection.OpenAsync() | ||
.ConfigureAwait(false); | ||
|
||
// Then | ||
Assert.Equal(ConnectionState.Open, connection.State); | ||
} | ||
|
||
[Fact] | ||
public async Task ExecScriptInRunningContainer() | ||
{ | ||
// Given | ||
const string script = @" | ||
CREATE TABLE MyTable ( | ||
id INT(6) UNSIGNED PRIMARY KEY, | ||
name VARCHAR(30) NOT NULL | ||
); | ||
INSERT INTO MyTable (id, name) VALUES (1, 'MyName'); | ||
SELECT * FROM MyTable; | ||
"; | ||
|
||
// When | ||
var result = await this.mySqlFixture.Container.ExecScriptAsync(script) | ||
.ConfigureAwait(false); | ||
|
||
// Then | ||
Assert.DoesNotContain("ERROR", result.Stderr); | ||
Assert.Equal(0, result.ExitCode); | ||
Assert.Contains("MyName", result.Stdout); | ||
} | ||
|
||
[Fact] | ||
public async Task ThrowErrorInRunningContainerWithInvalidScript() | ||
{ | ||
// Given | ||
const string script = "invalid SQL command"; | ||
|
||
// When | ||
var result = await this.mySqlFixture.Container.ExecScriptAsync(script) | ||
.ConfigureAwait(false); | ||
|
||
// Then | ||
Assert.NotEqual(0, result.ExitCode); | ||
Assert.Contains("ERROR 1064 (42000)", result.Stderr); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters