[C#] Ensuring Project A starts when Project B needs it...

Caporegime
Joined
18 Oct 2002
Posts
29,493
Location
Back in East London
Howdy.. I've got two projects, one with my WCF service (Project A), another with my "test" client (Project B) that communicates with said service. Both are in the same solution.

As we are using automated integration/testing.. it'd be nice to have a simple line in our tests to "start" Project A when we are using the tests in Project B.

Setting Project A as a dependency of Project B doesn't do the trick.

Something like..
Code:
Assembly.StartProject("Project A");
or whatever :)

Anyone know of something?
 
Last edited:
Just change the solution settings to start both projects in the correct order. I have a very similar scenario to you open as I type.
 
Last edited:
See, I guess I wasn't specific enough.. Project B never actually "starts" .. only the tests are run within it. And to complicate things a little further, we aren't using MSTest, we are using NUnit. :)
 
Pre/post build events?

Edit: Or could you just have your TextFixtureSetUp start the service? Might be a bit slow and smells a bit of an integration test....
 
It is an integration test :)

I don't know what to put into my SetUp to start the service, hence this thread I guess :)
 
Create a Project C that contains the code that comprises the WCF service i.e. the code to be executed AND tested.

Project A is left with a small amount of boilerplate/bootstrapper code and references Project C.

Project B, of course, contains your tests and references Project C.
 
I'm not sure that solves the problem, perhaps I am misunderstanding. Project A is nothing but the WCF service, and Project B is nothing but tests with a Service Reference to what is effectively Project A.

a quick example of what happens:

A snippet from Service project:
Code:
[ServiceContract]
interface IWebService
{
  [OperationContract]
  public string DoSomething(string anArg);
}

public class WebService : IWebService
{
  public string DoSomething(string anArg)
  {
    if (anArg == "foo") return "bar";
    return null;
  }
}
Snippet from Tests project (with a service reference to Service project):
Code:
[TestFixture]
public class TestService
{
  public WebService Service;

  [SetUp]
  public void SetUp
  {
    Service = new WebServiceClient();
  }

  [Test]
  public void TestDoSomething()
  {
    var result = Service.DoSomething("foo");
    Assert.That(result, Is.EqualTo("bar"));
  }
}
But the test times out because the Service project has not started.
 
Self-host the services from the test itself. The only way you can do that (without violating DRY) is to create a third project which contains your WCF code that will be shared between the tests and the main entry point.
 
So other than instantiating a service host (and keep it in 'Project C' as you rightly say) there isn't simply a way to just start the project? :) I was hoping there was a way to do it similar to how the IDE starts the project when I update my service reference in project B, project A automatically starts (as it is updating a design time localhost URI)
 
Nope. And even if there is some hacky way to do it. You don't want to rely on the IDE's rather bespoke behaviour for loading these type of WCF services because you won't then be able to have your tests run on an automated basis (i.e. continuous integration).
 
I haven’t used WCF before, but I believe it is just hosted in ASP.NET? You can start the ASP.NET Development web server from the command line (VS2010 location):
C:\Program Files\Common Files\microsoft shared\DevServer\10.0\WebDev.WebServer40.EXE /port:8081 /path:"<path to the root>"
 
The Development web server is for development. It isn't testing or CI friendly.

WCF services can be self-hosted. ASP.NET is, for whatever reason, the most popular way of hosting them but it isn't the only way.

It's easy to do. He just needs to make his test project self-host his WCF services. And then it can connect to them to perform integration tests.
 
Back
Top Bottom