You know I stand corrected...I looked too quickly at the class. My bad. Thanks MS for hiding constructor....(sorry for the bad advice)
On Wed, Nov 11, 2009 at 9:03 PM, TheMightyKumquat <[email protected]>wrote: > > Thanks for the reply, Tim. How would creating a mock by hand work for > a ValidationEventArgs object? Wouldn't it still run into the internal > constructor being hidden problem? > > On Nov 12, 10:06 am, Tim Barcz <[email protected]> wrote: > > The constructors are internal so subclassing is hard because you can't > call > > base. > > > > If this were me, I wouldn't use Rhino, I create a mock by hand to do what > I > > want. It's not too hard to do. > > > > On Wed, Nov 11, 2009 at 6:01 PM, TheMightyKumquat <[email protected] > >wrote: > > > > > > > > > > > > > > > > > I'm looking to confirm that the following isn't possible. > > > > > I'm trying to unit test this method: > > > private void ValidationCallback(object sender, ValidationEventArgs > > > args) > > > { > > > this._isValid = false; > > > this._schemaErrors += args.Message + Environment.NewLine; > > > } > > > > > My problem is that ValidationEventArgs has no visible constructor, so > > > instantiating it for the test gives a compilation error. From the > > > compilation error, I worked out that the constructor should have two > > > parameters, a XmlSchemaException and an XmlSeverityType enum value. > > > > > I wondered whether it might be possible to stub or mock the > > > ValidationEventArgs class, so I coded > > > > > [TestMethod] > > > public void ValidationCallbackTest() > > > { > > > string msg = "message"; > > > object [] argsForConstructor = {new XmlSchemaException(), > > > XmlSeverityType.Warning); > > > ValidationEventArgs args = MockRepository.GenerateStub(typeof > > > (ValidationEventArgs), argsForConstructor); > > > Expect.Call(args.Message).Return(msg); > > > accessor.ValidationCallback(this, args); //accessor is a private > > > accessor object, instantiated when test initializes > > > Assert.IsFalse(accessor._isValid); > > > assert.AreEqual(accessor._schemaErrors, msg + Environment.NewLine); > > > } > > > > > This test fails at runtime with the message > > > "System.NotSupportedException: Parent does not have a default > > > constructor. The default constructor must be explicitly defined." > > > > > I take it that my stub is still trying to call the constructor of the > > > actual class and is being denied access, or not finding a > > > parameterless construcor in the concrete class? I'm a bit hazy on > > > this: Ayende's notes say that "Rhino Mocks supports mocking classes as > > > well as interfaces. In fact, it can even mock classes that don't have > > > a default constructor!", so I don't know why I'm getting an error > > > saying that I need a default constructor. > > > > -- > > Tim Barcz > > Microsoft C# MVP > > Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp:// > www.twitter.com/timbarcz- Hide quoted text - > > > > - Show quoted text - > > > -- Tim Barcz Microsoft C# MVP Microsoft ASPInsider http://timbarcz.devlicio.us http://www.twitter.com/timbarcz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
