The exaplanation? -- Fabio Maulo
El 04/08/2010, a las 21:45, "Jérôme Avoustin" <[email protected]> escribió: > I've just found something... but there's still a problem I don't > understand ! :) > > In fact, public methods of ValidatorEngine seem to be virtual ! > That's what I found in the source code : > > public virtual InvalidValue[] Validate(object entity, params object[] > activeTags) > > More than that, there is a test that test if ValidatorEngine public > methods are virtual : > > [Test] > public void CanMockMethods() > { > int countNonVirtualMethods = (from m in typeof > (ValidatorEngine).GetMethods() > where !m.IsVirtual && > m.IsPublic && m.Name != "GetType" > select m).Count(); > > Assert.AreEqual(0, countNonVirtualMethods, "Every public > method OR property should be virtual for mocking"); > } > > BUT, when I mock one of these methods (Validate), I have this message > with Moq : > System.ArgumentException : Invalid setup on a non-overridable member: > v => > v.Validate(value(JAN.Helpers.Tests.NHibernate.Validator.ValidatorTest > +<>c__DisplayClass7).testParameter, null) > > AND, when I use reflector on ValidatorEngine, the Validate method is > not marked as virtual !!! > > I use the version 1.2.0.3001. > Is there a problem with this revision ? > > Thanks for the explanation ! :) > > Jérôme > > > On 5 août, 02:09, Jérôme Avoustin <[email protected]> wrote: >> Hi ! >> >> I'd like to use ValidatorEngine in my classes. >> I inject a singleton instance to all these classes, thanks to Autofac. >> But now I want to unit test my classes, and I can't find a way to mock >> ValidatorEngine (yes ! I'm a mockist !) : no interface and no virtual >> methods... like a .NET class in fact ! :) (Yes I know about Typemock >> Isolator and mocks frameworks like that, but I think they encourage >> bad design...) >> >> So, since MS did a reaaaaaally bad choice by not making methods >> virtual by default (fu#*$ing sh%µ*t !!), is there a way, in NHibernate >> Validator framework, to handle this ? >> >> Thanks ! >> >> Jérôme > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" 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/nhusers?hl=en. > -- You received this message because you are subscribed to the Google Groups "nhusers" 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/nhusers?hl=en.
