samedi 27 juin 2015

Castle windsor to use a fakeiteasy object while Resolving in Unit test

I am very noob in both FakeItEasy and Castle Windsor and that is why i am having problem even in searching Google as i don't know the keywords to search for.

Now coming to the problem

I am having a class

public class PersonService : IPersonService
{
    IMarriageHelper objIMarriageHelper;
    IPersonRepository objIPersonRepository;
    public PersonService(IMarriageHelper objMarriageHelper, IPersonRepository objPersonRepository)
    {
        this.objIMarriageHelper = objMarriageHelper;
        this.objIPersonRepository = objPersonRepository;
    }

}

Now I am using Castle Windsor to resolve my PersonService class in unit test case.

        var objContainer = new WindsorContainer();
        objContainer.Register(Component.For<PersonService>());
        objContainer.Register(Component.For<IMarriageHelper>().ImplementedBy<MarriageHelper>());
        objContainer.Register(Component.For<IPersonRepository>().ImplementedBy<PersonRepository>());
        var objPersonService = objContainer.Resolve<PersonService>();

Now the problem is I want to send fake object of PersonRepository while resolving PersonService but not MarraigeHelper.

Pleas help me out with this as I am very new to this.

Aucun commentaire:

Enregistrer un commentaire