我假设您熟悉official documentation,我认为这非常好。
我的建议是尝试使用 Rhino,当你遇到一些更具体的问题时,在 SO 或其他地方搜索解决方案。我不认为 Rhino 模拟有一个全面的备忘单。我想你会更幸运地问“我如何使用 Rhino Mocks 做到这一点和那个”
编辑:
好吧,当你定位 AAA 时,你不需要使用 Record/Playback。
AAA 涉及三个步骤:
.
IOmicronDll mockWrapper = MockRepository.GenerateMock<IOmicronDll>();
mockWrapper.Expect(wrapper => wrapper.Lock(1, ref errors)).OutRef(string.Empty).Return(true).Repeat.Any();
mockWrapper.Expect(wrapper => wrapper.Exec(1, "sys:cfg?(type)", ref output, ref errors)).OutRef("1,CMC 56,0;", "").Return(true).Repeat.Any();
mockWrapper.Expect(wrapper => wrapper.Exec("1", "sys:cfg?(type)", ref output, ref errors)).OutRef("1,CMC 56,0;", "").Return(true).Repeat.Any();
Microsoft.Practices.Unity.UnityContainer c = new Microsoft.Practices.Unity.UnityContainer();
c.RegisterInstance<IOmicronDll>(mockWrapper);
.
Assert.AreEqual("CMC 56", omicron.Type);
mockWrapper.AssertWasCalled(wrapper => wrapper.Release(), options => options.Repeat.AtLeastOnce());
也许上面的例子不是最好的,但可能会让你进入正确的方向。