jeudi 19 février 2015

'Could not open connection' when testing a web app running against a SQLite Database

On a project my team is working on, I am trying to write SpecFlow feature tests for a web project. When we're running these feature tests, though, both the website and the test project are connecting to a local SQLite database.


However, I'm getting a "Could not open database file" exception when running the steps that pre-seed my data (in the below scneario, my first step.)


Feature:



Scenario: Example Feature
Given the following employee exists
| Last Name | First Name | Office Building | Department |
| Smith | John | Fargo | Accounting |
And I view the first screen for the following
| Office Building | Department |
| Fargo | Accounting |
And I select the first available employee
And I assign the employee to cubicle 01
And I enter effective date today
When I click save
Then the cubicle assignment appears in the list of assignments
| Office Building | Cubicle | Effective Date | Employee |
| Fargo | 01 | today | Smith, John |


That step's code looks sort of like this (repeated code has been omitted, for brevity):


FloorPlanSteps.cs:



[Given(@"The following employee exists")]
public void GivenTheFollowingEmployeeExists(Table employeeInfo)
{
var employeeRow = employeeInfo.Rows[0];
string employeeName = employeeRow["Last Name"] + ", " + employeeRow["First Name"];
// Link the other columns to variables.

// Failing on this statement!
FloorPlan plan = FloorPlanRepository.GetPlan(officeBuilding, department);
if(plan == null)
{
plan = new Plan
{
OfficeBuilding = officeBuilding,
Department = department
};
FloorPlanRepository.Save(plan);
}

// Repeat as necessary until tables for this step are seeded.
}


The actual exception is happening at a lower level than our repository, though. We have a DataContext.cs file that helps us to more easily use NHibernate to set up connections. In there is a method, InitializeSessionFactory(), which is where I'm actually seeing the exception occur:


DataContext.cs:



private static bool InitializeSessionFactory()
{
try
{
Configuration configuration = BuildConfiguration();
// Attempting to run the below line triggers the 'Could not open database exception...
_sessionFactory = configuration.BuildSessionFactory();
return true;
}
catch (Exception ex)
{
return string.IsNullOrEmpty(ex.Message);
}
}


Given that I've ensured that the folder and file have read/write permissions enabled, and a well-formed connection string, all I can figure is that something else - most likely the web project - is preventing the test project from connecting to the database, and being able to perform any kind of data access.


Question: If I'm running my web project against the SQLite database, will it prevent my feature test project from being able to do direct database manipulation, like I'm seeing? If this is the case, is there any way that I can have both the web project and the feature test project hitting the same SQLite database?


Aucun commentaire:

Enregistrer un commentaire