rhino-mocks

Unit testing with I/O dependencies

喜欢而已 提交于 2019-12-24 09:49:59
问题 I would like to test the following class but I/O and sealed class dependencies are making it quite hard. public class ImageDrawingCombiner { /// <summary> /// Save image to a specified location in path /// </summary> /// <param name="path">Location to save the image</param> /// <param name="surface">The image as canvas</param> public void CombineDrawingsIntoImage(Uri path, Canvas surface) { Size size = new Size(surface.ActualWidth, surface.ActualHeight); // Create a render bitmap and push the

asp.net mvc rhino mocks mocking httprequest values

核能气质少年 提交于 2019-12-24 03:38:12
问题 I'm trying to write a test can I mock a HttpRequestBase to return post values like this? How can I achieve this? var collection = new NameValueCollection(); collection.Add("Id", "1"); collection.Add("UserName", ""); var mocks = new MockRepository(); using (mocks.Record()) { Expect.Call(requestBase.Params).Return(collection); } Basically I have a requirement that rquires me to mock request post parameters as opposed to form values as the UI client is not a html form, any ideas how to fake/mock

Is there a way to decide when a RhinoMocks mock starts recording?

时光总嘲笑我的痴心妄想 提交于 2019-12-24 00:26:02
问题 As I understand it, a mock object created with RhinoMocks enter the recording state directly when it is created, and then you call Replay() to enter the replay state. I would like to manually decide when the mock object starts recording, or be able to pause the recording. Would that be possible in RhinoMocks? Thanks /Erik 回答1: Mocks are either in record or replay mode. They can't be in a "nothing" mode. If you don't want to use the AAA syntax and you want to control the record/replay state

Rhino.Mocks and ref parameter

早过忘川 提交于 2019-12-23 14:49:53
问题 I'm having problems to test a method that has a ref parameter. I'm not the library/code owner, so I can't change it, so please do not suggest that I remove the ref parameter. I'm using this website as reference: http://ayende.com/wiki/Rhino%20Mocks%203.5.ashx#OutandRefarguments Here is the test: [Test] public void TestBuildSimpleProfile() { // arrange var barMock = MockRepository.GenerateStrictMock<ICommandBar>(); var controlBuilder = new ControlBuilder(barMock); var user = new Usuario();

Cannot mock class with constructor having array parameter using Rhino Mocks

折月煮酒 提交于 2019-12-23 10:28:53
问题 We are not able to mock this class in RhinoMocks. public class Service { public Service(Command[] commands){} } public abstract class Command {} // Code var mock = MockRepository.GenerateMock<Service>(new Command[]{}); // or mock = MockRepository.GenerateMock<Service>(null) Rhino mocks fails complaining that it cannot find a constructor with matching arguments. What am I doing wrong? Thanks, 回答1: Try like this: var mock = MockRepository.GenerateMock<Service>( new object[] { new Command[0] } )

Stubbing a property twice with rhino mocks

会有一股神秘感。 提交于 2019-12-23 08:07:42
问题 For some objects I want to create default stubs so that common properties contains values. But in some cases I want to override my default behaviour. My question is, can I somehow overwrite an already stubbed value? //First I create the default stub with a default value var foo = MockRepository.GenerateStub<IFoo>(); foo.Stub(x => x.TheValue).Return(1); //Somewhere else in the code I override the stubbed value foo.Stub(x => x.TheValue).Return(2); Assert.AreEqual(2, foo.TheValue); //Fails,

Mocking a private field

左心房为你撑大大i 提交于 2019-12-22 09:48:57
问题 I know a similar question has been asked but I have not found a clear solution. I'm trying to mock a private field from a large class. The private field gets instantiated in some earlier method and I'm trying to unit test a latter method which references the field. So I have an earlier method in my class: public bool validateAll(ref DataEntry[] oEntries, string sMediaPlanId, ITemplateGenerator oTempGen) { ... // private field that I am trying to mock this._sMediaPlanObjective = (MPWrapper

Mocking sealed classes without public constructors?

房东的猫 提交于 2019-12-22 05:39:29
问题 The particular class I'm testing depends upon the HttpSessionState object. The HttpSessionState class has no public constructors. The class under test is only using this object as a NameValue store. The class is used in an ASMX web service to return information for a particular method. I'm thinking about creating a facade around the HttpSessionState class where I can provide a Dictionary <string, string> instead of the Session object in testing. Is this a good idea or standard practice? 回答1:

Rhino Mocks: Can I use Stub() when one of my parameters is Expression<Func<T1, T2>>?

倖福魔咒の 提交于 2019-12-22 05:30:10
问题 I have a method on an interface that looks like this and I want to stub it with Rhino Mocks: TValue GetPropertyOfExistingObject<TValue>(long id, Expression<Func<T, TValue>> propertyExpression); My code that does the stubbing looks like this: var service = MockRepository.GenerateStub<IQuoteService>(); service.Stub(s => s.GetPropertyOfExistingObject(1, q => q.QuoteNumber)).Return(1234); Notice that one of the parameters in that method is an Expression<Func<T1, T2>> , and this stub is not

What would this Moq code look like in RhinoMocks

蓝咒 提交于 2019-12-21 09:26:41
问题 Hey people... trying to get my mocking sorted with asp.net MVC. I've found this example on the net using Moq, basically I'm understanding it to say: when ApplyAppPathModifier is called, return the value that was passed to it. I cant figure out how to do this in Rhino Mocks, any thoughts? var response = new Mock<HttpResponseBase>(); response.Expect(res => res.ApplyAppPathModifier(It.IsAny<string>())) .Returns((string virtualPath) => virtualPath); 回答1: If you are using the stub method as