How do I use an API of a windows service?

83 views Asked by At

I've got a big windows service application. It performs actions on a time bound basis. Sometimes I need to be able to use some of it's functionality in isolation from the rest of the application. Currently I've got a battery of 'unit tests' which call into various sources and perform the desired functionality. My problem is these are not unit tests, they are the way we're exposing the API. If we run all the unit tests in the project, we'll be damaging some of our production data.

My question is how do I go about accessing some of the functionality of the application without unit testing? I was thinking of perhaps something like an interpreter over the top of it where you can call various parts of the functionality, but am not really that sure where to start.

An example of a unit test in our code will be:

[TestMethod]
public void TransferFunds()
{
    int accountNumberTo = 123456;
    int accountNumberFrom = 654321;
    var accountFrom = Store.GetAccount(accountNumberFrom);
    var accountTo = Store.GetAccount(accountNumberTo);
    double amountToTransfer = 1000;
    DateTime transactionDate = new DateTime(2010,01,01);
    Store.TransferFunds(accountFrom, AccountTo, amountToTransfer, transactionDate);
    var client = BankAccountService.Client();
    client.Contribute(accountNumberTo, amountToTransfer, transactionDate);
    client.Contribute(accountNumberFrom, amountToTransfer, transactionDate);
}

How can we move this out of unit tests, but still have the ability to run code like this?

1

There are 1 answers

2
Morten On

Your setup sounds very dangerous. I would create separate console applications for your different needs. I would also remove recommend that you remove all unittests that endangers your production data. Having that sort of unittests is just down-right bad!