rhino-mocks

Has anyone successfully mocked the Socket class in .NET?

两盒软妹~` 提交于 2019-12-18 15:40:24
问题 I'm trying to mock out the System.net.Sockets.Socket class in C# - I tried using NUnit mocks but it can't mock concrete classes. I also tried using Rhino Mocks but it seemed to use a real version of the class because it threw a SocketException when Send(byte[]) was called. Has anyone successfully created and used a Socket mock using any mocking framework? 回答1: Whenever I run into these kinds of problems with Moq I end up creating an interface to abstract away the thing I can't mock. So in

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

梦想的初衷 提交于 2019-12-18 12:44:54
问题 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? 回答1: EasyMock doesn't support this so you're

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

走远了吗. 提交于 2019-12-18 12:43:18
问题 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

How to use Rhino Mocks to Mock an HttpContext.Application

走远了吗. 提交于 2019-12-18 11:43:28
问题 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

How to Mock a Static Singleton?

扶醉桌前 提交于 2019-12-18 03:16:26
问题 I have number of classes I've been asked to add some unit tests to with Rhino Mocks and having some issues. First off, I know RhinoMocks doesn't allow for the mocking of Static members. I'm looking for what options I have (besides using TypeMock). An example of the class I have is similar to the below: class Example1 : ISomeInterface { private static ISomeInterface _instance; private Example1() { // set properties via private static methods } static Example1() { _instance = new Example1(); }

Rhino Mocks - Difference between GenerateStub<T> & GenerateMock<T> [closed]

六眼飞鱼酱① 提交于 2019-12-17 10:25:36
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Can any of the Rhino experts explain me by giving a suitable example of the difference between the above methods on the MockRepository class (Rhino Mocks framework). Where should one use Stub over Mock method or otherwise? 回答1: you should use a mock when you are going to verify

How can I deal with too Many Mock Expectations in unit tests?

南笙酒味 提交于 2019-12-14 03:59:11
问题 I am writing unit tests for my presentation class in MVP pattern.But I am having trouble to write mock setup code. I have a presenter and when presenter's Load method called I want to test view should load class properties, table fields, data types,set presenter.... So When I have a different thing to do when presenter load always I have to add new expectation to test. And test is getting bigger every time. [Test] public void When_Presenter_Loads_View_Should_Display_Selected_Class_Properties(

Mocking Ajax.IsRequest to return False

烂漫一生 提交于 2019-12-14 02:33:18
问题 I am trying to mock the Ajax.IsRequest() method of ASP.Net MVC. I found out how to do it in order for it to return true: Expect.Call(_myController.Request.Headers["X-Requested-With"]).Return("XMLHttpRequest").Repeat.Any(); This works and returns true. Now I need to test the other branch of the code. How can I mock it to return false? I have tried removing the mock altogether, It fails with: System.NullReferenceException : Object reference not set to an instance of an object.] If I do: Expect

Why are all objects listing Rhino stub methods in intellisense?

假如想象 提交于 2019-12-13 16:24:56
问题 I noticed that slightly annoyingly, every object ( not just stub objects) is listing all the common Rhino methods like AssertNeverCalled in Visual Studio. It makes browsing the properties/methods much harder. Is this a bug with Visual Studio (corrupted Intellisense DB for instance) or a 'feature' of Rhino Mocks? 回答1: To answer your question I need to split my answer between the arrange and the asserts methods. The reason you face those extension methods on reference types instances is because

Set a property of an object in a Expect.Call

你离开我真会死。 提交于 2019-12-13 13:51:05
问题 It's kind of hard to explain what I'm searching for but my example should clarify it. I have next code: var schedule = ScheduleUtil.CreateScheduleDto(user, user); Expect.Call(() => _scheduleRepository.Save(schedule)); Now, what I want to do is when this Save call is made, the schedule.id property should be set to another value (1 for instance). I do not want to mock schedule. Can this be done? The Save method doesn't return a value, so that's not a possiblity, but I do want the object