@Patrick: Using Visual Studio's "Goto To Definition" the API [from metadata] is:
public int Add(RadItem value); As a newbie, I assume that since the Add function has a return value my expectation has to have a .Return(...). Is my assumption incorrect? On Mar 10, 9:23 pm, Patrick Steele <[email protected]> wrote: > It sounds like the "Add" method may not actually return anything -- > but you've set an expectation that the Add will return an Int: > > collection.Expect(c => c.Add(null)).IgnoreArguments().Return(0); > > Have you tried removed the "Return(0)" clause? > > -- > Patrick Steelehttp://weblogs.asp.net/psteele > > > > On Mon, Mar 8, 2010 at 6:15 PM, BaRuSa <[email protected]> wrote: > > The Rad components are third party controls that I do not have control > > of changing the way they work. I have a helper method extension that > > provides steps for frequently repeated code. > > > public static void AddItems(this RadComboBox comboBox, > > Dictionary<string, string> items) > > { > > RadItemCollection collection; > > RadComboBoxItem item; > > > comboBox.SuspendLayout(); > > collection = comboBox.Items; > > collection.Clear(); > > > foreach (KeyValuePair<string, string> pair in items) > > { > > item = new RadComboBoxItem(pair.Key, pair.Value); > > item.Name = pair.Key; > > collection.Add(item); > > } > > > comboBox.ResumeLayout(); > > } > > > Due the order of SuspendLayout, clearing items, adding items, and > > ResumeLayout being important I want to create an ordered test. > > > [TestMethod] > > public void AddItems_call_in_specific_order() > > { > > RadItemCollection collection; > > RadComboBox comboBox; > > MockRepository repository; > > > repository = new MockRepository(); > > collection = repository.StrictMock<RadItemCollection>(); > > comboBox = repository.StrictMock<RadComboBox>(); > > > using (repository.Ordered()) > > { > > comboBox.Expect(c => c.SuspendLayout()); > > comboBox.Expect(c => c.Items).Return(collection); > > collection.Expect(c => c.Clear()); > > collection.Expect(c => > > c.Add(null)).IgnoreArguments().Return(0); > > comboBox.Expect(c => c.ResumeLayout()); > > } > > > using (repository.Playback()) > > { > > comboBox.AddItems(testItems); > > } > > } > > > I receive an error at the collection.Expect for the c.Add as follows: > > > System.InvalidOperationException: Type 'System.Int32' doesn't match > > the return type 'System.Void' for method > > 'RadItemCollection.OnInsertComplete(missing parameter, missing > > parameter);'. > > > As I am new to using the Rhino Mock framework I don’t understand this > > error. My function AddItems doesn’t call OnInsertComplete. The test > > function doen’t call OnInsertComplete. I thought the purpose of > > using a mock framework it that the framework emits code to stand in > > place of the real code. I don’t understand why I am getting this > > error because OnInsertComplete is not being tested and should not even > > exist. > > > I am assuming OnInsertComplete is a private function because I don’t > > have access to the function to do an Expect. The most important > > question is how do I fix my test? I tried changing StrickMock to all > > the different variations including Stub. Is there a way to emulate > > the OnInsertComplete command?- Hide quoted text - > > - Show quoted text - -- 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.
