Open
Description
Use case:
- DB-First
- Model generated by dotnet ef cli tool with "scaffold"
To help with making sure the generated model is valid with the sql server provider there should be a method to help out with that.
Maybe we need a new project for sql server specific thing in testing or we would need to add the nuget package for the sql server to the general testing package (which i would not prefer).
Code could look something like this:
var builder = new DbContextOptionsBuilder<MyDbContext>();
builder.UseSqlServer("Server=.;Database=404;Connection Timeout=1;Command timeout=1");
using var ctx = new MyDbContext(builder.Options);
var action = () => ctx.AnyTable.FirstOrDefault();
action.Should().ThrowExactly<SqlException>().WithMessage(
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)");
This test or method would throw exceptions if the model has some issues with the sql server provider, so one can fix them right away.
- Decide where to put this functionality for helping out with testing db models used in sql server
- Implement and provide the functionality described