views:

33

answers:

1

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor) and another like this=>InsertJCDC(fakeBox).

When I stub out the parent I want to return fakePor. But when I run the code it returns null instead. Here is the unit test.

[Test]
        public void PorBLL_InsertByPorInsertCV_DoingGoodCase()
        {
            // Startup object mapper
            _Bootstrapper.Bootstrap();

            // create the mock for generic Crud
            IGenericCrud mockGenericCrud = MockRepository.GenerateMock<IGenericCrud>();
            PorInsertCV fakePor = new PorInsertCV();
            PorBoxInsertCV fakeBox = new PorBoxInsertCV();

            // build fake return
            PorEO fakePorNewRow = new PorEO();
            fakePorNewRow.PorId = 22;

            // stub parent and child insert routines.
            mockGenericCrud.Stub(c => c.InsertJCDC<PorEO, PorInsertCV>(fakePor)).Return(fakePorNewRow);
            mockGenericCrud.Stub(c => c.InsertJCDC<PorBoxEO, PorBoxInsertCV>(fakeBox)).Return(null);
            ObjectFactory.Inject(typeof(IGenericCrud), mockGenericCrud);
            IPorBLL localWithMock = ObjectFactory.GetInstance<IPorBLL>();

            // build user args to csll bll with and use for insert
            PorInsertCV userArgs = new PorInsertCV();
            userArgs.AccessionNbr = "364-80-0007";
            userArgs.NbrBoxes = 11;
            userArgs.RegId = 20;
            userArgs.TransmitedDt = Convert.ToDateTime("1/30/1980");

            // call the bll using the stub
            localWithMock.InsertByPorInsertCV(userArgs);
        }

Any help is greatly appreciated

A: 

I can't really follow your code that well, but I'll give it a shot.

From my skills of deduction, this line here is the one giving you issues:

mockGenericCrud.Stub(c => c.InsertJCDC<PorEO, PorInsertCV>(fakePor)).Return(fakePorNewRow);

Because you're expecting fakePorNewRow to be returned when you call localWithMock.InsertByPorInsertCV(userArgs); - yeah?

If that's your case, what your problem is, is that it will only return fakePorNewRow when it is given fakePor ... not userArgs as you have given it.

Tell me if I'm completely off track.

HTHs,
Charles

Ps. You might want to add the tag of which mocking framework you are using to the question.

Charlino