tags:

views:

101

answers:

1

I am using Joshua Flanagan article “Auto mocking Explained” as a guide. In the article there is a section called “The same tests, with automocker would look like this”. I used this information to build code to run the automocker.
As you can see below answer is a list returned from the BLL. Answer does have one row in it; however, all fields are null. So the test for boo fails. Any tips and hints would be greatly appreciated.

[Test]
        public void GetStaffListAndRolesByTeam_CallBLLWithDALStub()
        {
            // Build List<> data for stub
            List<StaffRoleByTeamCV> stubData = new List<StaffRoleByTeamCV>();
            StaffRoleByTeamCV stubRow = new StaffRoleByTeamCV();
            stubRow.Role = "boo";
            stubRow.StaffId = 12;
            stubRow.StaffName = "Way Cool";
            stubData.Add(stubRow);

            // create the automocker
            var autoMocker = new RhinoAutoMocker<PeteTestBLL>();

            // get instance of test class (the BLL)
            var peteTestBllHdl = autoMocker.ClassUnderTest;

            // stub out call to DAL inside of BLL
            autoMocker.Get<IPeteTestDAL>().Stub(c => c.GetStaffListAndRolesByTeam("4146")).Return(stubData);

            // make call to BLL this should return stubData
            List<StaffRoleByTeamCV> answer = peteTestBllHdl.GetStaffListAndRolesByTeam("4146");

            // do simple asserts to test stubData present
            // this passes
            Assert.IsTrue(1 == answer.Count,  "Did not find any rows"); 
            // this fails
            Assert.IsTrue(answer[0].Role == "boo", "boo was not found");  
        }

I tried using MockMode.AAA but still no joy

A: 

I haven't tried, but this article suggests that by default all the mocks created by automocker are not replayed: http://www.lostechies.com/blogs/joshuaflanagan/archive/2008/09/25/arrange-act-assert-with-structuremap-rhinoautomocker.aspx

Grzenio