public void XorSolutions( ) { IRuleChecker <IList <string> > rc = new RuleCheckerBase <IList <string> >( ); rc.Add( new Xor <IList <string> >( new Contains <string>("a"), new Contains <string>("b"))); IList <string> list = new CList <string>( ); IViolation <IList <string> > violation = rc.Check(list); Assert.IsNotInstanceOf <NonViolation <IList <string> > >(violation); ISolution <IList <string> >[] solutions = violation.Solutions.ToArray( ); Assert.AreEqual(2, solutions.Length); IAction <IList <string> >[] actions1 = solutions[0].Actions.ToArray( ); IAction <IList <string> >[] actions2 = solutions[1].Actions.ToArray( ); Assert.AreEqual(1, actions1.Length); Assert.AreEqual(1, actions2.Length); Assert.AreEqual(1, actions1.Count(a => a is Add <string>)); Assert.AreEqual(0, actions1.Count(a => a is Remove <string>)); Assert.AreEqual(1, actions2.Count(a => a is Add <string>)); Assert.AreEqual(0, actions2.Count(a => a is Remove <string>)); IAction <IList <string> >[] allActions = actions1.Union(actions2).ToArray( ); Assert.AreEqual(1, allActions.Count(a => a is Add <string> add && add.Target == "a")); Assert.AreEqual(1, allActions.Count(a => a is Add <string> add && add.Target == "b")); Assert.AreEqual(0, allActions.Count(a => a is Remove <string> rem && rem.Target == "a")); Assert.AreEqual(0, allActions.Count(a => a is Remove <string> rem && rem.Target == "b")); }
public void GrcCtorTest1( ) { Exception exc = null; try { IList <string> list = new CList <string>( ); IList <IRule <IList <string> > > rules = new List <IRule <IList <string> > >( ); GenericRuleChecker <IList <string> > grc = new GenericRuleChecker <IList <string> >(rules, list); Assert.AreEqual(0, grc.Subject.Count); } catch (Exception e) { exc = e; } Assert.IsNull(exc); }
public void GrcCtorTest2( ) { Exception exc = null; try { IList <string> list = new CList <string>( ); IList <IRule <IList <string> > > rules = new List <IRule <IList <string> > > { new Contains <string>("hello") }; GenericRuleChecker <IList <string> > grc = new GenericRuleChecker <IList <string> >(rules, list); } catch (Exception e) { exc = e; } Assert.IsNotNull(exc); }
public void GrcCtorTest3( ) { Exception exc = null; try { IList <string> list = new CList <string>( ); IList <IRule <IList <string> > > rules = new List <IRule <IList <string> > > { new Contains <string>("hello") }; GenericRuleChecker <IList <string> > grc = new GenericRuleChecker <IList <string> >( rules, list, true); Assert.AreEqual(1, grc.Subject.Count); Assert.AreEqual("hello", grc.Subject[0]); } catch (Exception e) { exc = e; } Assert.IsNull(exc); }