Binboo.Core.Tests.Framework.ArgumentCollectingTestCaseBase.SendCommandAndCollectResult C# (CSharp) Method

SendCommandAndCollectResult() protected method

protected SendCommandAndCollectResult ( string commandLine, ParamValidator>.Expression validatorExpressions, Func argumentChecker ) : void
commandLine string
validatorExpressions ParamValidator>.Expression
argumentChecker Func
return void
        protected void SendCommandAndCollectResult(string commandLine, Expression<Func<int, ParamValidator>>[] validatorExpressions, Func<string, ArgumentRecorder, bool> argumentChecker)
        {
            try
            {
                var recorder = ArgumentRecorder.NewInstance();
                ArgumentEchoingPlugin.ArgumentRecorder = recorder;
                ArgumentEchoingPlugin.ValidatorExpressions = validatorExpressions;

                _chat.Reset();

                _mockSkype.SendMessage("user", commandLine);
                const int timeout = 1000;
                var gotAnswer = _chat.WaitForMessages(timeout);

                Assert.AreEqual(0, _errors.Count, _errors.Aggregate("", (acc, curr) => curr + "\r\n" + acc));

                Assert.IsTrue(gotAnswer, "No answer for message '{0}' in {1} ms", commandLine, timeout);

                foreach (var msg in _chat.SentMessages)
                {
                    Console.WriteLine(msg.Body);
                }

                Assert.IsTrue(argumentChecker(_chat.SentMessages.ElementAt(0).Body, recorder),
                              string.Format("Command Line: {0}\r\n   Recorded: {1}", commandLine, recorder));
            }
            catch(Exception)
            {
                ArgumentEchoingPlugin.ValidatorExpressions = null;
                ArgumentEchoingPlugin.ArgumentRecorder = null;
                throw;
            }
        }