public void GetRules_default_ones_and_injected()
        {
            //ARRANGE
            CertificateValidationRulesFactory.InstanceCreator = ValidationRuleInstanceCreatorMock.CreateInstance;
            var configuration = new CertificateValidationConfiguration
            {
                X509CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.Custom
            };
            var rule1           = typeof(CertificateValidationRuleMock1).AssemblyQualifiedName;
            var rule2           = typeof(CertificateValidationRuleMock).AssemblyQualifiedName;
            var rule3           = typeof(CertificateValidationRuleFailedMock).AssemblyQualifiedName;
            var ruleDescriptor  = new ValidationRuleDescriptor(rule1);
            var ruleDescriptor2 = new ValidationRuleDescriptor(rule2);
            var ruleDescriptor3 = new ValidationRuleDescriptor(rule3);

            configuration.ValidationRules.Add(ruleDescriptor);
            configuration.ValidationRules.Add(ruleDescriptor2);
            configuration.ValidationRules.Add(ruleDescriptor3);
            //ACT
            var rules = CertificateValidationRulesFactory.GetRules(configuration)
                        .ToList();

            //ASSERT
            Assert.AreEqual(5, rules.Count);
            Assert.IsTrue(rules.Any(x => x.GetType() == typeof(EffectiveDateRule)));
            Assert.IsTrue(rules.Any(x => x.GetType() == typeof(ExpirationDateRule)));
            Assert.IsTrue(rules.Any(x => x.GetType() == typeof(CertificateValidationRuleMock1)));
            Assert.IsTrue(rules.Any(x => x.GetType() == typeof(CertificateValidationRuleMock)));
            Assert.IsTrue(rules.Any(x => x.GetType() == typeof(CertificateValidationRuleFailedMock)));
        }
        public override void Validate(X509Certificate2 certificate)
        {
            var configiration = this._configurationProvider.GetConfiguration();
            var context       = new CertificateValidationContext(certificate);
            Func <CertificateValidationContext, Task> seed = x => Task.CompletedTask;

            var rules = CertificateValidationRulesFactory.GetRules(configiration);
            var validationDelegate = rules.Aggregate(seed, (f, next) => new Func <CertificateValidationContext, Task>(c => next.Validate(c, f)));
            var task = validationDelegate(context);

            task.Wait();
        }
        public override void Validate(X509Certificate2 certificate)
        {
            this._logProvider.LogMessage(String.Format("Validating certificate: {0}", certificate.Subject));
            var configiration = this.GetConfiguration();
            var context       = new CertificateValidationContext(certificate);
            Func <CertificateValidationContext, Task> seed = x => Task.CompletedTask;

            var rules = CertificateValidationRulesFactory.GetRules(configiration);
            var validationDelegate = rules.Aggregate(seed, (f, next) => new Func <CertificateValidationContext, Task>(c => next.Validate(c, f)));
            var task = validationDelegate(context);

            task.Wait();
        }
        public void GetRules_default_ones()
        {
            //ARRANGE
            var configuration = new CertificateValidationConfiguration
            {
                X509CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.Custom
            };

            CertificateValidationRulesFactory.InstanceCreator = ValidationRuleInstanceCreatorMock.CreateInstance;
            //ACT
            var rules = CertificateValidationRulesFactory.GetRules(configuration)
                        .ToList();

            //ASSERT
            Assert.AreEqual(2, rules.Count);
            Assert.IsTrue(rules.Any(x => x.GetType() == typeof(EffectiveDateRule)));
            Assert.IsTrue(rules.Any(x => x.GetType() == typeof(ExpirationDateRule)));
        }