rhino-mocks

Is it possible to create a mock object that implements multiple interfaces with EasyMock?

烂漫一生 提交于 2019-11-30 07:50:02
Is it possible to create a mock object that implements several interfaces with EasyMock? For example, interface Foo and interface Closeable ? In Rhino Mocks you can provide multiple interfaces when creating a mock object, but EasyMock's createMock() method only takes one type. Is it possbile to achieve this with EasyMock, without resorting to the fallback of creating a temporary interface that extends both Foo and Closeable , and then mocking that? EasyMock doesn't support this so you're stuck with fallback of the temporary interface. As an aside, I smell a little bit of a code wiff - should a

Rhino Mocks AssertWasCalled (multiple times) on property getter using AAA

試著忘記壹切 提交于 2019-11-30 07:48:46
I have a mocked object that is passed as a constructor argument to another object. How can I test that a mocked object's property has been called? This is code I am using currently: INewContactAttributes newContact = MockRepository.GenerateMock<INewContactAttributes>(); newContact.Stub(x => x.Forenames).Return("One Two Three"); someobject.ConsumeContact(newContact); newContact.AssertWasCalled(x => { var dummy = x.Forenames; }); This works except when within the "someobject" the getter on Forenames property is used multiple times. That's when I get "Rhino.Mocks.Exceptions

How to use Rhino Mocks to Mock an HttpContext.Application

我是研究僧i 提交于 2019-11-30 04:02:13
I'm new to Mocking frameworks and have started using RhinoMocks to assist with my MVC App Unit Testing. I'm using Scott Hanselmanns MVC Mock Helper to assist in mocking the HttpContext. I've succesfully (after some time) mocked some of what I need but have come unstuck when it comes to the Application property of the HttpContext. In my application I store an object in the Application and retrieve it within a Controller like: SomeObj foo = (SomeObj)Application["fooKey"]; This gets created on Application_Start in my MVC App. UPDATED FOLLOWING FIRST ANSWER (additional code for clarity) Currently

What is the AAA syntax equivalent to using Ordered() in Rhino Mocks

有些话、适合烂在心里 提交于 2019-11-30 03:21:29
问题 I can't for the life of me find the proper syntax using the Fluent/AAA syntax in Rhino for validating order of operations. I know how to do this with the old school record/playback syntax: MockRepository repository = new MockRepository(); using (repository.Ordered()) { // set some ordered expectations } using (repository.Playback()) { // test } Can anyone tell me what the equivalent to this in AAA syntax for Rhino Mocks would be. Even better if you can point me to some documentation for this.

Stubbing or Mocking ASP.NET Web API HttpClient

a 夏天 提交于 2019-11-30 01:31:05
I am using the new Web API bits in a project, and I have found that I cannot use the normal HttpMessageRequest , as I need to add client certificates to the request. As a result, I am using the HttpClient (so I can use WebRequestHandler ). This all works well, except that it isn't stub/mock friendly, at least for Rhino Mocks. I would normally create a wrapper service around HttpClient that I would use instead, but I would like to avoid this if possible, as there are a lot of methods that I would need to wrap. I am hoping that I have missing something—any suggestions on how to stub HttpClient ?

How to Construct IdentityResult With Success == true

房东的猫 提交于 2019-11-30 00:15:00
问题 I have a class with Microsoft.AspNet.Identity.UserManager injected, and I want to expect the userManager.CreateAsync(user, password) method to return a Task where the IdentityResult.Succeeded = true. However, the only available constructors for IdentityResult are failure constructors that will cause Succeeded property to be false. How does one create an IdentityResult that has Succeeded == true? IdentityResult doesn't implement an interface and Succeeded isn't virtual so I don't see any

What are the capabilities of Moq and Rhino.mocks?

*爱你&永不变心* 提交于 2019-11-29 19:12:36
I cannot find a specific feature-by-feature comparison of Moq and Rhino. All the questions are "which do you like better and why", or "here's how you do a simple mock in rhino and how it's done in moq". I cannot find a deep comparison anywhere. I'm aware of the syntax differences, I'm not looking for answers about that. I am looking for a capability comparison . For example: Rhino has Expect.On() for threaded mocking. Can Moq do this? What about Multi-mocking (implementing multiple interfaces with one mock). Can Moq do this? I believe Moq can now mock Protected members. Can Rhino do this? Edit

Rhino Mocks stubs and mocks are only good for interfaces?

不想你离开。 提交于 2019-11-29 16:26:55
问题 Is it correct that Rhino Mocks stubs and mocks are only good for interfaces, not concrete classes? I spent quite a time trying to make this piece of code working. I did not expect the stubbed pubSubClient to always call Send method from the class. That method has some dependencies and throws exception. [Test] public void Test01() { PubSubMessage psm = new PubSubMessage(); var pubSubClient = MockRepository.GenerateStub<PubSubClient>(); pubSubClient.Stub(x => x.Send(psm)).IgnoreArguments()

How can I verify that a Microsoft Fakes (beta) stub/shim was called (like AssertWasCalled in Rhino Mocks)?

六月ゝ 毕业季﹏ 提交于 2019-11-29 13:47:21
I'm using the beta of Microsoft Fakes in Visual Studio 11. How can I verify that a dependency's method was called by my system under test? As verify functionality is not included in the Microsoft Fakes Beta, the code below is a basic test for whether or not a method on a dependency was called. You could enhance the true test to test parameter values or other conditions of a proper call. Test: [TestMethod] public void TestMethod1() { var secondDoItCalled = false; var secondStub = new Fakes.ShimSecond(); secondStub.DoIt = () => { secondDoItCalled = true; }; var first = new First(secondStub);

Can't get RhinoMocks to emit a mock that follows the generic type restriction rules

会有一股神秘感。 提交于 2019-11-29 10:53:21
So, using NUnit and RhinoMocks: //Defines basic behavior of all persistable domain objects public interface IDomainObject {...} //defines domain objects specific to the Security DB public interface ISecurityDomainObject : IDomainObject {...} //Defines a basic transactional data Repository; there are multiple implementors //which each close TRest to the interface that defines their DB's domain classes public interface IRepository<TRest> : IDisposable where TRest:IDomainObject { IUnitOfWork BeginUnitOfWork(); void CommitUnitOfWork(IUnitOfWork unitOfWork); void RollBackUnitOfWork(IUnitOfWork