private TestHostContext Setup( [CallerMemberName] string name = "", IssueMatchersConfig matchers = null, ContainerInfo jobContainer = null, ContainerInfo stepContainer = null) { matchers?.Validate(); _onMatcherChanged = null; _issues = new List <Tuple <DTWebApi.Issue, string> >(); _messages = new List <string>(); _commands = new List <string>(); var hostContext = new TestHostContext(this, name); _variables = new Variables(hostContext, new Dictionary <string, DTWebApi.VariableValue>()); _executionContext = new Mock <IExecutionContext>(); _executionContext.Setup(x => x.Global) .Returns(new GlobalContext { Container = jobContainer, Variables = _variables, WriteDebug = true, }); _executionContext.Setup(x => x.GetMatchers()) .Returns(matchers?.Matchers ?? new List <IssueMatcherConfig>()); _executionContext.Setup(x => x.Add(It.IsAny <OnMatcherChanged>())) .Callback((OnMatcherChanged handler) => { _onMatcherChanged = handler; }); _executionContext.Setup(x => x.AddIssue(It.IsAny <DTWebApi.Issue>(), It.IsAny <string>())) .Callback((DTWebApi.Issue issue, string logMessage) => { _issues.Add(new Tuple <DTWebApi.Issue, string>(issue, logMessage)); }); _executionContext.Setup(x => x.Write(It.IsAny <string>(), It.IsAny <string>())) .Callback((string tag, string message) => { _messages.Add($"{tag}{message}"); hostContext.GetTrace().Info($"{tag}{message}"); }); _commandManager = new Mock <IActionCommandManager>(); _commandManager.Setup(x => x.TryProcessCommand(It.IsAny <IExecutionContext>(), It.IsAny <string>(), It.IsAny <ContainerInfo>())) .Returns((IExecutionContext executionContext, string line, ContainerInfo container) => { if (line.IndexOf("##[some-command]") >= 0) { _commands.Add(line); return(true); } return(false); }); _outputManager = new OutputManager(_executionContext.Object, _commandManager.Object, stepContainer); return(hostContext); }
private void Add(IssueMatcherConfig matcher) { var matchers = new IssueMatchersConfig { Matchers = { matcher, }, }; matchers.Validate(); _onMatcherChanged(null, new MatcherChangedEventArgs(matcher)); }