Skip to content

Commit

Permalink
test: assert compatibility with DbReader (#1054)
Browse files Browse the repository at this point in the history
* test: add new test to cover DbReader MicroORM
* fix: set Sqlite as not supported for DbReader
  • Loading branch information
Seddryck authored Jul 17, 2024
1 parent 8e26113 commit 030ee5f
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DubUrl.Core/Querying/Dialects/Casters/DateTimeCaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DateTimeCaster()
protected bool TryTruncate(DateTime value, out T? result)
{
var parse = GetMethod();
result = (T?)(parse?.Invoke(null, new object[] { value }));
result = (T?)(parse?.Invoke(null, [value]));
return parse is not null;
}
}
2 changes: 1 addition & 1 deletion DubUrl.Core/Querying/Dialects/Casters/TimeSpanCaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TimeSpanCaster()
protected bool TryTruncate(TimeSpan value, out T? result)
{
var parse = GetMethod();
result = (T?)(parse?.Invoke(null, new object[] { value }));
result = (T?)(parse?.Invoke(null, [value]));
return parse is not null;
}
}
4 changes: 2 additions & 2 deletions DubUrl.Core/Registering/BinFolderDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public virtual IEnumerable<Type> Execute()
{
var files = Assemblies.Aggregate(
Array.Empty<string>(), (seed, asm) =>
seed.Concat(new[] { asm?.Location ?? string.Empty }).ToArray()
[.. seed, .. new[] { asm?.Location ?? string.Empty }]
)
.Where(x => !string.IsNullOrEmpty(x))
.Distinct()
.Select(Path.GetDirectoryName)
.Where(Directory.Exists)
.Aggregate(
Array.Empty<string>(), (seed, location) =>
seed.Concat(Directory.GetFiles(location!)).ToArray()
[.. seed, .. Directory.GetFiles(location!)]
)
.Where(x => Path.GetExtension(x) == ".dll");

Expand Down
31 changes: 25 additions & 6 deletions DubUrl.QA/BaseAdoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using DubUrl.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Dapper;
using DubUrl.QA.Dapper;
using static DubUrl.QA.MicroOrmCustomerRepository;
using System.Linq.Expressions;
using Dapper;
using DbReader;

namespace DubUrl.QA;

Expand Down Expand Up @@ -308,12 +308,12 @@ public virtual void QueryCustomerWithDapperRepository()
using var provider = new ServiceCollection()
.AddSingleton(EmptyDubUrlConfiguration)
.AddDubUrl(options)
.AddSingleton<IDapperConfiguration>(
provider => ActivatorUtilities.CreateInstance<DapperConfiguration>(provider
.AddSingleton<Dapper.IDapperConfiguration>(
provider => ActivatorUtilities.CreateInstance<Dapper.DapperConfiguration>(provider
, new[] { ConnectionString }))
.AddTransient<ICustomerRepository, DapperCustomerRepository>()
.AddTransient<Dapper.ICustomerRepository, Dapper.DapperCustomerRepository>()
.BuildServiceProvider();
var repo = provider.GetRequiredService<ICustomerRepository>();
var repo = provider.GetRequiredService<Dapper.ICustomerRepository>();
var customers = repo.GetAllAsync().Result;
Assert.That(customers, Has.Count.EqualTo(5));
Assert.Multiple(() =>
Expand All @@ -324,4 +324,23 @@ public virtual void QueryCustomerWithDapperRepository()
Assert.That(customers.Any(x => x.BirthDate == DateTime.MinValue), Is.False);
});
}

[Test]
[Category("DbReader")]
public abstract void QueryCustomerWithDbReader();
protected void QueryCustomerWithDbReader(string sql)
{
var connectionUrl = new ConnectionUrl(ConnectionString);

using var conn = connectionUrl.Open();
var customers = conn.Read<DbReader.Customer>(sql).ToList();
Assert.That(customers, Has.Count.EqualTo(5));
Assert.Multiple(() =>
{
Assert.That(customers.Select(x => x.CustomerId).Distinct().ToList(), Has.Count.EqualTo(5));
Assert.That(customers.Any(x => string.IsNullOrEmpty(x.FullName)), Is.False);
Assert.That(customers.Select(x => x.BirthDate).Distinct().ToList(), Has.Count.EqualTo(5));
Assert.That(customers.Any(x => x.BirthDate == DateTime.MinValue), Is.False);
});
}
}
19 changes: 19 additions & 0 deletions DubUrl.QA/BaseAdomdProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,23 @@ public virtual void QueryCustomerWithDapperRepository()
Assert.That(customers.Any(x => x.BirthDate == DateTime.MinValue), Is.False);
});
}

