Beispiel #1
0
 static RuleSet FetchRuleSet( string filename, int serializationTime )
 {
     var persistance = new XmlPersister( new RuleSetXmlSerializer(), new StreamFactory( filename ), serializationTime );
     var rs = !File.Exists( filename ) ? new RuleSet() : persistance.RecreateRuleSet();
     persistance.RegisterRuleSet( rs );
     return rs;
 }
        public void RuleSetOnlyNotifiesWhenStrictlyNeccessary()
        {
            var changedprops = new List<string>();
            var persister = new XmlPersister( new RuleSetXmlSerializer(), new StreamFactory( "data.xml" ), 2000 );
            var rs = persister.RecreateRuleSet();
            rs.PropertyChanged += ( s, e ) => changedprops.Add( e.PropertyName );

            var controller = new AlchemyController( rs );

            var rule = controller.RecommendNewRule();
            rule.Result = new[] { new Element( "alpha" ) };
            controller.ReportChangedRule( rule );

            Assert.AreEqual( 1, changedprops.Count( p => p.Equals( "FoundElements" ) ) );
            Assert.AreEqual( 1, changedprops.Count( p => p.Equals( "Rules" ) ) );
        }