1
I Use This!
Activity Not Available

News

Posted about 11 years ago by Jeremy Skinner
Update changelog
Posted about 11 years ago by Jeremy Skinner
Merge pull request #31 from Kukkimonsuta/master Allow nullable target properties for greater/less validators
Posted about 11 years ago by JeremyS
Hi Apologies for the late reply, I've been out of the country without internet access. I'm not able to reproduce this. I created a blank PCL project targeting NET 4.5, Silverlight 5, WP8, Windows Store (Win 8 and higher) and then ran the ... [More] following in the package manager console: install-package FluentValidation The PCL version of FluentValidation was successfully installed. Jeremy [Less]
Posted about 11 years ago by Jeremy Skinner
Added Czech and Finish translation of error messages
Posted about 11 years ago by JeremyS
Czech and Finish translations resx files attached
Posted about 11 years ago by JeremyS
Czech and Finish translations resx files attachedComments: Added in latest commit - thanks
Posted about 11 years ago by mariellen
Hi there Apologies if this is not the appropriate place for this question... It could be an Nsubstitute question - hopefully someone can help me though... :) I use a lot of rulesets for the validation in different scenarios in my website. I have ... [More] just started getting into TDD [read noob]. I am hoping to find a way to verify which Ruleset was used to validate my objects. I am using NSubstitute. Here is an example of my UserDtoValidator ruleset that I call from my UserService when someone wants to opt out of emails from my site. // Requesting to opt out of emails RuleSet(Rulesets.UserOptOutOfEmails, () => RuleFor(x => x.EmailAddress) .Cascade(CascadeMode.StopOnFirstFailure) .NotEmpty().WithState(x => ValidationTypes.Error) .WithLocalizedMessage(() => ValidationMessages.UserOptOutOfEmailsEmailNotNull) .EmailAddress().WithState(x => ValidationTypes.Error) .WithLocalizedMessage(() => ValidationMessages.UserOptOutOfEmailsEmailValid) .Length(0, 200).WithState(x => ValidationTypes.Error) .WithLocalizedMessage( () => ValidationMessages.UserOptOutOfEmailsEmailLessThan200Characters)); In my UserService OptOutOfEmailsFromSite method, I validate thus: var results = _userDtoValidator.Validate(userDto, ruleSet: Rulesets.UserOptOutOfEmails); if (!results.IsValid) { responseDto.IsSuccessful = false; MessagesHelper.HandleValidationResults(results, responseDto); return responseDto; } In my tests, I do the following, to verify a call was made to the validator from the service. Just to make sure I don't accidentally skip the validation... [TestMethod] public void OptOutOfEmails_ShouldCallUserDtoValidatorWithCorrectRuleset() { var userDtoValidator = Substitute.For<UserDtoValidator>(); _mockedUserService = Substitute.For<UserService>(userDtoValidator); var userDto = new UserDto(); var response = _mockedUserService.OptOutOfEmailsFromSite(userDto, _clientRequestDto); var x = userDtoValidator.Received(1).Validate(Arg.Any<ValidationContext<UserDto>>()); } This works great except I would like to verify that the correct ruleset was called (because I cut and paste methods a LOT and sometimes forget to replace the ruleset in the method e.g. so my OptOut method calls RuleSets.UserForgotPassword instead of RuleSets.UserOptOutOfEmailswhich I may not pick up on immediately and may actually pass more often than not. I am not sure how to do this, without adding extra methods or variables elsewhere to track the ruleset. It would just be nice if I could add it into that existing line of code. I did struggle with even getting that code working, I am really new to NSubstitute so there is probably a way to do it.. Thank you very much for your assistance and thank you to the authors for writing this code, it's lovely to work with. Mariellen [Less]
Posted about 11 years ago by sychare
I may be misunderstanding but I'm having trouble using MustAsync in Silverlight. It seems to be hanging and not returning after task completion. The rule is defined as: RuleFor(x => x.SomeInput) .MustAsync(Test) ... [More] .WithMessage("Input is incorrect"); With the following methods: private async Task<bool> Test(string someInput) { var result = await TestInner(); return result; } private Task<bool> TestInner() { var taskCompletionSource = new TaskCompletionSource<bool>(); TaskEx.Run(() => { Thread.Sleep(1000); taskCompletionSource.TrySetResult(false); }); return taskCompletionSource.Task; } A breakpoint on "taskCompletionSource.TrySetResult(false);" is always hit, however "return result;" is never reached. If this is something I'm doing wrong any guidance would be greatly appreciated! Many thanks, Wayne [Less]
Posted about 11 years ago by leej0nes
Resolved using above. Was calling similar code elsewhere with errors.
Posted about 11 years ago by leej0nes
Hi Jeremy, I'm loving FluentValidation. Thanks for all the effort you have put into it however I'm having an issue with Rulesets and WebForms. There seems to be no way to specify with Ruleset to use when calling Validate. Unfortunately I've ... [More] deleted my initial code that attempted to use the Rulesets but am currently trying this method found on the net: Errors = new List<ValidationFailure>(); var validator = GetType().GetCustomAttributes(typeof(ValidatorAttribute), true)[0] as ValidatorAttribute; // ReSharper disable once PossibleNullReferenceException var validatorType = Activator.CreateInstance(validator.ValidatorType) as IValidator; // ReSharper disable once PossibleNullReferenceException var result = validatorType .Validate( new ValidationContext<DebtorSearchModel>( this, new PropertyChain(), new RulesetValidatorSelector("NameOrNumber"))); IsValid = result.IsValid; Errors = result.Errors; return IsValid; Are you able to help? [Less]