2010-02-19 24 views
1

我正在使用Joshua Flanagan的文章「Auto mocking Explained」作爲指導。在文章中有一節叫做「同樣的測試,用automocker看起來就像這樣」。我使用這些信息來構建代碼來運行automocker。
正如你可以看到下面的答案是從BLL返回的列表。答案確實有一行;但是,所有字段都是空的。所以boo的測試失敗了。任何提示和提示將不勝感激。Rhino AutoMocker和存根

[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"); 
     } 

我嘗試使用MockMode.AAA但仍然沒有喜悅

回答

1

新版本的AutoMocker(1.0.3)可用。新版本支持中繼模式,如本示例中所示。

[TestMethod] 
    public void ShouldSupportOrderedTest() 
    { 
     //Arrange 
     var autoMocker = new RhinoAutoMocker<CustomerUpdater>(); 

     var mockRepository = autoMocker.Repository; 

     using (mockRepository.Ordered()) 
     { 
      autoMocker.Get<ICustomerDataProvider>().Expect(x => x.GetCustomer(Arg<int>.Is.Anything)).Return(new CustomerItem()); 
      autoMocker.Get<ICustomerDataProvider>().Expect(x => x.UpdateCustomer(Arg<CustomerItem>.Is.Anything)); 
      autoMocker.Get<ILogWriter>().Expect(x => x.Write(Arg<string>.Is.Anything)); 
      autoMocker.Get<ILogWriter>().Expect(x => x.Write(Arg<string>.Is.Anything)); 
      autoMocker.Get<IMailSender>().Expect(x => x.SendMail(Arg<string>.Is.Anything, Arg<string>.Is.Anything)); 
     } 

     //Act 
     autoMocker.ClassUnderTest.UpdateCustomerName(1, "Frank", "[email protected]"); 

     //Assert 
     ExceptionAssert.Throws<ExpectationViolationException>(mockRepository.VerifyAll,"IMailSender.SendMail(anything, anything); Expected #1, Actual #0.\r\nILogWriter.Write(anything); Expected #1, Actual #0.\r\n"); 

    } 
0

是的,在以前的版本中是這樣。但改爲支持版本1.0.3中的有序測試。