Question: How do I create unit tests for out parameters of a private function?

My service layer:

```
private int LoadProduct(string productId, out IProduct product)
{
    product = this.Load(productId);

    return ErrorCodes.Success;
}

```

Test case:

```
[Test]
public void LoadProductTest()
{
    var offerService = new OfferProcessor();
    var privateOfferService = new PrivateObject(offerService);

    IProduct myProduct = null;

    var result = (int)privateOfferService.Invoke("LoadProduct", 
                       new object[] {"AnId", myProduct });

    Assert.That(result, Is.EqualTo(ErrorCodes.Success));
    Assert.That(myProduct, Is.NotNull());
}

```

The above test case does not compile. How do I pass Invoke an out parameter and then access it after the call?

Answer: 
try saving the object array that you pass the invoke call.

```
object[] args = new object[] { "AnId", myProduct };
var result = (int)privateOfferService.Invoke("LoadProduct", args);
Assert.That(args[1], Is.NotNull());

```

<https://stackoverflow.com/a/2438069/1311351>
I believe it's considered good practice to return the actual object, and not use error codes for return values. If there is an error, throw an exception. And if you return the actual business object, you won't have this issue.

Since you don't say what about your code doesn't compile, I'm assuming your test method can't access the private method. VS will allow you to test private methods if you do this (right-click in the method and choose Create Unit Tests...):

![enter image description here](https://i.stack.imgur.com/r7btv.png)