[Test]
[Category("DbReader")]
public abstract void QueryCustomerWithDbReader();
protected void QueryCustomerWithDbReader(string sql)
{
var connectionUrl = new ConnectionUrl(ConnectionString);

using var conn = connectionUrl.Open();
var customers = conn.Query<DbReader.Customer>(sql).ToList();
Assert.That(customers, Has.Count.EqualTo(5));
Assert.Multiple(() =>
{
Assert.That(customers.Select(x => x.CustomerId).Distinct().ToList(), Has.Count.EqualTo(5));
Assert.That(customers.Any(x => string.IsNullOrEmpty(x.FullName)), Is.False);
Assert.That(customers.Select(x => x.BirthDate).Distinct().ToList(), Has.Count.EqualTo(5));
Assert.That(customers.Any(x => x.BirthDate == DateTime.MinValue), Is.False);
});
}
}
6 changes: 5 additions & 1 deletion DubUrl.QA/CockRoach/AdoProviderCockRoach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public override void QueryCustomerWithPositionalParameter()
public override void QueryCustomerWithDapper()
=> QueryCustomerWithDapper("select * from Customer");

[Test]
public override void QueryCustomerWithDbReader()
=> QueryCustomerWithDbReader("select * from Customer");

[Test]
public override void QueryCustomerWithWhereClause()
=> Assert.Ignore("Issue with lower in template");
}
}
14 changes: 14 additions & 0 deletions DubUrl.QA/DbReader/Customer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DubUrl.QA.DbReader;

internal record Customer(
int CustomerId,
string FullName,
DateTime BirthDate
)
{ }
1 change: 1 addition & 0 deletions DubUrl.QA/DubUrl.QA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DbReader" Version="2.6.0" />
<PackageReference Include="DuckDB.NET.Bindings.Full" Version="1.0.1" />
<PackageReference Include="Dapper" Version="2.1.44" />
<PackageReference Include="DuckDB.NET.Data" Version="1.0.1" />
Expand Down
4 changes: 4 additions & 0 deletions DubUrl.QA/DuckDB/AdoProviderDuckDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public override void QueryCustomerWithPositionalParameter()
public override void QueryCustomerWithDapper()
=> QueryCustomerWithDapper("select * from Customer");

[Test]
public override void QueryCustomerWithDbReader()
=> QueryCustomerWithDbReader("select * from Customer");

[Test]
public override void QueryCustomerWithWhereClause()
=> Assert.Ignore("Object of type 'DuckDB.NET.DuckDBDateOnly' cannot be converted to type 'System.DateTime'");
Expand Down
4 changes: 4 additions & 0 deletions DubUrl.QA/FirebirdSQL/AdoProviderFirebirdSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ public override void QueryCustomerWithPositionalParameter()
[Test]
public override void QueryCustomerWithDapper()
=> QueryCustomerWithDapper("select * from Customer");

[Test]
public override void QueryCustomerWithDbReader()
=> QueryCustomerWithDapper("select CustomerId as \"CustomerId\", FullName as \"FullName\", BirthDate as \"BirthDate\" from Customer");
}
6 changes: 5 additions & 1 deletion DubUrl.QA/MsSqlServer/AdoProviderMsSqlServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public override void QueryCustomerWithPositionalParameter()
public override void QueryCustomerWithDapper()
=> QueryCustomerWithDapper("select * from Customer");

}
[Test]
public override void QueryCustomerWithDbReader()
=> QueryCustomerWithDbReader("select * from Customer");

}
3 changes: 3 additions & 0 deletions DubUrl.QA/Mysql/AdoProviderMySQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ public override void QueryCustomerWithPositionalParameter()
[Test]
public override void QueryCustomerWithDapper()
=> QueryCustomerWithDapper("select * from Customer");
[Test]
public override void QueryCustomerWithDbReader()
=> QueryCustomerWithDbReader("select * from Customer");
}
4 changes: 4 additions & 0 deletions DubUrl.QA/Postgresql/BaseAdoProviderPostgresql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ public override void QueryCustomerWithPositionalParameter()
[Test]
public override void QueryCustomerWithDapper()
=> QueryCustomerWithDapper("select * from \"Customer\"");

[Test]
public override void QueryCustomerWithDbReader()
=> QueryCustomerWithDapper("select * from \"Customer\"");
}
5 changes: 4 additions & 1 deletion DubUrl.QA/PowerBiDesktop/AdomdProviderPowerBiDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ public override void QueryCustomerWithPositionalParameter()
public override void QueryCustomerWithDapper()
=> QueryCustomerWithDapper("EVALUATE SELECTCOLUMNS(Customer, \"CustomerId\" , Customer[CustomerId], \"FullName\" , Customer[FullName], \"BirthDate\" , Customer[BirthDate])");

[Test]
public override void QueryCustomerWithDbReader()
=> QueryCustomerWithDapper("EVALUATE SELECTCOLUMNS(Customer, \"CustomerId\" , Customer[CustomerId], \"FullName\" , Customer[FullName], \"BirthDate\" , Customer[BirthDate])");
//[Test]
//public override void QueryTwoYoungestCustomersWithRepositoryFactory()
// => Assert.Ignore("Not investigated why, but not working");

//[Test]
//public override void QueryCustomerWithWhereClause()
// => Assert.Ignore("Not investigated why, but not working");
}
}
4 changes: 4 additions & 0 deletions DubUrl.QA/SingleStore/AdoProviderSingleStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public override void QueryCustomerWithPositionalParameter()
[Test]
public override void QueryCustomerWithDapper()
=> QueryCustomerWithDapper("select * from Customer");

[Test]
public override void QueryCustomerWithDbReader()
=> QueryCustomerWithDbReader("select * from Customer");
}
6 changes: 5 additions & 1 deletion DubUrl.QA/Sqlite/AdoProviderSqlite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public override void QueryCustomerWithPositionalParameter()
[Test]
public override void QueryCustomerWithDapper()
=> QueryCustomerWithDapper("select * from Customer");
}

[Test]
public override void QueryCustomerWithDbReader()
=> Assert.Ignore("Not investigated");
}
4 changes: 4 additions & 0 deletions DubUrl.QA/SsasMultidim/AdomdProviderSsasMultidim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public override void QueryCustomerWithPositionalParameter()
public override void QueryCustomerWithDapper()
=> Assert.Ignore("Test not implemented");

[Test]
public override void QueryCustomerWithDbReader()
=> Assert.Ignore("Test not implemented");

[Test]
[Category("DatabaseUrl")]
[Category("Primitive")]
Expand Down
4 changes: 4 additions & 0 deletions DubUrl.QA/SsasTabular/AdomdProviderSsasTabular.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public override void QueryCustomerWithPositionalParameter()
public override void QueryCustomerWithDapper()
=> Assert.Ignore("Test not implemented");

[Test]
public override void QueryCustomerWithDbReader()
=> Assert.Ignore("Test not implemented");

[Test]
public override void QueryCustomerWithRepository()
=> Assert.Ignore("Test not implemented");
Expand Down
8 changes: 6 additions & 2 deletions DubUrl.QA/Trino/AdoProviderTrino.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public override void QueryCustomerWithPositionalParameter()
[Test]
public override void QueryCustomerWithDapper()
=> Assert.Ignore("Unable to cast object of type 'System.Int64' to type 'System.Int32'");


[Test]
public override void QueryCustomerWithDbReader()
=> Assert.Ignore("Unable to cast object of type 'System.Int64' to type 'System.Int32'");

[Test]
public override void QueryCustomerWithDapperRepository()
=> Assert.Ignore("Unable to cast object of type 'System.Int64' to type 'System.Int32'");
Expand All @@ -44,4 +48,4 @@ public override void QueryTwoYoungestCustomersWithRepositoryFactory()
//[Test]
//public override void QueryIntervalWithDatabaseUrl()
// => Assert.Ignore("Trino doesn't support 'Interval' type");
}
}

0 comments on commit 030ee5f

Please sign in to comment.