English 中文(简体)
structureMap mocks stub help
原标题:

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

问题回答

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签