0b4f638cb9
BREAKING CHANGE: The previous abstraction was confusing/misleading and was forcefully registering all connections as transient. These changes invert the relationship a bit and change the injectable INonTransactionalDbConnection<TConnectionType> into scoped. It also allows us to provide an explicit connection factory for Sqlite and an extension method that's easier to use while preserving the very slim nature of the core data access package.
40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using FruityFoundation.DataAccess.Abstractions;
|
|
using FruityFoundation.DataAccess.Sqlite;
|
|
|
|
namespace FruityFoundation.Tests.DataAccess.Sqlite;
|
|
|
|
public class SqliteDbConnectionFactoryTests
|
|
{
|
|
[Test]
|
|
public void CreateConnection_WithValidConnectionString_ReturnsNonTransactionalDbConnection_ReadWrite()
|
|
{
|
|
// Arrange
|
|
var connectionFactory = new SqliteDbConnectionFactory(
|
|
serviceProvider: null!,
|
|
getReadWriteConnectionString: _ => "Data Source=:memory:",
|
|
getReadOnlyConnectionString: null!);
|
|
|
|
// Act
|
|
var result = connectionFactory.CreateConnection();
|
|
|
|
// Assert
|
|
Assert.That(result, Is.InstanceOf<INonTransactionalDbConnection<ReadWrite>>());
|
|
}
|
|
|
|
[Test]
|
|
public void CreateReadOnlyConnection_WithValidConnectionString_ReturnsNonTransactionalDbConnection_ReadOnly()
|
|
{
|
|
// Arrange
|
|
var connectionFactory = new SqliteDbConnectionFactory(
|
|
serviceProvider: null!,
|
|
getReadWriteConnectionString: null!,
|
|
getReadOnlyConnectionString: _ => "Data Source=:memory:");
|
|
|
|
// Act
|
|
var result = connectionFactory.CreateReadOnlyConnection();
|
|
|
|
// Assert
|
|
Assert.That(result, Is.InstanceOf<INonTransactionalDbConnection<ReadOnly>>());
|
|
}
|
|
}
|