I have a problem with running Unit tests in visual studio. I am doing a project that is a small system for VHS rental store. I was supposed to create a DB and create objects based on this data a insert them into the list where they will be processed.
Everything works correctly in "Data Layer" project. But when I try to create a second project in Visual Studio 2019 dedicated to Unit tests and i run the same part of code from "DataLayer/program.cs" in new project i get an error:
It looks as if Tests is unable to see where "Customers.db" is located and i do not know how to fix it. Here is my App.config from DataLayer project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Default" connectionString="Data Source=.\Customers.db;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Here is part of code that i want to test:
SqliteDataAccess sqda = new SqliteDataAccess()
var list = new System.Collections.Generic.List<Customer>(sqda.GetAllCustomersFromDb());
var movies = new List<VhsMovie>(sqda.GetAllAvailableMoviesFromDb());
foreach (Customer cs in list)
{
Console.WriteLine(cs.getInfoAboutCustomer());
}
And that's the content of SqliteDataAccess.cs:
public List<VhsMovie> GetAllMoviesFromDb()
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
var output = cnn.Query<VhsMovie>("select movieTitle, ID, renterID from Movies", new DynamicParameters());
return output.ToList();
}
}
private string LoadConnectionString(string id = "Default"){
return ConfigurationManager.ConnectionStrings[id].ConnectionString;
}
I do not know why DataLayer sees Db but Test does not. Could you please help me :)