rhino-mocks

Rhino Mocks - Setting up results for non-virtual methods

对着背影说爱祢 提交于 2019-12-11 09:29:46
问题 I'm playing around with Rhino Mocks and am trying to set some dummy results on my mocked objects so when they are called in my factory methods I don't have to worry about the data. But I've hit a snag, the methods I want to have the dummy results for are causing exceptions because they aren't virtual . I've got code like this: using(mock.Record()){ SetupResult.For(service.SomeMethod()).Return("hello world"); } Does the SomeMethod method have to be a virtual to be have a mocked result? Also,

How to mock a Model in MVC3 when using Rhino Mocks

倾然丶 夕夏残阳落幕 提交于 2019-12-11 07:35:27
问题 I am new to Rhino Mocks. I have several models. One of them is as below. I want to use Rhino Mocks. I downloaded the latest Rhino.Mocks.dll and added it to my testharness project. How do I mock my model objects? I want to create a seperate project for mocking my model object. Can someone guideme the procedure? public class BuildRegionModel { public string Name { get; set; } public string Description { get; set; } public List<SelectListItem> StatusList { get; set; } public string Status { get;

Why does my partial mock have all virtual methods mocked, even if no expectations are set?

早过忘川 提交于 2019-12-11 03:55:16
问题 I have a user control which does some validation in the ValidateChildren method which I would like to test. I have created a partial mock of the user control, but although I am not setting any expectations on the ValidateChildren method, I am simply calling it, it is simply skipped and the code inside the method never executes. To try and understand what is going on I created a simple test, like so: public class Foo { public virtual bool Method1() { throw new NotImplementedException(); }

Moq to Rhino - fake partial repository

心不动则不痛 提交于 2019-12-11 03:09:01
问题 I got this really cool Moq method that fakes out my GetService, looks like this private Mock<IGetService<TEntity>> FakeGetServiceFactory<TEntity>(List<TEntity> fakeList) where TEntity : class, IPrimaryKey, new() { var mockGet = new Mock<IGetService<TEntity>>(); mockGet.Setup(mock => mock.GetAll()).Returns(fakeList); mockGet.Setup(mock => mock.Get(It.IsAny<int>())).Returns((int i) => fakeList.Find(fake => fake.Id.ToString() == i.ToString())); mockGet.Setup(mock => mock.Get(It.IsAny<Expression

Mocking collections with Rhino Mocks

a 夏天 提交于 2019-12-11 02:58:12
问题 So this is something I guess many people want to do, mock a collection. In the past with Rhino I have done this with something like: var col_mock = MockRepository.GenerateMock<ICustomCollection>(); // returns ICustom let's say List<ICustom> col_real = new List<ICustom>(); col_real.Add(custom_mock1); col_real.Add(custom_mock2); col_real.Add(custom_mock3); col_mock.Stub(x => x.GetEnumerator()).Return(col_real.GetEnumerator()); So yup this works fine, when you foreach col_mock you get the mocked

RhinoMocks: AssertWasCalled doesn't work on Stub

狂风中的少年 提交于 2019-12-11 02:44:52
问题 I'm trying to assert with RhinoMocks that a certain property setter was called. But it's not working as expected. The following simplified example illustrates the problem. Consider this interface: public interface IMyInterface { string SomeProperty { get; set; } } And now consider the following code: var mock = MockRepository.GenerateStub<IMyInterface>(); mock.SomeProperty = "abc"; mock.AssertWasCalled(x => x.SomeProperty = Arg<string>.Is.Anything); I was expecting the assert on the last line

Rhino Mocks: AAA Synax: Assert property was set with a given type

╄→гoц情女王★ 提交于 2019-12-11 02:43:29
问题 I am trying to assert that a property in a mock object was set with a given type. The property has an abstract type and is set with one of a number of concrete types. This is what I'm trying to do, and it's always passing the test regardless of the value that Foo.DoSomething() sets Foo.Bar with: [Test] public void DoSomething_SetsCorrectBar() { // Arrange Foo foo = MockRepository.GenerateMock<Foo>(); // Creates mock in Replay mode (what I want for AAA syntax). // Act foo.DoSomething(); //

Can I make Rhino Mocks GenerateStub or GenerateMock return a new type every time?

拈花ヽ惹草 提交于 2019-12-11 01:52:48
问题 I want to create an IList of objects that are all different concrete types, so: var tasks = new List<ITask>(); foreach (string taskName in taskNames) { var task = MockRepository.GenerateStub<ITask>(); task.Stub(t => t.Name).Return(taskName); tasks.Add(task); } return tasks; The problem is that each stub object is all the same concrete type. Normally this is fine, but I have a case where I want to test each one being a different type. Can I somehow configure Rhino Mocks to do this, in this

Why do Rhino Stubs allow me to set expectations on them?

不想你离开。 提交于 2019-12-10 22:57:42
问题 This question clarifies the conceptual differences between mocks and stubs in Rhino: What are the differences between mocks and stubs on Rhino Mocks? However I'm left confused why Rhino Stub objects provide methods such as .Expect and .VerifyAllExpectations() when these appear to do nothing at all. Why do mock/stub objects seemingly provide the same interface? It's making me think I've missed something fundamental - or is it just an implementation quirk? 回答1: The reason for this behavior is

How to setup return value for a readonly property using RhinoMocks in VB.NET?

廉价感情. 提交于 2019-12-10 20:55:06
问题 I'm using RhinoMock in VB.NET and I need to set the return value for a readonly list. Here's what I want to do (but doesn't work): dim s = Rhino.Mocks.MockRepository.GenerateStub(of IUserDto)() s.Id = guid.NewGuid s.Name = "Stubbed name" s.Posts = new List(of IPost) It fails on the compile because Posts is a readonly property. Then I tried a lambda expression, which works fine for Function calls, but not so much for Properties. This fails to compile. s.Stub(Function(x As IUserDto) x.Posts)