Skip to content

Commit

Permalink
Merge branch 'FirebirdSQL:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gilsonjoanelo authored Jan 12, 2025
2 parents 7b69cd2 + 59cfb1f commit a7574a0
Show file tree
Hide file tree
Showing 23 changed files with 1,062 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@
<OutputType>Exe</OutputType>
<StartupObject>FirebirdSql.Data.TestsBase.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Using Include="NUnit.Framework.Legacy.ClassicAssert" Alias="Assert" />
<Using Include="NUnit.Framework.Legacy.CollectionAssert" Alias="CollectionAssert" />
<Using Include="NUnit.Framework.Legacy.StringAssert" Alias="StringAssert" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net8.0'">
<!-- left in repo as an example/documentation for .NET Framework -->
<None Remove="app.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnitLite" Version="3.13.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnitLite" Version="4.2.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EntityFramework.Firebird\EntityFramework.Firebird.csproj" />
Expand Down
86 changes: 86 additions & 0 deletions src/FirebirdSql.Data.FirebirdClient.Tests/BlobStreamTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
using FirebirdSql.Data.TestsBase;
using NUnit.Framework;

namespace FirebirdSql.Data.FirebirdClient.Tests;

[TestFixtureSource(typeof(FbServerTypeTestFixtureSource), nameof(FbServerTypeTestFixtureSource.Default))]
[TestFixtureSource(typeof(FbServerTypeTestFixtureSource), nameof(FbServerTypeTestFixtureSource.Embedded))]
public class BlobStreamTests : FbTestsBase
{
public BlobStreamTests(FbServerType serverType, bool compression, FbWireCrypt wireCrypt)
: base(serverType, compression, wireCrypt)
{ }

[Test]
public async Task FbBlobStreamReadTest()
{
var id_value = RandomNumberGenerator.GetInt32(int.MinValue, int.MaxValue);
var insert_values = RandomNumberGenerator.GetBytes(100000 * 4);

await using (var transaction = await Connection.BeginTransactionAsync())
{
await using (var insert = new FbCommand("INSERT INTO TEST (int_field, blob_field) values(@int_field, @blob_field)", Connection, transaction))
{
insert.Parameters.Add("@int_field", FbDbType.Integer).Value = id_value;
insert.Parameters.Add("@blob_field", FbDbType.Binary).Value = insert_values;
await insert.ExecuteNonQueryAsync();
}
await transaction.CommitAsync();
}

await using (var select = new FbCommand($"SELECT blob_field FROM TEST WHERE int_field = {id_value}", Connection))
{
await using var reader = await select.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
await using var output = new MemoryStream();
await using (var stream = reader.GetStream(0))
{
await stream.CopyToAsync(output);
}

var select_values = output.ToArray();
CollectionAssert.AreEqual(insert_values, select_values);
}
}
}

[Test]
public async Task FbBlobStreamWriteTest()
{
var id_value = RandomNumberGenerator.GetInt32(int.MinValue, int.MaxValue);
var insert_values = RandomNumberGenerator.GetBytes(100000 * 4);

await using (var transaction = await Connection.BeginTransactionAsync())
{
await using (var insert = new FbCommand("INSERT INTO TEST (int_field, blob_field) values(@int_field, @blob_field)", Connection, transaction))
{
insert.Parameters.Add("@int_field", FbDbType.Integer).Value = id_value;
insert.Parameters.Add("@blob_field", FbDbType.Binary).Value = insert_values;
await insert.ExecuteNonQueryAsync();
}

await using (var select = new FbCommand($"SELECT blob_field FROM TEST WHERE int_field = {id_value}", Connection, transaction))
{
await using var reader = await select.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
await using var stream = reader.GetStream(0);
await stream.WriteAsync(insert_values);

break;
}
}
await transaction.CommitAsync();
}

await using (var select = new FbCommand($"SELECT blob_field FROM TEST WHERE int_field = {id_value}", Connection))
{
var select_values = (byte[])await select.ExecuteScalarAsync();
CollectionAssert.AreEqual(insert_values, select_values);
}
}
}
1 change: 1 addition & 0 deletions src/FirebirdSql.Data.FirebirdClient.Tests/FbBlobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public async Task BinaryBlobTest()
insert.Parameters.Add("@blob_field", FbDbType.Binary).Value = insert_values;
await insert.ExecuteNonQueryAsync();
}

await transaction.CommitAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public async Task ReadBinaryTest()
{
bytes[i] = (byte)random.Next(byte.MinValue, byte.MaxValue);
}
var binaryString = $"x'{BitConverter.ToString(bytes).Replace("-", string.Empty)}'";
var binaryString = $"x'{Convert.ToHexString(bytes)}'";

await using (var command = new FbCommand($"select {binaryString} from TEST", Connection, transaction))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public void EqualityFalse(FbZonedDateTime expected, FbZonedDateTime actual)
Assert.AreNotEqual(expected, actual);
}

[Test]
public void ConvertToDateTimeShouldNotThrow()
{
var fbZonedDateTime = new FbZonedDateTime(new DateTime(2020, 12, 4, 10, 38, 0, DateTimeKind.Utc), "UTC");

Assert.DoesNotThrow(() => Convert.ChangeType(fbZonedDateTime, typeof(DateTime)));
}

public void DateTimeShouldBeUtc()
{
Assert.Throws<ArgumentException>(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ public void EqualityFalse(FbZonedTime expected, FbZonedTime actual)
{
Assert.AreNotEqual(expected, actual);
}

[Test]
public void ConvertToTimeSpanShouldNotThrow()
{
var fbZonedTime = new FbZonedTime(TimeSpan.FromMinutes(142), "UTC");

Assert.DoesNotThrow(() => Convert.ChangeType(fbZonedTime, typeof(TimeSpan)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
<StartupObject>FirebirdSql.Data.TestsBase.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnitLite" Version="3.13.3" />
<Using Include="NUnit.Framework.Legacy.ClassicAssert" Alias="Assert" />
<Using Include="NUnit.Framework.Legacy.CollectionAssert" Alias="CollectionAssert" />
<Using Include="NUnit.Framework.Legacy.StringAssert" Alias="StringAssert" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnitLite" Version="4.2.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FirebirdSql.Data.FirebirdClient\FirebirdSql.Data.FirebirdClient.csproj" />
Expand Down
Loading

0 comments on commit a7574a0

Please sign in to comment.