Put interface behind database provider for testing. Use state object to get data from database, then map to model.
This commit is contained in:
parent
5a0d0933ce
commit
20ccdd07f1
11 changed files with 118 additions and 34 deletions
32
Website.Tests/Data/MySQLDatabaseProviderTests.cs
Normal file
32
Website.Tests/Data/MySQLDatabaseProviderTests.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using Website.Data;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
using MySql.Data.MySqlClient;
|
||||
using NSubstitute;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Website.Tests.Data
|
||||
{
|
||||
public class MySQLDatabaseProviderTests
|
||||
{
|
||||
const string ConnectionString = "Server=host;User ID=username;Password=password;Database=database";
|
||||
|
||||
[Fact]
|
||||
public void NewConnection_WithStringConstructor_ReturnsMySQLConnection() {
|
||||
var provider = new MySQLDatabaseProvider(ConnectionString);
|
||||
var connection = provider.NewConnection();
|
||||
connection.Should().BeOfType<MySqlConnection>();
|
||||
(connection as MySqlConnection).ConnectionString.Should().Be(ConnectionString);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NewConnection_WithConfigConstructor_ReturnsMySQLConnection() {
|
||||
var config = Substitute.For<IConfiguration>();
|
||||
config.GetConnectionString("database").Returns(ConnectionString);
|
||||
var provider = new MySQLDatabaseProvider(ConnectionString);
|
||||
var connection = provider.NewConnection();
|
||||
connection.Should().BeOfType<MySqlConnection>();
|
||||
(connection as MySqlConnection).ConnectionString.Should().Be(ConnectionString);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,7 +12,9 @@
|
|||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="fluentassertions" Version="5.6.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
|
||||
<PackageReference Include="mysqlconnector" Version="0.52.0" />
|
||||
<PackageReference Include="nsubstitute" Version="4.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue