new is just to avoid confusion on the inheritance of the class since the method is "shadowing" the original one.
On Mar 24, 4:21 pm, Tuna Toksoz <[email protected]> wrote: > Maybe it has something to do with "new" keyword, don't know. > > Tuna Toksöz > Eternal sunshine of the open source mind. > > http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike > > On Tue, Mar 24, 2009 at 9:57 PM, Jake <[email protected]> wrote: > > > So how can I mock that underlying object to test the functionality in > > ProcessItem? > > > On Mar 24, 3:39 pm, Chris Martin <[email protected]> wrote: > > > Looking under the hood, this is what I can determine: > > > MSTest is generating a proxy to the real object under test. It's only > > doing > > > this to be able to call the real object. Guess what? The real object in > > turn > > > calls FileExists, which isn't mocked. The result you're seing is the > > result > > > of File.Exists in Sys.IO. > > > > On Tue, Mar 24, 2009 at 12:33 PM, Jake <[email protected]> wrote: > > > > > ClassA_Accessor gets generated on runtime and makes otherwise "hidden" > > > > methods and members available for testing. And Yes it is used by > > > > MSTest only. > > > > > On Mar 24, 3:31 pm, Chris Martin <[email protected]> wrote: > > > > > What is ClassA_Accessor? > > > > > Is this some "trick" that MSTest relies on? > > > > > > On Tue, Mar 24, 2009 at 12:26 PM, Jake <[email protected]> wrote: > > > > > > > It's in Files in the RhinoMock Group (look on the right-side) > > > > > > > On Mar 24, 3: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." > > > > > > -- > > > > > > 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 -~----------~----~----~----~------~----~------~--~---
