rhino-mocks-3.5

Rhino Mock throws an exception when raising an event

混江龙づ霸主 提交于 2020-01-06 02:51:19
问题 Is it possible to simulate an event using Rhino Mocks framework without getting the exception below? A first chance exception of type 'System.NotSupportedException' occurred in Rhino.Mocks.dll - Can't create mocks of sealed classes public interface IWithEvent { event EventHandler RaiseMeWithoutExceptionPlease; } [TestClass] public class MockedEvents { [TestMethod] public void EventsTest() { IWithEvent withEvent = MockRepository.GenerateStub<IWithEvent>(); for (int i = 0; i < 500; i++) { //

Handling Multiple Mocks and Asserts in Unit Tests

烂漫一生 提交于 2019-12-22 12:43:26
问题 I currently have a repository that is using Entity Framework for my CRUD operations. This is injected into my service that needs to use this repo. Using AutoMapper, I project the entity Model onto a Poco model and the poco gets returned by the service. If my objects have multiple properties, what is a correct way to set-up and then assert my properties? If my service has multiple repo dependencies what is the correct way to setup all my mocks? * - A class [setup] where all the mocks and

Rhinomocks - Mocking delegates

我只是一个虾纸丫 提交于 2019-12-20 02:36:17
问题 public interface IServiceInvoker { R InvokeService<T, R>(Func<T, R> invokeHandler) where T : class; } public class MediaController : Controller { private IServiceInvoker _serviceInvoker; public MediaController(IServiceInvoker serviceInvoker) { _serviceInvoker = serviceInvoker; } public JsonResult GetAllMedia() { var media = _serviceInvoker.InvokeService<IMediaService, List<MediaBase>>(proxy => proxy.GetAllMediaInJson()); JsonResult jsonResult = new JsonResult(); jsonResult.Data = media;

Invalid call, the last call has been used or no call has been made

霸气de小男生 提交于 2019-12-12 07:26:11
问题 I am getting this error when I try to set a mock to have PropertyBehavior() : System.InvalidOperationException: System.InvalidOperationException: Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).. I am trying to use only Rhino Mocks 3.5 (Arrange, Act, Assert) Here is my code: private IAddAddressForm form; private AddAddressMediator mediator; [TestInitialize()] public void MyTestInitialize() { form =

RhinoMocks: AssertWasCalled doesn't work on Stub

狂风中的少年 提交于 2019-12-11 02:44:52
问题 I'm trying to assert with RhinoMocks that a certain property setter was called. But it's not working as expected. The following simplified example illustrates the problem. Consider this interface: public interface IMyInterface { string SomeProperty { get; set; } } And now consider the following code: var mock = MockRepository.GenerateStub<IMyInterface>(); mock.SomeProperty = "abc"; mock.AssertWasCalled(x => x.SomeProperty = Arg<string>.Is.Anything); I was expecting the assert on the last line

Rhino - Mocking classes and not overriding virtual methods

独自空忆成欢 提交于 2019-12-07 04:45:17
问题 If I'm mocking a class, like below, is there any way I can get the mock to not override a virtual method? I know I can simply remove the virtual modifier, but I actually want to stub out behavior for this method later. In other words, how can I get this test to pass, other than removing the virtual modifier: namespace Sandbox { public class classToMock { public int IntProperty { get; set; } public virtual void DoIt() { IntProperty = 1; } } public class Foo { static void Main(string[] args) {

Handling Multiple Mocks and Asserts in Unit Tests

谁说我不能喝 提交于 2019-12-06 07:33:28
I currently have a repository that is using Entity Framework for my CRUD operations. This is injected into my service that needs to use this repo. Using AutoMapper, I project the entity Model onto a Poco model and the poco gets returned by the service. If my objects have multiple properties, what is a correct way to set-up and then assert my properties? If my service has multiple repo dependencies what is the correct way to setup all my mocks? * - A class [setup] where all the mocks and objects are configured for these test fixtures?***** I want to avoid having 10 tests and each test has 50

Rhino - Mocking classes and not overriding virtual methods

北慕城南 提交于 2019-12-05 10:00:23
If I'm mocking a class, like below, is there any way I can get the mock to not override a virtual method? I know I can simply remove the virtual modifier, but I actually want to stub out behavior for this method later. In other words, how can I get this test to pass, other than removing the virtual modifier: namespace Sandbox { public class classToMock { public int IntProperty { get; set; } public virtual void DoIt() { IntProperty = 1; } } public class Foo { static void Main(string[] args) { classToMock c = MockRepository.GenerateMock<classToMock>(); c.DoIt(); Assert.AreEqual(1, c.IntProperty)

Rhinomocks - Mocking delegates

两盒软妹~` 提交于 2019-12-01 22:08:06
public interface IServiceInvoker { R InvokeService<T, R>(Func<T, R> invokeHandler) where T : class; } public class MediaController : Controller { private IServiceInvoker _serviceInvoker; public MediaController(IServiceInvoker serviceInvoker) { _serviceInvoker = serviceInvoker; } public JsonResult GetAllMedia() { var media = _serviceInvoker.InvokeService<IMediaService, List<MediaBase>>(proxy => proxy.GetAllMediaInJson()); JsonResult jsonResult = new JsonResult(); jsonResult.Data = media; jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return jsonResult; } [TestClass] public class

Invalid call, the last call has been used or no call has been made

橙三吉。 提交于 2019-12-01 02:19:23
I am getting this error when I try to set a mock to have PropertyBehavior() : System.InvalidOperationException: System.InvalidOperationException: Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).. I am trying to use only Rhino Mocks 3.5 (Arrange, Act, Assert) Here is my code: private IAddAddressForm form; private AddAddressMediator mediator; [TestInitialize()] public void MyTestInitialize() { form = MockRepository.GenerateMock<IAddAddressForm>(); mediator = new AddAddressMediator(form); // Make the