我一直在使用Moq因为我过去几年的mock需要,但在看了FakeItEasy之后我想试一试。我经常想测试是否使用正确的参数调用了一个方法,但我发现使用FakeItEasy没有令人满意的方法。我有以下代码要测试:publicclassWizardStateEngine:IWizardStateEngine{privatereadonlyIWorkflowInvoker_workflowInvoker;privateList_history;publicWizardStateEngine(IWorkflowInvokerworkflowInvoker){_workflowInvoker=w
以下测试用例在rhino模拟中失败:[TestFixture]publicclassEnumeratorTest{[Test]publicvoidShould_be_able_to_use_enumerator_more_than_once(){varnumbers=MockRepository.GenerateStub();numbers.Stub(x=>x.GetEnumerator()).Return(newList{1,2,3}.GetEnumerator());varsut=newObjectThatUsesEnumerator();varcorrectResult=sut.
我有这个代码:Expect.Call(factory.CreateOrder()).Return(newOrder()).Repeat.Times(4);当它被调用四次时,每次都返回相同的实例。我想要返回不同的实例。我希望能够做类似的事情:Expect.Call(factory.CreateOrder()).Return(()=>newOrder()).Repeat.Times(4);这可以通过某种方式完成吗? 最佳答案 而不是使用.Return(newOrder());尝试使用.Do((Func)delegate(){return
我一直在尝试使用文件流来模拟使用,但未能完成此操作并且我不确定该怎么做,我正在使用rhino模拟。privateConnectionLoadConnectionDetailsFromDisk(stringbodyFile){//logicbeforeusing(FileStreamfs=File.Open(bodyFile,FileMode.Open,FileAccess.Read,FileShare.ReadWrite)){returnthis.serverConfiguration.LoadConfiguration(fs,flowProcess);}//morelogic}谁能告
嘿,人们很想知道您拥有或了解的有关nServiceBus、RhinoServiceBus和MassTransit的任何资源。视频?博客文章?书?演示项目等 最佳答案 如果您对公共(public)交通感兴趣,可以看看:GettingStartedandDocumentationElegantcodePodcast如果您使用structuremapDruSellersBlogChrisPattersonBlogTheirGoogleGroups在某些时候你会得到http://codebetter.com/blogs/dru.seller
我有一个TimeMachine类,它为我提供当前日期/时间值。该类看起来像这样:publicclassTimeMachine{publicvirtualDateTimeGetCurrentDateTime(){returnDateTime.Now;};publicvirtualDateTimeGetCurrentDate(){returnGetCurrentDateTime().Date;};publicvirtualTimeSpanGetCurrentTime(){returnGetCurrentDateTime().TimeOfDay;};}我想在我的测试中使用TimeMachin
这个问题在这里已经有了答案:Expressionreferencesamethodthatdoesnotbelongtothemockedobject(4个答案)关闭5年前。我已经使用IConfigurationRoute来访问这样的目录。if(type=="error")directory=_config.GetValue("Directories:SomeDirectory");_config是在构造函数中注入(inject)的IConfigurationRoot。我尝试了下面的方法来模拟它。varmockConfigurationRoot=newMock();mockConfig
模拟对WCF服务的调用时,出现以下错误:Method'ICustomerEntities.GetCustomerFromPhoneNumber("01234123123");'requiresareturnvalueoranexceptiontothrow.我用谷歌搜索并在这里搜索-我能找到的只是我需要重新订购各种电话等,但在我的情况下这似乎没有意义?也许有人可以向我指出它实际上确实?我的测试设置是这样的_entities=MockRepository.GenerateStrictMock();并且第三行测试方法失败,设置result2_entities.Expect(ip=>ip.G
我正在使用MOQ模拟具有预期返回列表的方法调用。我的方法返回一个列表,但我希望模拟在每次调用该方法时创建一个新列表。到目前为止我做了什么:Listexpected=newList{newCorrelation(){Code="SelfError1"},newCorrelation(){Code="SelfError2"}};MockselfMock=newMock();selfMock.Setup(f=>f.Validate()).Returns(expected);我想要实现的是让模拟在每次调用方法get时返回一个新列表。我试过这个但没用:selfMock.Setup(f=>f.Va
如何使用RhinoMocks模拟索引属性? 最佳答案 我假设您指的是使用this[]的属性varmockClass=MockRepository.GenerateMock();mockClass.Expect(m=>m["key"]).Return("value");//returnavaluemockClass.Expect(m=>m["key2"]="value2");//setavalue...sometestinhereusingsomethingthatdependsonmockClass...mockClass.Veri