The files section of the web interface.

Tuna Toksöz
Eternal sunshine of the open source mind.

http://devlicio.us/blogs/tuna_toksoz
http://tunatoksoz.com
http://twitter.com/tehlike




On Tue, Mar 24, 2009 at 9:25 PM, Chris Martin <[email protected]> wrote:

> Where is that zip file?
>
>
> On Tue, Mar 24, 2009 at 12:23 PM, Jake <[email protected]> wrote:
>
>>
>> I uploaded ProtectedMethodCase.zip into files (It works in
>> VisualStudio 2008 with Microsoft Test Framework). I implemented the
>> test using the PartialMock as was suggested earlier.
>>
>> On Mar 24, 3:20 pm, Tim Barcz <[email protected]> wrote:
>> > It wasn't AAA, I was trying to clarify aruond PartialMock but I think I
>> only
>> > muddied the waters....
>> >
>> > On Tue, Mar 24, 2009 at 2:19 PM, Tuna Toksoz <[email protected]> wrote:
>> > > I didin't realize it was AAA syntax, because I saw ReplayAll, and
>> though
>> > > the record/replay mode.
>> >
>> > > Tuna Toksöz
>> > > Eternal sunshine of the open source mind.
>> >
>> > >http://devlicio.us/blogs/tuna_toksoz
>> > >http://tunatoksoz.com
>> > >http://twitter.com/tehlike
>> >
>> > > On Tue, Mar 24, 2009 at 9:08 PM, Chris Martin <[email protected]
>> >wrote:
>> >
>> > >> This won't even compile.
>> > >> Your methods are protected.
>> >
>> > >> Change them to public and this following passes.
>> >
>> > >> ---
>> > >>     public class ClassA
>> > >>     {
>> > >>         public bool Success;
>> >
>> > >>         public virtual bool FileExists(string filename)
>> > >>         {
>> > >>             return File.Exists(filename);
>> > >>         }
>> >
>> > >>         public virtual void Process(string filename)
>> > >>         {
>> > >>             Success = FileExists(filename);
>> > >>         }
>> > >>     }
>> >
>> > >>     [TestFixture]
>> > >>     public class Tests
>> > >>     {
>> > >>         [Test]
>> > >>         public void process_test()
>> > >>         {
>> > >>             var mocks = new MockRepository();
>> >
>> > >>             var a = mocks.PartialMock<ClassA>();
>> >
>> > >>  Expect.Call(a.FileExists(null)).IgnoreArguments().Return(true);
>> > >>             mocks.ReplayAll();
>> >
>> > >>             a.Process("test.test");
>> >
>> > >>             Assert.AreEqual(a.Success, true);
>> > >>         }
>> > >>     }
>> >
>> > >> On Tue, Mar 24, 2009 at 10:50 AM, Jake <[email protected]> wrote:
>> >
>> > >>> Sorry, for this mistake, but method is virtual!
>> > >>> Here is more info:
>> >
>> > >>> public class classA: baseClass
>> > >>> {
>> >
>> > >>>   public bool Success;
>> >
>> > >>>   protected virtual bool FileExists(string fileName)
>> > >>>   {
>> > >>>      return File.Exists(fileName);
>> > >>>   }
>> >
>> > >>>   protected virtual void Process(string fileName)
>> > >>>   {
>> > >>>     //Do something
>> > >>>     if(FileExists(fileName))
>> > >>>      {
>> > >>>       Success = true;
>> > >>>      }
>> > >>>     else
>> > >>>     {
>> > >>>      Success = false;
>> > >>>     }
>> > >>>  }
>> > >>> }
>> >
>> > >>> Unit test:
>> >
>> > >>> [TestMethod]
>> > >>> public void ProcessTest()
>> > >>> {
>> > >>>    var a = _mocks.StrickMock<baseClass>();
>> > >>>    Expect.Call(a.FileExists(null)).IgnoreArguments().Return(true);
>> > >>>    _mocks.ReplayAll();
>> > >>>   a.Process("test.test"); //File doesn't exists
>> > >>>   Assert.AreEqual(true, a.Success); //Fails here
>> > >>> }
>> >
>> > >>> On Mar 24, 1:39 pm, Alex McMahon <[email protected]> wrote:
>> > >>> > Method2 must be a virtual method for RhinoMocks to be able to mock
>> the
>> > >>> > method with a PartialMock,
>> >
>> > >>> > On Tue, Mar 24, 2009 at 5:21 PM, Jake <[email protected]> wrote:
>> >
>> > >>> > > Ayende,
>> > >>> > > I am trying to use Rhino Mocks in following scenario:
>> >
>> > >>> > > void classA.Method1()
>> > >>> > > {
>> > >>> > >    //some stuff
>> > >>> > >    if(classA.Method2(var))
>> > >>> > >    {
>> > >>> > >        //Do something
>> > >>> > >  }
>> > >>> > >    else
>> > >>> > >  {
>> > >>> > >     //Do something else
>> > >>> > >  }
>> > >>> > >    //some other stuff
>> > >>> > > }
>> >
>> > >>> > > Now, I created partial mock for the class and set expectation
>> for
>> > >>> > > Method2 like so:
>> >
>> > >>> > >
>> Expect.Call(classAMock.Method2(null)).IgnoreArguments().Return(true);
>> >
>> > >>> > > Real implementation of the method returns false.
>> >
>> > >>> > > When I execute the test it goes through the path when Method2
>> returns
>> > >>> > > false.
>> >
>> > >>> > > How can that be?
>> >
>> > >> --
>> >
>> > >> Charles Kettering  - "My interest is in the future because I am going
>> to
>> > >> spend the rest of my life there."
>>
>>
>
>
> --
>
> Isaac Asimov  - "I do not fear computers. I fear the lack of them."
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to