Пример #1
0
        private List <IValidatorRunEntry> RunValidatorInstance(ValidatorInstanceInfo info)
        {
            var             startTime      = DateTime.Now;
            IValidatorProxy validatorProxy = null;

            try
            {
                validatorProxy = _validatorProvider.GetValidatorProxy(info.ValidatorId);
                IValidatorInstance validatorInstance = _validatorProvider.GetValidatorInstance(info.ValidatorId, info.ValidatorInstanceId);

                log.Debug("Validator: {ValidatorId}  Version:  {ValidatorVersion}{NewLine}   Description:  {Description}", validatorProxy.ValidatorId, validatorProxy.Version.ToString(), Environment.NewLine, validatorProxy.Description);
                log.Debug("ValidatorInstance: {Name}  Description: {Description} beginning to validate.", validatorInstance.Name, validatorInstance.Description);

                IValidator               validator = validatorProxy.Create(validatorInstance);
                IValidatorContext        vc        = new ValidatorContext();
                IList <IValidatorResult> results   = validator.Execute(vc);

                var endTime = DateTime.Now;

                log.Debug("ValidatorInstance: {Name} finished validating. Start: {start}  End: {end}", validatorInstance.Name, startTime.ToString(), endTime.ToString());
                log.Debug("ValidatorInstance: {Name} returned {resultCount} results.", validatorInstance.Name, results.Count);

                List <IValidatorRunEntry> runEntries = results.Select(x =>
                                                                      new ValidatorRunEntry(startTime, endTime, x, validator.FilterSequence)
                {
                } as IValidatorRunEntry).ToList();

                return(runEntries);
            }
            catch (Exception ex)
            {
                log.Error(ex, "{ValidatorProxy} execution caused Error: {Message}", validatorProxy.ValidatorId, ex.Message);

                var vr = new ValidatorResult(validatorProxy.ValidatorId, ex.Message, ValidatorResultCode.Error, UnhandledExceptionResultCode);

                var vre = new ValidatorRunEntry(startTime, DateTime.Now, vr);

                return(new List <IValidatorRunEntry>()
                {
                    vre
                });
            }
        }
Пример #2
0
        public void AddScheduleToValidationServerVerificationWorks(IValidatorRunner validatorRunner, IScheduleCallback scheduleCallbacker, IValidationScheduler validatorScheduler, IValidatorProvider validatorProvider, IList <IValidatorInstance> validatorInstancesToReturn, string unknownInstanceId, string includedAndNotScheduledValidatorIdInstanceId,
                                                                   string includedAndScheduledValidatorIdInstanceId, string includedAndScheduledValidatorId, string includedAndNotScheduledValidatorId, string unknownProxyId, IList <IValidatorProxy> validatorProxiesToReturn, IValidationResultHandler[] notificationHandler, IPublishEndpoint publishEndpoint)
        {
            var includedProxy    = Substitute.For <IValidatorProxy>();
            var includedInstance = Substitute.For <IValidatorInstance>();

            includedProxy.ValidatorId.ReturnsForAnyArgs(includedAndNotScheduledValidatorId);
            includedInstance.ValidatorInstanceId.ReturnsForAnyArgs(includedAndNotScheduledValidatorIdInstanceId);

            var includedAndScheduledProxy    = Substitute.For <IValidatorProxy>();
            var includedAndScheduledInstance = Substitute.For <IValidatorInstance>();

            includedAndScheduledProxy.ValidatorId.ReturnsForAnyArgs(includedAndScheduledValidatorId);
            includedAndScheduledInstance.ValidatorInstanceId.ReturnsForAnyArgs(includedAndScheduledValidatorIdInstanceId);

            validatorProvider.GetValidatorProxy(includedProxy.ValidatorId).Returns(includedProxy);
            validatorProvider.GetValidatorProxy(includedAndScheduledProxy.ValidatorId).Returns(includedAndScheduledProxy);

            validatorProvider.GetValidatorInstance(includedAndScheduledValidatorId, includedAndScheduledValidatorIdInstanceId).Returns(includedAndScheduledInstance);

            validatorProvider.GetValidatorInstance(includedAndNotScheduledValidatorId, includedAndNotScheduledValidatorIdInstanceId).Returns(includedInstance);

            validatorScheduler.IsValidationScheduled(includedAndNotScheduledValidatorId, includedAndNotScheduledValidatorIdInstanceId).Returns(false);

            validatorScheduler.IsValidationScheduled(includedAndScheduledValidatorId, includedAndScheduledValidatorIdInstanceId).Returns(true);


            validatorProvider.When(x => x.GetValidatorProxy(Arg.Is <string>(d => d != includedAndNotScheduledValidatorId && d != includedAndScheduledValidatorId))).Do(g => { throw new Exception(); });

            validatorProvider.When(x => x.GetValidatorInstance(Arg.Any <string>(), Arg.Is <string>(d => d != includedAndNotScheduledValidatorIdInstanceId && d != includedAndScheduledValidatorIdInstanceId))).Do(g => { throw new Exception(); });

            var vs = new ValidationServer(validatorProvider, validatorRunner, validatorScheduler, scheduleCallbacker, publishEndpoint, notificationHandler);

            ScheduleRequest validRequest = new ScheduleRequest(includedProxy.ValidatorId, includedInstance.ValidatorInstanceId, "* * * * *");
            ScheduleRequest requestWithInValidInstance = new ScheduleRequest(includedProxy.ValidatorId, unknownInstanceId, "* * * * *");
            ScheduleRequest requestWithInValidProxy    = new ScheduleRequest(unknownProxyId, unknownInstanceId, "* * * * *");
            ScheduleRequest alreadyScheduledRequest    = new ScheduleRequest(includedAndScheduledValidatorId, includedAndScheduledValidatorIdInstanceId, "* * * * *");

            //This do not throw - Pass Verification
            vs.AddValidationsToSchedule(new List <ScheduleRequest>()
            {
                validRequest
            });

            //This throw cause proxy is not available
            Assert.ThrowsAny <Exception>(() => vs.AddValidationsToSchedule(new List <ScheduleRequest>()
            {
                requestWithInValidInstance
            }));

            //This throws cause instance is not available
            Assert.ThrowsAny <Exception>(() => vs.AddValidationsToSchedule(new List <ScheduleRequest>()
            {
                requestWithInValidInstance
            }));

            //This throws cause item is already scheduled is not available
            Assert.ThrowsAny <Exception>(() => vs.AddValidationsToSchedule(new List <ScheduleRequest>()
            {
                alreadyScheduledRequest
            }));
        }