How to Mock a Task Result?

The simplest thing is just to return a completed task with the expected result: var responseTask = Task.FromResult(response); I imagine reason this hangs is that the mocked task is never started and hence the given func is not run. You could start it in your test: var responseTask = MockRepository.GenerateMock<Task<HttpResponseMessage>>(taskFunc); responseTask.Start(); However there’s no reason … Read more

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

Although I fundamentally agree with Nick Holt’s answer, I thought I should point out that mockito allows to do what you ask with the following call : Foo mock = Mockito.mock(Foo.class, withSettings().extraInterfaces(Bar.class)); Obviously you’ll have to use the cast: (Bar)mock when you need to use the mock as a Bar but that cast will not … Read more

How to clear previous expectations on an object?

There are three ways: You can reset the expectations by using BackToRecord I have to admit that I never really used it because it is awkward. // clear expectations, an enum defines which _stubRepository.BackToRecord(BackToRecordOptions.All); // go to replay again. _stubRepository.Replay(); Edit: Now I use it sometimes, it is actually the cleanest way. There should be … Read more

Castle DynamicProxy – Failure when creating proxy involving a GTP used as a GTR

I’m not a Castle expert nor compiler guru, but I believe the issue is a little bit of magic that is hidden inside the RhinoMocks.Tests assembly: From https://github.com/ayende/rhino-mocks/blob/master/Rhino.Mocks.Tests/TestInfo.cs using System.Runtime.CompilerServices; using Rhino.Mocks; [assembly: InternalsVisibleTo(RhinoMocks.StrongName)] And for completeness sake, RhinoMocks.StrongName is defined as: /// <summary> /// Used for [assembly: InternalsVisibleTo(RhinoMocks.StrongName)] /// Used for [assembly: InternalsVisibleTo(RhinoMocks.NormalName)] /// … Read more

Mocking Asp.net-mvc Controller Context

Using MoQ it looks something like this: var request = new Mock<HttpRequestBase>(); request.Expect(r => r.HttpMethod).Returns(“GET”); var mockHttpContext = new Mock<HttpContextBase>(); mockHttpContext.Expect(c => c.Request).Returns(request.Object); var controllerContext = new ControllerContext(mockHttpContext.Object , new RouteData(), new Mock<ControllerBase>().Object); I think the Rhino Mocks syntax is similar.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)