rhino-mocks

Is there any open source mocking framework resembling TypeMock? [closed]

ε祈祈猫儿з 提交于 2019-12-09 04:37:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last month . TypeMock is too expensive for a hobbist like me :) Moq or the next version of RhinoMocks have no plans on listening to the profiling API, why is that? EDIT: This enables features such as: Mocking non-virtual methods and properties (!). Mocking browser environments. simpler syntax which is less fragile (and not

Rhino mock an abstract class w/o mocking its virtual method?

半腔热情 提交于 2019-12-09 03:13:34
问题 Can I execute the body of a virtual method that lives on an abstract class which has been mocked using Rhino Mocks? To be clear, I'm not trying to mock the behavior of the virtual method. I'm trying to /test/ the virtual method (on the mocked class). Is this idea a blatant misuse of Rhino Mocks? 回答1: Yes, that should be absolutely fine. I can't say I've tried it, but I'd be very surprised if it failed. EDIT: I suspect you want the PartialMock method. Here's an example: using System; using

Rhino Mocks - How to assert a mocked method was called n-times?

邮差的信 提交于 2019-12-08 14:48:31
问题 How can i assert that a method on a mocked object was called exactly called n-times? Here is the code snippet from a controller action, i like to test: for (int i = 0; i <= newMatchCommand.NumberOfMatchesToCreate; i++) { serviceFacade.CreateNewMatch("tester", Side.White); } The "service facade" object is the (strict) mock and will be injected into the controller. The unit test should assert that the CreateNewMatch method within the action was called n-times. (e.g. 5) 回答1: Try Expect.Call

Mocking data access Layer Rhino mock

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 11:59:58
问题 How can i mock data access layer using Rhino mocks I have the following classes: public interface IDataAccess { int ExecuteNoneQuery(SqlConnection connection, string storedProcedureName, IEnumerable<SqlParameter> sqlParameters); } public class DataAccess : IDataAccess { public int ExecuteNoneQuery(SqlConnection connection, string storedProcedureName, IEnumerable<SqlParameter> sqlParameters) { using (SqlCommand command = connection.CreateCommand()) { // do some stuff return command

RhinoMocks mock method without return

我的梦境 提交于 2019-12-08 10:20:14
问题 I am new to mocking. I need to mock method (it doesn't have return value). I cannot find any examples of how to mock a method. I need to mock ITempDa.Import method. var stub = MockRepository.GenerateStub<ITempDA>(); stub.Stub(x => x.Import(param1)). ??? public void MockedImport() { // some processing here } ITempDa.Import should be mocked and instead some internal method " MockedImport " should be called. 回答1: As @JamesLucas said you don't need to use Return() method(you should use this

How to mock HttpContext.Current.Items with NUnit and Rhino Mocks

白昼怎懂夜的黑 提交于 2019-12-08 07:54:41
问题 I'm using NUnit and RhinoMocks for unit testing on the (WebApi) project. There is a method I'm trying to write test for, which is supposed to add an item to HttpContext.Current.Items. public override void OnActionExecuting(HttpActionContext actionContext) { HttpContext.Current.Items.Add("RequestGUID", Guid.NewGuid()); base.OnActionExecuting(actionContext); } I have no idea how can I make HttpContext.Current.Items available to the method when ran from within a test method. How can I achieve

Mocking the Registry - SystemWrapper

好久不见. 提交于 2019-12-08 07:18:53
问题 I've tried following this as a guide for Mocking the registry: http://www.rhyous.com/2011/11/04/unit-testing-registry-access-with-rhinomocks-and-systemwrapper/ When I try to Mock it, I always get a null return for "reg" in my class when it tries to do the OpenSubKey call, in my _Real() test it works fine. Tests: private RegistryService CreateMockedRegistryService() { var registryService = new RegistryService(MockRepository.GenerateMock<ILoggerFacadeExtended>(), MockRepository.GenerateMock

RhinoMocks AAA Syntax

為{幸葍}努か 提交于 2019-12-08 02:34:34
问题 I've spent a good part of the day trying to figure out why a simple RhinoMocks test doesn't return the value I'm setting in the return. I'm sure that I'm just missing something really simple but I can't figure it out. Here's my test: [TestMethod] public void CopyvRAFiles_ShouldCallCopyvRAFiles_ShouldReturnTrue2() { FileInfo fi = new FileInfo(@"c:\Myprogram.txt"); FileInfo[] myFileInfo = new FileInfo[2]; myFileInfo[0] = fi; myFileInfo[1] = fi; var mockSystemIO = MockRepository.GenerateMock

Using RhinoMocks, how can I assert that one of several methods was called?

谁说胖子不能爱 提交于 2019-12-07 22:38:06
问题 Consider the following service interfaces: public interface IServiceA { void DoSomething(string s); void DoSomething(string s, bool b); } public interface IServiceB { void DoSomething(); } The implementation of IServiceB depends on IServiceA like this: public class ServiceB : IServiceB { private IServiceA _serviceA; public ServiceB(IServiceA serviceA) { _serviceA = serviceA; } public void DoSomething() { _serviceA.DoSomething("Hello", true); } } Ie. the dependency is injected in the

Mocking the Registry - SystemWrapper

牧云@^-^@ 提交于 2019-12-07 18:57:20
I've tried following this as a guide for Mocking the registry: http://www.rhyous.com/2011/11/04/unit-testing-registry-access-with-rhinomocks-and-systemwrapper/ When I try to Mock it, I always get a null return for "reg" in my class when it tries to do the OpenSubKey call, in my _Real() test it works fine. Tests: private RegistryService CreateMockedRegistryService() { var registryService = new RegistryService(MockRepository.GenerateMock<ILoggerFacadeExtended>(), MockRepository.GenerateMock<IConnectivityService>()); // Mock the Base Key so we can throw errors and manipulate it registryService