I have a solution with an MVC project containing a Services project on top of a Core project.
I just added a Unit Tests project and referenced Core and Services - I'm trying to test Services.
I have a basic call in the test:
public class CrudTests
{
private readonly SetServices _setService = new SetServices();
[TestMethod]
public void TestMethod()
{
_setService.CreateSet("Test Set", "Test Set Details", null);
Which ends up failing because the test can't connect to a database. My config has this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\;Initial Catalog=Project.Services.Tests;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Project.Services.Tests.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
I've tried by creating the database Project.Services.Tests and then running, but I get this:
Message=Database 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\App.Services.Tests.mdf' already exists. Choose a different database name. Cannot attach the file 'C:\PROJECTS\App\App\Services.Tests\bin\Debug\Services.Tests.mdf' as database 'App.Services.Tests'. Source=.Net SqlClient Data Provider ErrorCode=-2146232060 Class=16 LineNumber=65536 Number=1801 Procedure="" Server=.\ State=2 StackTrace:
I tried deleting the database and letting the test do it's thing, and I get this:
A file activation error occurred. The physical file name '\Project.Services.Tests.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation.
How can I get this working properly?