1
I Use This!
Activity Not Available

News

Posted over 11 years ago by mariellen
Hi Jeremy Thanks for your response. I am calling the validator with ruleset in my code like this: var results = _userDtoValidator.Validate(userDto, ruleSet: Rulesets.UserOptOutOfEmails); where RuleSets.UserOptOutOfEmails is just the name of ... [More] the ruleset I will try your suggestion anyway just for interest's sake but thanks for the explanation regarding how I should be testing. I do have unit tests that verify the validators behave correctly but I wasn't sure if in my service/controller/integration/somethingelse tests I should replicate all the rule checking... or just ensure that the validator was called correctly and trust the rest. What is the best way to verify that I have correctly called my validators where I need to (and not just totally left out code accidentally)? What do other people do for this sort of thing.. ? I have a lot to learn about testing! Sorry I know that this is really off topic advice (and I might not be wording my question terribly well either). It's so much easier asking someone directly "what should I do" sometimes than trying to garner best practices online, especially when I am only just figuring out the differences between mocks, dummies, stubs etc etc.. I used to use the words almost interchangeably and I know I still get it wrong now. the above can be taken as rhetorical questions, if it's too tiring to answer :) thanks again. Mariellen [Less]
Posted over 11 years ago by JeremyS
Hi It depends on how you're calling the validator. How are you specifying the ruleset in your calling code? I have never used NSubstitute, so I can't help with that, but it should provide a way of checking parameters of the method being invoked ... [More] , so it should be possible to set up the mock to expect the correct ruleset is being passed in. You should be able to inspect the ValidationContext in the last line of your test - it has a Selector property on it that should be an instance of RulesetValidatorSelector. That being said, if you're new to unit testing and TDD I'd actually suggest that you stay away from these types of tests using mocks. Mocks tend to lead to very brittle tests as they encourage testing the implementation of your code (ie how the various components interact with each other, which methods are being called etc), meaning that as soon as you change the implementation then your tests break (which will happen often if you're refactoring). It's far more useful to test behaviour (ie, the end result of what your code is producing) than how the components interact with each other. This way, you can refactor your code as much as you need to, but the tests will not need changing as you're only testing for the end result. Jeremy [Less]
Posted over 11 years ago by Jeremy Skinner
Update changelog
Posted over 11 years ago by Jeremy Skinner
Merge branch 'RuleForEach-Bugfix' of https://git01.codeplex.com/forks/tripolitov/fluentvalidation
Posted over 11 years ago by JeremyS
Hi Patrick You'd need to define separate validator objects for each tenant (rather than having just 1 per model), and explicitly specify the custom messages in each of these validators that are tenant-specific. Your app would then need to implement ... [More] a custom mechanism for locating the correct validator to use for the current tenant, rather than using any of FV's built in mechanisms for validator instantiation. Jeremy [Less]
Posted over 11 years ago by JeremyS
I'm using package fluentvalidation.mvc 5 for asp.net mvc 5.1.2 (vs 2013) and followed this tutorial http://fluentvalidation.codeplex.com/wikipage?title=mvc&referringTitle=DocumentationNow I am having problem when I submit the form, MVC's ... [More] DefaultModelBinder does not validate the object. I have register ```FluentValidationModelValidatorProvider.Configure();```in global.asx, ClientValidationEnabled and UnobtrusiveJavaScriptEnabled is true in web.config.I've also downloaded latest jquery.validation package, add to BundleConfig, and in its view I've added```@section Scripts { @Scripts.Render("~/bundles/jqueryval")}```Comments: Please could you provide a small sample project that reproduces the problem. Thanks. [Less]
Posted over 11 years ago by JeremyS
Hi I personally wouldn't use FluentValidation for this. FluentValidation is designed for situations where you know the rules that you need in advance - it isn't designed for situations where you're looking to dynamically create rules on-the-fly. ... [More] When I need to do this kind of dynamic validation then I tend to encapsulate this into a separate validation object which doesn't make use of FluentValidation, but instead handles its own rule creation. There's no problem with mixing FV with other sources of validation within the same project. Jeremy [Less]
Posted over 11 years ago by JeremyS
Apologies for the late reply. I've been out of the country with no internet access. The simplest thing to do would be to use the overload of LessThan that takes a lambda. This way the call to DateTime.Now will be lazily-evaluated: RuleFor(x => ... [More] x.TradeDate).LessThan(x => DateTime.Now.Date.AddDays(1)); Alternatively if you want to turn off the instance cache for all validators then you can provide your own implementation of IValidatorFactory that doesn't make use of the InstanceCache. [Less]
Posted over 11 years ago by JeremyS
Hi AbstractValidator is designed to be used against an object whose properties being validated, so using an AbstractValidator<int> isn't something that I'd suggest doing. A better approach would probably be to define a custom property ... [More] validator (inheriting from the PropertyValidator base class) and then include your validation logic in this instead. Jeremy [Less]
Posted over 11 years ago by dsancho
Hello, you're right. I don't know what happened, maybe a nuget update? Thanks!