jeudi 27 août 2015

C#: test a method with an object parameter implementing a private interface

I have a first project with a method that returns a Model object instance implemented with a private class PrivateModel inheriting Model and a private interface IFoo.

Sample:

Project1:

public class Model {}
private interface IFoo {}
private class PrivateModel : Model, IFoo {}

// a sample class with the returning method
public class Bar
{
    public static Model CreateModelInstance()
    { return new PrivateModel(); }

    // code...
}

Project2:

// get model instance
var model = Bar.CreateModelInstance(); // return a Model

The second project calls a method "Act" with the model parameter, but Act's implementation tests if the model is a PrivateModel (with the IFoo implementation).

Project1:

public class Bar
{
    // code...

    public static bool Act(Model model)
    {
        // sample logic
        return model is IFoo;
    }
}

Now the question:

Because I have to test a method that performs calls to Act method (it's static), and I can't moke up it, I have to build an object that implements IFoo (that is private). Can I implement a class similar to TestClass: IFoo into the test project (a third project), or I have to use a Model returned from the Project1?

Aucun commentaire:

Enregistrer un commentaire