Skip to content

Commit

Permalink
test: completing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Farenheith committed Oct 20, 2024
1 parent 76bef57 commit 835af1d
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Codibre.GrpcSqlProxy.Test;

[Collection("Sequential")]
public class GrpcSqlProxyClientBatchTest
{
[Fact]
Expand Down
135 changes: 135 additions & 0 deletions test/Codibre.GrpcSqlProxy.Test/GrpcSqlProxyClientErrorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using Codibre.GrpcSqlProxy.Api;
using Codibre.GrpcSqlProxy.Client;
using Codibre.GrpcSqlProxy.Client.Impl;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;

namespace Codibre.GrpcSqlProxy.Test;

public class GrpcSqlProxyClientErrorTest
{
[Fact]
public async Task Should_Throw_An_Error_For_InvalidTable()
{
// Arrange
var server = await TestServer.Get();
var client = new GrpcSqlProxyClient(
new SqlProxyClientOptions(
server.Url,
server.Config.GetConnectionString("SqlConnection") ?? throw new Exception("No connection string")
)
{
Compress = false
}
);
Exception? thrownError = null;

// Act
try
{
using var channel = client.CreateChannel();
await channel.Execute("DELETE FROM NonExistingTable");
}
catch (Exception err)
{
thrownError = err;
}

// Assert
thrownError.Should().BeOfType<SqlProxyException>();
}

[Fact]
public async Task Should_Throw_An_Error_For_InvalidSyntax()
{
// Arrange
var server = await TestServer.Get();
var client = new GrpcSqlProxyClient(
new SqlProxyClientOptions(
server.Url,
server.Config.GetConnectionString("SqlConnection") ?? throw new Exception("No connection string")
)
{
Compress = false
}
);
Exception? thrownError = null;

// Act
try
{
using var channel = client.CreateChannel();
await channel.Execute("DELETE FRO TB_PRODUTO");
}
catch (Exception err)
{
thrownError = err;
}

// Assert
thrownError.Should().BeOfType<SqlProxyException>();
}
[Fact]
public async Task Should_Throw_An_Error_For_InvalidTable_OnBatch()
{
// Arrange
var server = await TestServer.Get();
var client = new GrpcSqlProxyClient(
new SqlProxyClientOptions(
server.Url,
server.Config.GetConnectionString("SqlConnection") ?? throw new Exception("No connection string")
)
{
Compress = false
}
);
Exception? thrownError = null;

// Act
try
{
using var channel = client.CreateChannel();
channel.Batch.AddNoResultScript($"DELETE FROM NonExistingTable");
await channel.Batch.Execute();
}
catch (Exception err)
{
thrownError = err;
}

// Assert
thrownError.Should().BeOfType<SqlProxyException>();
}

[Fact]
public async Task Should_Throw_An_Error_For_InvalidSyntax_OnBatch()
{
// Arrange
var server = await TestServer.Get();
var client = new GrpcSqlProxyClient(
new SqlProxyClientOptions(
server.Url,
server.Config.GetConnectionString("SqlConnection") ?? throw new Exception("No connection string")
)
{
Compress = false
}
);
Exception? thrownError = null;

// Act
try
{
using var channel = client.CreateChannel();
channel.Batch.AddNoResultScript($"DELETE FRO TB_PRODUTO");
await channel.Batch.Execute();
}
catch (Exception err)
{
thrownError = err;
}

// Assert
thrownError.Should().BeOfType<SqlProxyException>();
}
}
1 change: 1 addition & 0 deletions test/Codibre.GrpcSqlProxy.Test/GrpcSqlProxyClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Codibre.GrpcSqlProxy.Test;

[Collection("Sequential")]
public class GrpcSqlProxyClientTest
{
[Fact]
Expand Down

0 comments on commit 835af1d

Please sign in to comment.