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.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---