tag:blogger.com,1999:blog-14744716.post624044420653418351..comments2024-02-22T18:04:19.754+05:30Comments on My conversations with gullible machines...: Meet the frameworks : Rhino Mocks v Moq v jMock : Part 1Gishuhttp://www.blogger.com/profile/17616896114730114577noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-14744716.post-58741803050612691672014-04-22T23:58:05.345+05:302014-04-22T23:58:05.345+05:30See, I would consider that to be a bad unit test. ...See, I would consider that to be a bad unit test. If you are setting up another value, it should be in a different test; your test does not seem granular enough.Jeremy Holovacshttps://www.blogger.com/profile/08155647330103251463noreply@blogger.comtag:blogger.com,1999:blog-14744716.post-9900026874927781292013-07-23T12:53:24.737+05:302013-07-23T12:53:24.737+05:30This should work out-of-the-box. I suspect obj1 an...This should work out-of-the-box. I suspect obj1 and obj2 - are they custom types? If they are Equal (i.e. obj1.Equals(obj2) returns true, then you have effectively overwritten the first expectation. Hence both calls will return false.<br /><br />Here's a passing test to prove that it does - Moq v3.1.416.3 (quite old I think)<br /><br />[Test]<br />public void MoqDefense()<br />{<br /> var mock = new Mock();<br /><br /> mock.Setup(m => m.Do("a")).Returns(true);<br /> mock.Setup(m => m.Do("z")).Returns(false);<br /><br /> Assert.IsTrue(mock.Object.Do("a"));<br /> Assert.IsFalse(mock.Object.Do("z"));<br /><br />}Gishuhttps://www.blogger.com/profile/17616896114730114577noreply@blogger.comtag:blogger.com,1999:blog-14744716.post-16178275131441827282013-07-23T04:48:00.637+05:302013-07-23T04:48:00.637+05:30I have recently been looking at Moq, I am a long t...I have recently been looking at Moq, I am a long time user of the Rhino AAA syntax.<br /><br />The key issue I have with Moq is as follows. Try and set up a mock object where a call to function X with one set of params returns value 1 and call to function X with different params returns value 2.<br /><br />Everything falls apart and you are into ugly pattern matching and work arounds to solve. The trouble is this is a common thing to require as sooner or later you are looping over data calling operations.<br /><br />Have I missed something or does Moq not handle this clean like Rhino does.<br /><br />Rhino<br /><br />mockObj.Expect(x => x.DoWork("a", obj1, 2)).Return(true);<br />mockObj.Expect(x => x.DoWork("a", obj2, 2)).Return(false);<br /><br />try this in Moq (replacing Expect with Setup and both calls return falseAnonymousnoreply@blogger.com