Пример #1
0
        public BlockViewModel(IWindowManager windowManager)
        {
            _windowManager = windowManager;
            LoadDomainBlacklist();
            LoadAddressBlacklist();
            var localDomainRules = new CollectionContainer {
                Collection = DomainBlacklist.LocalRules
            };
            var remoteDomainRules = new CollectionContainer {
                Collection = DomainBlacklist.RemoteRules
            };
            var addressRules = new CollectionContainer {
                Collection = AddressBlacklist.Rules
            };

            DomainRuleCollection.Add(localDomainRules);
            DomainRuleCollection.Add(remoteDomainRules);
            AddressRuleCollection.Add(addressRules);
            _isWorking = false;
            SetPlugins(MainViewModel.Instance.Plugins);

            if (File.Exists(_domainBlacklistPath))
            {
                UpdateDomainBlacklistPathInfoString();
            }

            if (File.Exists(_addressBlacklistPath))
            {
                UpdateAddressBlacklistPathInfoString();
            }
        }
        public void ThenClause_WithRuleCollection_CollectionRulesAreRun()
        {
            var rule = CollectionPropertyRule.CreateCollectionPropertyRule<Patient, IEnumerable<Address>> (
                p => p.Addresses, "Rule 1" );
            var addressRuleCollection = new AddressRuleCollection ();
            var ruleCalled = false;
            addressRuleCollection.NewRule ( () => addressRuleCollection.MyEmptyRule ).When ( c => ruleCalled = true );
            rule.WithRuleCollection ( addressRuleCollection );

            var patient = new Patient ();
            patient.Addresses.Add ( new Address ( null, null, null, null, null ) );

            var ruleEngineContext = new RuleEngineContext<Patient> ( patient );

            foreach ( var thenClause in rule.ThenClauses )
            {
                thenClause ( ruleEngineContext );
            }

            Assert.IsTrue ( ruleCalled );
        }
Пример #3
0
        public void ThenClause_WithRuleCollection_CollectionRulesAreRun()
        {
            var rule = CollectionPropertyRule.CreateCollectionPropertyRule <Patient, IEnumerable <Address> > (
                p => p.Addresses, "Rule 1");
            var addressRuleCollection = new AddressRuleCollection();
            var ruleCalled            = false;

            addressRuleCollection.NewRule(() => addressRuleCollection.MyEmptyRule).When(c => ruleCalled = true);
            rule.WithRuleCollection(addressRuleCollection);

            var patient = new Patient();

            patient.Addresses.Add(new Address(null, null, null, null, null));

            var ruleEngineContext = new RuleEngineContext <Patient> (patient);

            foreach (var thenClause in rule.ThenClauses)
            {
                thenClause(ruleEngineContext);
            }

            Assert.IsTrue(ruleCalled);
        }