rhino-mocks

Unit testing a Func<Delegate> with Rhino Mocks throwing InvalidCastException with second Expect() invocation

旧城冷巷雨未停 提交于 2020-01-03 05:52:13
问题 I'm unit testing a class that gets some parameters injected by Autofac. Some of the parameters are Func<Delegate> . This allows me to create multiple delegates to use. Refer to this Autofac Wiki page if you need a better description. Here's part of the class. public class CreateProductCommand : TransactionalDBCommandBase<ProductImpl> { public delegate CreateProductCommand Factory(ProductInfo info, IAppSecurityContext context); private ProductInfo _info; private Func<SaveTextMasterCommand

How do I test an abstract class's protected abstract method?

隐身守侯 提交于 2020-01-02 07:23:23
问题 I've been working on the best way to test an abstract class named TabsActionFilter . I've guranteed that classes that inherit from TabsActionFilter will have a method called GetCustomer . In practice this design seems to work well. Where I've had some issues is figuring out how to test the OnActionExecuted method of the base class. This method relies upon the implementation of the the protected abstract GetCustomer method. I've tried mocking the class using Rhino Mocks but can't seem to mock

Error using MVCContrib TestHelper

你说的曾经没有我的故事 提交于 2020-01-01 15:03:13
问题 While trying to implement the second answer to a previous question, I am receiving an error. I have implemented the methods just as the post shows, and the first three work properly. The fourth one (HomeController_Delete_Action_Handler_Should_Redirect_If_Model_Successfully_Delete) gives this error: Could not find a parameter named 'controller' in the result's Values collection. If I change the code to: actual .AssertActionRedirect() .ToAction("Index"); it works properly, but I don't like the

How can I mock Server.HtmlEncode

柔情痞子 提交于 2020-01-01 12:25:09
问题 I am trying the following, but I am getting : Object reference not set to an instance of an object. HttpContextBase mockContext = MockRepository.GenerateMock<HttpContextBase>(); mockContext.Expect(c => c.Server.HtmlEncode("")).IgnoreArguments().Return(""); mockContext.Expect(c => c.Server.HtmlDecode("")).Return(""); controller.ControllerContext = new ControllerContext(mockContext, new RouteData(), controller); Matin, Thanks. That was enough to point me in the right direction provided here:

Ordering method return values with Rhino-Mock stubs

╄→尐↘猪︶ㄣ 提交于 2019-12-30 06:11:12
问题 I've started experimenting with Rhino-Mocks (3.6) while reading Roy Osherove's The Art of Unit Testing . He has an example that demonstrates that a mocked method can be scripted to return different results when called twice with the same parameter: [Test] public void ReturnResultsFromMock() { MockRepository repository = new MockRepository(); IGetRestuls resultGetter = repository.DynamicMock<IGetRestuls>(); using(repository.Record()) { resultGetter.GetSomeNumber("a"); LastCall.Return(1);

Can I test method call order with AAA syntax in Rhino-Mocks 3.6?

泄露秘密 提交于 2019-12-29 07:30:32
问题 Is it possible to test for the following example if the Method1 called 1st, then Method2 called after and then Method3 by using the AAA syntax, in Rhino-mocks 3.6 ? // Assert var mock = MockRepository.GenerateMock<ISomeService>(); // Act myObject.Service = mock; // How should I change this part to ensure that Rhino Mocks check the call order as well? mock.AssertWasCalled(m=>m.Method1()); mock.AssertWasCalled(m=>m.Method2()); mock.AssertWasCalled(m=>m.Method3()); 回答1: Here's one way to do it..

Rhino Mocks AAA Quick Start?

拥有回忆 提交于 2019-12-29 06:10:08
问题 I've been looking around for some decent information on using Rhino Mocks 3.5+ with the AAA syntax. I find a lot of blogs that have a mix of things from the old and new which seem to make it more difficult to figure out how to use it. Would would be great would be if there were a Rhino Mocks AAA Cheat Sheet like was done for an earlier version. Is it required that you know everything about the older versions of Rhino to actually use the newer version? I'm sure if I were an expert that I would

What is LastCall for in RhinoMocks?

大憨熊 提交于 2019-12-26 05:19:46
问题 What is the use of lastcall method in rhino mock? Can you please explain with the help of example? 回答1: LastCall allows you to do something additional to the last call that was added. Expect.Call(delegate{ mockObject.DoSomething("foo"); }).IgnoreArguments(); is that same as mockObject.DoSomething("foo"); LastCall.IgnoreArguments(); Hope this helps. 来源: https://stackoverflow.com/questions/5789662/what-is-lastcall-for-in-rhinomocks

Can Rhino Mocks Write My Expect Statements For Me? [closed]

落花浮王杯 提交于 2019-12-24 18:18:09
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I have a set of Visual Studio Team System unit (integration really) tests that talk to a remote database. The tests are getting too slow and unwieldy. I'd like to replace the entire set of tests with mocked out versions. The problem is it's painful to write all the expect

Weird error using Rhino Mocks “type doesn't match the return value”

↘锁芯ラ 提交于 2019-12-24 16:00:11
问题 EDIT: I played with this example and now my question is a different one entirely. When I run this example: using Rhino.Mocks; public interface IInterface { decimal GetDecimal(); } static class Util { public static double? DecToDouble(this IInterface input) { return (double) input.GetDecimal(); } } class MockExample { public void RunThis() { var stubReader = MockRepository.GenerateStub<IInterface>(); stubReader.Stub(sr => sr.DecToDouble()).Return(1.2); } } I get this error: System