Ejemplo n.º 1
0
        public CefMessage(
            DateTimeOffset startTime,
            string hostName,
            string deviceVendor,
            string deviceProduct,
            string deviceVersion,
            int deviceEventClassId,
            string name,
            CefSeverity severity)
        {
            Extensions = new Extensions {
                StartTime = startTime, SourceHostName = hostName
            };
            DeviceVendor       = deviceVendor;
            DeviceProduct      = deviceProduct;
            DeviceVersion      = deviceVersion;
            DeviceEventClassId = deviceEventClassId;
            Name     = name;
            Severity = severity;
            HostName = hostName;

            var result = RulesValidator.Validate(new CefMessageRule(), this);

            if (!result.IsValid)
            {
                throw new CefMessageValidationException(result.Results.ToErrorsString());
            }
        }
        public void ValidateUnitTest()
        {
            Config config = new Config();

            config.Load("unit_test_config.xml");
            // MaxAgeRule validation
            Assert.IsTrue(RulesValidator.Validate(config.Bundles["0"].Rules, 15, false, 0, null));
            Assert.IsFalse(RulesValidator.Validate(config.Bundles["0"].Rules, 18, false, 0, null));
            // MinAgeRule and StudentRule validation
            Assert.IsTrue(RulesValidator.Validate(config.Bundles["1"].Rules, 18, true, 0, null));
            Assert.IsTrue(RulesValidator.Validate(config.Bundles["1"].Rules, 25, true, 12000, null));
            Assert.IsFalse(RulesValidator.Validate(config.Bundles["1"].Rules, 17, true, 12000, null));
            Assert.IsFalse(RulesValidator.Validate(config.Bundles["1"].Rules, 18, false, 12000, null));
            // MinAgeRule and MinIncomeRule validation
            Assert.IsTrue(RulesValidator.Validate(config.Bundles["2"].Rules, 18, false, 5000, null));
            Assert.IsTrue(RulesValidator.Validate(config.Bundles["2"].Rules, 25, true, 5000, null));
            Assert.IsFalse(RulesValidator.Validate(config.Bundles["2"].Rules, 25, true, 0, null));
            Assert.IsFalse(RulesValidator.Validate(config.Bundles["2"].Rules, 17, false, 10000, null));
            // IncludeOneOfProductRule validation
            List <string> products = new List <string>();

            products.Add("2");
            products.Add("3");
            products.Add("4");
            Assert.IsTrue(RulesValidator.Validate(config.Products["3"].Rules, 22, false, 21000, products));
            products.RemoveAt(1);
            Assert.IsFalse(RulesValidator.Validate(config.Products["3"].Rules, 22, false, 21000, products));
        }
Ejemplo n.º 3
0
 public ValidationResult Validate(object message)
 {
     return(RulesValidator.Validate(this, (T)message));
 }