Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit Testing in MVC not creating/accessing database
    primarykey
    data
    text
    <p>I have a solution with an MVC project containing a Services project on top of a Core project. </p> <p>I just added a Unit Tests project and referenced Core and Services - I'm trying to test Services. </p> <p>I have a basic call in the test: </p> <pre><code>public class CrudTests { private readonly SetServices _setService = new SetServices(); [TestMethod] public void TestMethod() { _setService.CreateSet("Test Set", "Test Set Details", null); </code></pre> <p>Which ends up failing because the test can't connect to a database. My config has this: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;connectionStrings&gt; &lt;add name="DefaultConnection" connectionString="Data Source=.\;Initial Catalog=Project.Services.Tests;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Project.Services.Tests.mdf" providerName="System.Data.SqlClient" /&gt; &lt;/connectionStrings&gt; &lt;/configuration&gt; </code></pre> <p>I've tried by creating the database Project.Services.Tests and then running, but I get this: </p> <blockquote> <p>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:</p> </blockquote> <p>I tried deleting the database and letting the test do it's thing, and I get this: </p> <blockquote> <p>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.</p> </blockquote> <p>How can I get this working properly?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload