Reputation: 6707
I am using NUnit as my testing framework and I want to test an oracle query on specific testing data. I want to pull a dependency from nuget and run an in memory database to tests my query. I assume my query is sql compatible so I think I do not need to test against oracle directly.
My search so far resulted in this wiki entry where it looks like there is no suitable in memory database.
I also found that "Microsoft.EntityFrameworkCore.InMemory" could be used for certain scenarios and I think mine is not one of them.
To give some context - here is a test implementation that would miss the database.
using NUnit.Framework;
using System.Linq;
using System.Collections.Generic;
[TestFixture]
public class ExampleFixture
{
public class JobData { public string Name { get; set; } }
public string queryUnderTest = "select j.name, j.updated from T_JOB j where j.name like '%TEST%'";
[Test]
public void TestQuery()
{
var expected = new[] { new JobData { Name = "-TEST-" } };
var Data = expected.Concat(new[] { new JobData { Name = "OTHER" } });
var dataBase = MakeInMemoryDataBase();
WriteTable(dataBase, "T_JOB", Data);
var actual = QueryAndMakeJobs(dataBase, queryUnderTest);
CollectionAssert.AreEquivalent(expected, actual);
}
private IEnumerable<JobData> QueryAndMakeJobs(object dataBase, string queryUnderTest) => Enumerable.Empty<JobData>();
private void WriteTable(object imdb, string tablename, IEnumerable<JobData> data) {}
private object MakeInMemoryDataBase() => null;
}
I am restricted to open source dependencies that I can pull from nuget.org. My only other option would be to run an open source db from hub.docker.com.
Upvotes: 2
Views: 1060
Reputation: 1062745
Frankly, this isn't useful as a unit test; it is an integration test, as it fundamentally needs the appropriate server. Testing it against a completely different in-memory implementation is not a useful test - it tells you nothing about whether it will actually work, unless you're using that in-memory implementation for real in some scenario in your application. RDBMS implementations are touchy.
IMO you should focus on getting the appropriate actual RDBMS running in your test environment in some reproducible way.
Upvotes: 2