rhino-mocks

unit test with lambda fail using rhino mock

冷暖自知 提交于 2019-12-02 13:38:14
If I have this test Expect.Call(_session.Single<Admin>(x => x.Email == userModel.Email)).Repeat.Once().Return(null); Telling me Rhino.Mocks.Exceptions.ExpectationViolationException : ISession.Single(x => (x.Email == value(Enquete.Test.Controllers.MemberControllerTest+<>c__DisplayClassb).userModel.Email)); Expected #1, Actual #0. It fails but if I add .IgnoreArguments() it works. Is it possible to test using lambda? If I debug I can see that my Email is the same. Here's the full test : [Test] public void Register_Post_ReturnRedirectOnSuccess() { _builder.InitializeController(_controller); var

Mocking iterative behaviour

若如初见. 提交于 2019-12-02 12:29:16
I have an interface with iterative behaviour, and I am having trouble Mocking that in Rhinomocks. The example interface and class is a very simple version of my problem. Every time LineReader.Read() is called, the LineReader.CurrentLine() should return a different value -- the next line. This behaviour I haven't been able to reproduce in a mock so far. Thus, it has become a small hobby project of mine which I return to from time to time. I hope you can help me a step further. internal class LineReader : ILineReader { private readonly IList<string> _lines; private int _countOfLines; private int

Mock abstract class default behaviour with Rhino

情到浓时终转凉″ 提交于 2019-12-01 22:31:17
问题 I'm pretty new to mocking so this might be something I'm just not picking up on yet, but I can't find a good example anywhere. I'm trying to assert that by default, any class that inherits from my abstract class will instantiate a collection in the constructor. Here's the abstract class: public abstract class DataCollectionWorkflow : SequentialWorkflowActivity { private readonly DataSet _output = new DataSet(); private List<DataCollectionParameter> _params = null; public

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

How to assert that an action was called

六月ゝ 毕业季﹏ 提交于 2019-12-01 20:50:12
I need to asset an action called by a mock component. public interface IDispatcher { void Invoke(Action action); } public interface IDialogService { void Prompt(string message); } public class MyClass { private readonly IDispatcher dispatcher; private readonly IDialogservice dialogService; public MyClass(IDispatcher dispatcher, IDialogService dialogService) { this.dispatcher = dispatcher; this.dialogService = dialogService; } public void PromptOnUiThread(string message) { dispatcher.Invoke(()=>dialogService.Prompt(message)); } } ..and in my test.. [TestFixture] public class Test { private

How to mock a method call that takes a dynamic object

杀马特。学长 韩版系。学妹 提交于 2019-12-01 03:23:27
Say I have the following: public interface ISession { T Get<T>(dynamic filter); } } And I have the following code that I want to test: var user1 = session.Get<User>(new {Name = "test 1"}); var user2 = session.Get<User>(new {Name = "test 2"}); How would I mock this call? Using Moq, I tired doing this: var sessionMock = new Mock<ISession>(); sessionMock.Setup(x => x.Get<User>(new {Name = "test 1")).Returns(new User{Id = 1}); sessionMock.Setup(x => x.Get<User>(new {Name = "test 1")).Returns(new User{Id = 2}); And that didn't work. The returned results is null I also tried to do the following with

What is Rhino Mocks Repeat?

瘦欲@ 提交于 2019-12-01 02:36:25
What is Rhino Mocks Repeat ? Repeat.Any(); Repeat.Once(); What does it mean and how it works ? Matthew Brubaker It is used with the Expect construct as part of a fluent declaration. As for what it means: it means that the previous event is expected to occur that many times. For instance: Expect.Call(someMethod()).Repeat.Twice() says that someMethod() will be called exactly two times. 来源: https://stackoverflow.com/questions/466520/what-is-rhino-mocks-repeat

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

How to mock a method call that takes a dynamic object

喜欢而已 提交于 2019-11-30 23:05:37
问题 Say I have the following: public interface ISession { T Get<T>(dynamic filter); } } And I have the following code that I want to test: var user1 = session.Get<User>(new {Name = "test 1"}); var user2 = session.Get<User>(new {Name = "test 2"}); How would I mock this call? Using Moq, I tired doing this: var sessionMock = new Mock<ISession>(); sessionMock.Setup(x => x.Get<User>(new {Name = "test 1")).Returns(new User{Id = 1}); sessionMock.Setup(x => x.Get<User>(new {Name = "test 1")).Returns(new

What is Rhino Mocks Repeat?

北城余情 提交于 2019-11-30 22:15:38
问题 What is Rhino Mocks Repeat ? Repeat.Any(); Repeat.Once(); What does it mean and how it works ? 回答1: It is used with the Expect construct as part of a fluent declaration. As for what it means: it means that the previous event is expected to occur that many times. For instance: Expect.Call(someMethod()).Repeat.Twice() says that someMethod() will be called exactly two times. 来源: https://stackoverflow.com/questions/466520/what-is-rhino-mocks-repeat