예제 #1
0
        private void SetupValidationRulesForComparisonVehicles()
        {
            RuleSet("ComparisonVehicles", () =>
            {
                // We must have at least one non-empty comparison vehicle
                RuleFor(f => f.ComparisonVehicles)
                .NotNull()
                .Must(HaveAtLeastOneComparisonVehicle)
                .WithMessage(noComparisonVehicles);

                // We need to validate each comparison vehicle in turn to ensure the properties are set
                RuleFor(f => f.ComparisonVehicles)
                .NotNull()
                .SetCollectionValidator(comparisonValidator)
                .Where(v => VehicleValidator.NotBeAnEmptyVehicle(v));

                // The forecast vehicle cannot be the same as one of the comparison vehicles
                RuleFor(f => f)
                .NotNull()
                .Must(NotHaveAForecastVehicleSameAsAComparisonVehicle)
                .WithName("Forecast")
                .WithMessage(forecastSameAsComparison)
                .WithState(f => ListForecastVehiclesSameAsComparisonVehicle(f));

                // Each comparison vehicle is checked against to collection as a whole to ensure no duplicates
                RuleFor(f => f.ComparisonVehiclesWithIndex)
                .NotNull()
                .SetCollectionValidator(duplicateValidator)
                .Where(v => VehicleValidator.NotBeAnEmptyVehicle(v));
            });
        }
예제 #2
0
 private void SetupValidationRulesForTrimMapping()
 {
     RuleSet("TrimMapping", () =>
     {
         // We need to validate each comparison vehicle in turn to ensure all trim levels have been mapped
         RuleFor(f => f.ComparisonVehiclesWithIndex)
         .NotNull()
         .SetCollectionValidator(trimMappingValidator)
         .Where(v => VehicleValidator.NotBeAnEmptyVehicle(v));
     });
 }