rhino-mocks

RhinoMocks: Correct way to mock property getter

杀马特。学长 韩版系。学妹 提交于 2019-12-03 11:08:50
I'm new to RhinoMocks, and trying to get a grasp on the syntax in addition to what is happening under the hood. I have a user object, we'll call it User, which has a property called IsAdministrator. The value for IsAdministrator is evaluated via another class that checks the User's security permissions, and returns either true or false based on those permissions. I'm trying to mock this User class, and fake the return value for IsAdministrator in order to isolate some Unit Tests. This is what I'm doing so far: public void CreateSomethingIfUserHasAdminPermissions() { User user = _mocks

Rhino Mocks: Repeat.Once() not working?

故事扮演 提交于 2019-12-03 07:15:49
问题 Can anyone tell me why in the world the following test is not failing? [Test] public void uhh_what() { var a = MockRepository.GenerateMock<IPrebuiltNotifier>(); a.Expect(x => x.Notify()).Repeat.Once(); a.Notify(); a.Notify(); a.VerifyAllExpectations(); } Really need a second pair of eyes to confirm I'm not crazy...now I'm worried that all my tests are unreliable. 回答1: There is already a thread on the RhinoMocks group. GenerateMock creates a dynamic mock. The dynamic mock allows calls that are

Mocking method results

拟墨画扇 提交于 2019-12-03 06:36:37
I'm trying to find a way to fake the result of a method called from within another method. I have a "LoadData" method which calls a separate helper to get some data and then it will transform it (I'm interested in testing the transformed result). So I have code like this: public class MyClass(){ public void LoadData(){ SomeProperty = Helper.GetSomeData(); } public object SomeProperty {get;set;} } I want to have a known result from the Helper.GetSomeData() method. Can I use a mocking framework (I've got fairly limited experience with Rhino Mocks but am open to anything) to force an expected

Mocking GetEnumerator() method of an IEnumerable<T> types

故事扮演 提交于 2019-12-03 05:53:46
The following test case fails in rhino mocks: [TestFixture] public class EnumeratorTest { [Test] public void Should_be_able_to_use_enumerator_more_than_once() { var numbers = MockRepository.GenerateStub<INumbers>(); numbers.Stub(x => x.GetEnumerator()).Return(new List<int> { 1, 2, 3 }.GetEnumerator()); var sut = new ObjectThatUsesEnumerator(); var correctResult = sut.DoSomethingOverEnumerator2Times (numbers); Assert.IsTrue(correctResult); } } public class ObjectThatUsesEnumerator { public bool DoSomethingOverEnumerator2Times(INumbers numbers) { int sum1 = numbers.Sum(); // returns 6 int sum2 =

Rhino mock vs Typemock vs JustMock vs [closed]

萝らか妹 提交于 2019-12-03 03:10:09
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I need to choose mock framework to new project. What are the pros and cons for those frameworks? Any comparison table? I know that

Is there any open source mocking framework resembling TypeMock?

て烟熏妆下的殇ゞ 提交于 2019-12-03 02:36:32
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 having to go trough mock objects). Mocking static methods Sometimes is useful (Mostly in legacy scenarios, involving the dreaded DateTime.Now). And more .. TypeMock is too expensive for a hobbist like me It's probably also too expensive to develop and release for free. Declaimer I work

Asserting that a method is called exactly one time

☆樱花仙子☆ 提交于 2019-12-03 01:11:28
I want to assert that a method is called exactly one time. I'm using RhinoMocks 3.5. Here's what I thought would work: [Test] public void just_once() { var key = "id_of_something"; var source = MockRepository.GenerateStub<ISomeDataSource>(); source.Expect(x => x.GetSomethingThatTakesALotOfResources(key)) .Return(new Something()) .Repeat.Once(); var client = new Client(soure); // the first call I expect the client to use the source client.GetMeMyThing(key); // the second call the result should be cached // and source is not used client.GetMeMyThing(key); } I want this test to fail if the second

How do I mock IQueryable<T>

爱⌒轻易说出口 提交于 2019-12-03 01:02:23
I am creating a repository that exposes IQueryable. What is the best way to mock this out for my unit testing? Since I am using RhinoMocks for the rest of my mock objects, I tried to do the following: IQueryable<MyObject> QueryObject = MockRepository.GenerateStub<IQueryable<MyObject>>(); This doesn't work though so I tried doing this: IQueryable<MyObject> QueryObject = (new List<MyObject> { new MyObject() }).AsQueryable(); Is there a better way to do this, or have any other mocking frameworks built support for IQueryable in? My repository interface looks like this: public interface IRepository

Rhino Mocks: Repeat.Once() not working?

情到浓时终转凉″ 提交于 2019-12-02 20:48:22
Can anyone tell me why in the world the following test is not failing? [Test] public void uhh_what() { var a = MockRepository.GenerateMock<IPrebuiltNotifier>(); a.Expect(x => x.Notify()).Repeat.Once(); a.Notify(); a.Notify(); a.VerifyAllExpectations(); } Really need a second pair of eyes to confirm I'm not crazy...now I'm worried that all my tests are unreliable. There is already a thread on the RhinoMocks group . GenerateMock creates a dynamic mock. The dynamic mock allows calls that are not specified (=expected). If this happens, it just returns null (or the default value of the return type)

Rhino mock vs Typemock vs JustMock vs [closed]

瘦欲@ 提交于 2019-12-02 16:39:50
I need to choose mock framework to new project. What are the pros and cons for those frameworks? Any comparison table? I know that JustMock is i beta stage but it's look very good right now (very similar to TypeMock) Edit: I'v What about MS Mole? Dror Helper Before there was JustMock this question was asked and the answers can be found here . There is a very good Mocking framework comparison - it doesn't have JustMock yet but you get to see the syntax and capabilities of each .NET mocking framework. RhinoMocks (and Moq ) are both open source free to use projects that can create fake objects by