0

I have a web application with three layers: Web > Services > Core. I've just added a Services.Tests unit tests project and I'm trying to figure out how to get started.

I've added a reference from the Services.Tests project to the Services project. I then created an instance of the Services.service class in my Test class:

[TestClass]
public class CrudTests
{
    private readonly SetServices _setService = new SetServices();

    [TestMethod]
    public void TestMethod()
    {

But I got an error about _setService needing a reference to my Core project.

First question: Why do I need to reference my core project if the Services project already references it?

I've added the reference and ran the empty test, which passed. I then tried to call one of the basic methods within my service class:

[TestMethod]
public void TestMethod()
{
    _setService.CreateSet("Test Set", "Test Set Details", null);

But I get a providerIncompatileException.

Second question: What is the recommended way to create/use a dedicated test database?

Third question: How do I tell my tests project which database to use?

rae1
  • 6,066
  • 4
  • 27
  • 48
RobVious
  • 12,685
  • 25
  • 99
  • 181
  • In the future, try to split unrelated questions into different posts (you got at least 3). – rae1 Feb 20 '13 at 18:45

1 Answers1

1

By parts,

Why do I need to reference my core project if the Services project already references it?

Project references aren't inheritable, as per this answer. The fact that Services has a dependency on Core does not imply that whoever consumes Services needs to know anything about Core, or for that matter uses any logic exclusively defined in Core.

What is the recommended way to create/use a dedicated test database?

It depends entirely on what database, what ORM, what framework, etc. There aren't fixed ways to do it.

How do I tell my tests project which database to use?

In the same way you tell the application to do it: through the configuration. Simply create a DatabaseStub and hard-code the test database information in it.

Community
  • 1
  • 1
rae1
  • 6,066
  • 4
  • 27
  • 48