in Education by
I know I can do this: IDateTimeFactory dtf = MockRepository.GenerateStub(); dtf.Now = new DateTime(); DoStuff(dtf); // dtf.Now can be called arbitrary number of times, will always return the same value dtf.Now = new DateTime()+new TimeSpan(0,1,0); // 1 minute later DoStuff(dtf); //ditto from above What if instead of IDateTimeFactory.Now being a property it is a method IDateTimeFactory.GetNow(), how do I do the same thing? As per Judah's suggestion below I have rewritten my SetDateTime helper method as follows: private void SetDateTime(DateTime dt) { Expect.Call(_now_factory.GetNow()).Repeat.Any(); LastCall.Do((Func)delegate() { return dt; }); } but it still throws "The result for ICurrentDateTimeFactory.GetNow(); has already been setup." errors. Plus its still not going to work with a stub.... JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I know this is an old question, but thought I'd post an update for more recent Rhino Mocks versions. Based on the previous answers which use Do(), there is a slightly cleaner (IMO) way available if you are using AAA in Rhino Mocks (available from version 3.5+). [Test] public void TestDoStuff() { var now = DateTime.Now; var dtf = MockRepository.GenerateStub(); dtf .Stub(x => x.GetNow()) .Return(default(DateTime)) //need to set a dummy return value .WhenCalled(x => x.ReturnValue = now); //close over the now variable DoStuff(dtf); // dtf.Now can be called arbitrary number of times, will always return the same value now = now + new TimeSpan(0, 1, 0); // 1 minute later DoStuff(dtf); //ditto from above } private void DoStuff(IDateTimeFactory dtf) { Console.WriteLine(dtf.GetNow()); }

Related questions

0 votes
    I want to assign DataReader value to a DataSet, is there any method which helps to do this? JavaScript ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I want to assign DataReader value to a DataSet, is there any method which helps to do this? JavaScript ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I want create expression with reflection in c#. I am target script is: using (var service = new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    newbie question: how do i make my JSON output ignore null values? I don't want to necessarily set ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    newbie question: how do i make my JSON output ignore null values? I don't want to necessarily set ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    C#6 Update In C#6 ?. is now a language feature: // C#1-5 propertyValue1 = myObject != null ? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    C#6 Update In C#6 ?. is now a language feature: // C#1-5 propertyValue1 = myObject != null ? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    C#6 Update In C#6 ?. is now a language feature: // C#1-5 propertyValue1 = myObject != null ? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    C#6 Update In C#6 ?. is now a language feature: // C#1-5 propertyValue1 = myObject != null ? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    It happened to me that I needed to compare the result of sizeof(x) to a ssize_t. Of course GCC ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
0 votes
    I'm building an app using Visual Studio 2010. I can run my asp.net website from my computer (by ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    My question may be silly but I've been trying several ways and I still can't do what I want, i. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    I have a dataframe with 2 columns and I want to add the new column; This new column should be updated based on ... +=1 is not working. Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    So the problem is i don't get get a value from textbox field on GridView RowUpdating event. Here ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
...