J'utilise l'article de Joshua Flanagan "Auto Mocking Explained" comme guide. Dans l'article il y a une section appelée "Les mêmes tests, avec automocker ressemblerait à ceci". J'ai utilisé cette information pour construire le code pour exécuter le automocker.
Comme vous pouvez le voir ci-dessous, la réponse est une liste renvoyée par le BLL. La réponse a une rangée dedans; Cependant, tous les champs sont NULL. Donc, le test de boo échoue. Tous les conseils et astuces seraient grandement appréciés.Rhino AutoMocker et Stubs
[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");
}
J'ai essayé d'utiliser MockMode.AAA mais toujours pas de joie