2
using System.Collections.Generic;
5
using Concordion.Internal.Commands;
7
using Concordion.Internal;
8
using Concordion.Internal.Util;
10
using System.Text.RegularExpressions;
11
using System.Reflection;
13
namespace Concordion_Config.Spec.Command
15
public class BannedWordCommand : AbstractCommand
17
public override void Execute(CommandCall commandCall, IEvaluator evaluator, IResultRecorder resultRecorder)
19
String commandName = GetType().Name;
20
Check.IsFalse(commandCall.HasChildCommands, "Nesting commands inside a '" + commandName + "' is not supported");
21
var evalString=commandCall.Expression;
22
Element element = commandCall.Element;
23
Check.NotNull(evalString, "The " + commandName + " attribute must be set for an element containing " + commandName);
25
object fixture = evaluator.Fixture;
26
MethodInfo theMethod = fixture.GetType().GetMethod(evalString, new Type[] { typeof(string) });
27
if (theMethod == null)
29
throw new Exception("Fixture: " + fixture.GetType().FullName + " does not contain method named [" + evalString + "(string)]");
31
object result=theMethod.Invoke(fixture,new object[]{element.Text});
34
element.AddStyleClass("success");
35
resultRecorder.Record(Result.Success);
38
String bannedWord = result as String;
39
if (bannedWord == null)
41
throw new Exception("Method method named [" + evalString + "(string)] in " + fixture.GetType().FullName + " did not return string");
45
element.AddStyleClass("failure");
46
resultRecorder.Record(Result.Failure);
47
Element span=new Element("span");
48
span.AddStyleClass("commentary");
49
span.AppendText("Banned word ["+bannedWord+"] used");
50
element.AppendChild(span);
55
public override void Setup(CommandCall commandCall, IEvaluator evaluator, IResultRecorder resultRecorder) { }
56
public override void Verify(CommandCall commandCall, IEvaluator evaluator, IResultRecorder resultRecorder) { }