-
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
76bef57
commit 835af1d
Showing
3 changed files
with
137 additions
and
0 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
135 changes: 135 additions & 0 deletions
135
test/Codibre.GrpcSqlProxy.Test/GrpcSqlProxyClientErrorTest.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,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>(); | ||
} | ||
} |
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