public void CanRunCommand() { ICommand command = new TestCommand(); ICommunicator com = new TestCommunicator(); AlchemyController con = new AlchemyController( new RuleSet() ); command.Run( "input", con, com ); }
public void DisplayRuleDisplaysNothingIfApplicable() { IPreCommand c = new DisplayRecommendedRule(); var rs = new RuleSet(); var a = new AlchemyController( rs ); var t = new TestCommunicator(); t.DisplayCalled += ( o, e ) => Assert.IsTrue( string.IsNullOrEmpty( (string) o ) ); var result = c.Run( a, t ); Assert.AreEqual( Do.KeepProcessing, result ); }
public void DisplayRuleDisplaysRuleIfApplicable() { IPreCommand c = new DisplayRecommendedRule(); var rs = new RuleSet() { FoundElements = TestTools.GenerateElements( 1 ) }; var a = new AlchemyController( rs ); var t = new TestCommunicator(); int count = 0; t.DisplayCalled += ( o, e ) => { count++; Assert.IsTrue( ( (string) o ).Contains( "+" ) ); }; var result = c.Run( a, t ); Assert.AreEqual( Do.KeepProcessing, result ); Assert.AreEqual( 1, count ); }
public void PrintCommandWontPrintIrrelevant() { ICommand command = new PrintCommand(); var comm = new TestCommunicator(); int count = 0; comm.DisplayCalled += ( a, e ) => { count++; }; var rs = new RuleSet() { Rules = new[] { new Rule( new[] { "fire", "water" }, "water" ) } }; var controller = new AlchemyController( rs ); command.Run( "?fire3", controller, comm ); Assert.AreEqual( 0, count ); }
public void MultiCommandAddsRules() { ICommand command = new AddMultiComboCommand(); var com = new TestCommunicator(); var rs = new RuleSet() { FoundElements = new[] { new Element( "fire" ), new Element( "water" ) } }; var c = new AlchemyController( rs ); command.Run( "*fire", c, com ); Assert.AreEqual( 2, rs.Rules.Length ); }
static Chemist Setup( AlchemyController controller, IEnumerable<string> input ) { var tc = new TestCommunicator(); foreach( var s in input ) tc.InputQueue.Enqueue( s ); return new Chemist( controller, tc ); }