本文整理汇总了C#中IMessageLogger.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageLogger.SendMessage方法的具体用法?C# IMessageLogger.SendMessage怎么用?C# IMessageLogger.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessageLogger
的用法示例。
在下文中一共展示了IMessageLogger.SendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DiscoverTests
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
{
ChutzpahTracer.TraceInformation("Begin Test Adapter Discover Tests");
var settingsProvider = discoveryContext.RunSettings.GetSettings(AdapterConstants.SettingsName) as ChutzpahAdapterSettingsProvider;
var settings = settingsProvider != null ? settingsProvider.Settings : new ChutzpahAdapterSettings();
ChutzpahTracingHelper.Toggle(settings.EnabledTracing);
var testOptions = new TestOptions
{
MaxDegreeOfParallelism = settings.MaxDegreeOfParallelism,
ChutzpahSettingsFileEnvironments = new ChutzpahSettingsFileEnvironments(settings.ChutzpahSettingsFileEnvironments)
};
IList<TestError> errors;
var testCases = testRunner.DiscoverTests(sources, testOptions, out errors);
ChutzpahTracer.TraceInformation("Sending discovered tests to test case discovery sink");
foreach (var testCase in testCases)
{
var vsTestCase = testCase.ToVsTestCase();
discoverySink.SendTestCase(vsTestCase);
}
foreach (var error in errors)
{
logger.SendMessage(TestMessageLevel.Error, RunnerCallback.FormatFileErrorMessage(error));
}
ChutzpahTracer.TraceInformation("End Test Adapter Discover Tests");
}
示例2: ParseTests
private void ParseTests(StreamReader standardOutput, ITestCaseDiscoverySink discoverySink, IMessageLogger logger, string source)
{
string testcase = "";
bool testsStarted = false;
Regex testCaseMatch = new Regex(@".*\.$");
while (standardOutput.Peek() != -1)
{
string line = standardOutput.ReadLine();
if (!string.IsNullOrEmpty(line))
{
if (testCaseMatch.IsMatch(line))
{
testsStarted = true;
testcase = line.Trim();
logger.SendMessage(TestMessageLevel.Informational, string.Format("Found test case {0}", testcase.Trim('.')));
}
else if(testsStarted)
{
TestCase test = new TestCase(testcase + line.Trim(), Plugin.VisualStudio2012.GTest.GTestExecutor.ExecutorUri, source);
discoverySink.SendTestCase(test);
logger.SendMessage(TestMessageLevel.Informational, string.Format("Found test {0}", testcase + line.Trim()));
}
}
}
}
示例3: DiscoverTests
public static IEnumerable<NodeUnitTestDescriptor> DiscoverTests(string filename, IMessageLogger logger)
{
List<NodeUnitTestDescriptor> foundTests = new List<NodeUnitTestDescriptor>();
StringBuilder sbException = new StringBuilder();
Process proc = new Process();
string nodeFullPath = NodeJsHelper.LocateNodeJs();
proc.StartInfo.FileName = nodeFullPath;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.OutputDataReceived += (sender, args) =>
{
if (!string.IsNullOrEmpty(args.Data))
{
try
{
var test = JsonConvert.DeserializeObject<NodeUnitTestDescriptor>(args.Data);
foundTests.Add(test);
}
catch(JsonReaderException)
{
logger.SendMessage(TestMessageLevel.Informational, args.Data);
}
}
};
proc.ErrorDataReceived += (sender, args) =>
{
if (!string.IsNullOrEmpty(args.Data))
{
sbException.AppendLine(args.Data);
}
};
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.StandardInput.Write(Resources.Disco);
proc.StandardInput.Write("disco(\"" + filename.Replace("\\", "\\\\") + "\");");
proc.StandardInput.Close();
proc.WaitForExit();
if (sbException.Length > 0)
{
throw new Exception(sbException.ToString());
}
return foundTests;
}
示例4: DiscoverTests
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger,
ITestCaseDiscoverySink discoverySink)
{
logger.SendMessage(TestMessageLevel.Informational, Process.GetCurrentProcess().ProcessName + " Id: " + Process.GetCurrentProcess().Id.ToString());
foreach (var source in sources)
{
logger.SendMessage(TestMessageLevel.Informational, source);
}
try
{
GetTests(sources, discoverySink);
}
catch (Exception e)
{
logger.SendMessage(TestMessageLevel.Error, "exception thrown during test discovery: " + e.Message);
}
}
示例5: DiscoverTests
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
{
// indicate start of discovery
logger.SendMessage(TestMessageLevel.Informational, Strings.DISCOVERER_STARTING);
int discoveredSpecCount = 0;
int sourcesWithSpecs = 0;
Settings settings = GetSettings(discoveryContext);
foreach (string assemblyPath in sources.Distinct())
{
try
{
if (!File.Exists(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(assemblyPath)), "Machine.Specifications.dll")))
continue;
sourcesWithSpecs++;
logger.SendMessage(TestMessageLevel.Informational, string.Format(Strings.DISCOVERER_LOOKINGIN, assemblyPath));
List<TestCase> specs = discoverer.DiscoverSpecs(assemblyPath)
.Select(spec => SpecTestHelper.GetVSTestCaseFromMSpecTestCase(assemblyPath, spec, settings.DisableFullTestNameInIDE, MSpecTestAdapter.uri, CreateTrait))
.ToList();
foreach (TestCase discoveredTest in specs)
{
discoveredSpecCount++;
if (discoverySink != null)
{
discoverySink.SendTestCase(discoveredTest);
}
}
}
catch (Exception discoverException)
{
logger.SendMessage(TestMessageLevel.Error, string.Format(Strings.DISCOVERER_ERROR, assemblyPath, discoverException.Message));
}
}
// indicate that we are finished discovering
logger.SendMessage(TestMessageLevel.Informational, string.Format(Strings.DISCOVERER_COMPLETE, discoveredSpecCount, sources.Count(), sourcesWithSpecs));
}
示例6: FindTests
public List<NodejsTestInfo> FindTests(IEnumerable<string> testFiles,
string nodeExe,
IMessageLogger logger,
string workingDirectory) {
string testInfo = string.Empty;
string discoverResultFile = Path.GetTempFileName();
try {
string stdout = EvaluateJavaScript(nodeExe, string.Join(";", testFiles), discoverResultFile, logger, workingDirectory);
if (!String.IsNullOrWhiteSpace(stdout)) {
IEnumerable<String> stdoutLines = stdout.Split(new string[] {Environment.NewLine},
StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("NTVS_ERROR:")).Select(s => s.Trim().Remove(0,11));
if (stdoutLines != null && stdoutLines.Count() > 0) {
foreach (string s in stdoutLines) {
logger.SendMessage(TestMessageLevel.Error, s);
}
//There was an error during detection, return an empty set
return new List<NodejsTestInfo>();
}
}
for (int i = 0; i < 4; i++) {
try {
testInfo = File.ReadAllText(discoverResultFile);
break;
} catch (IOException) {
//We took an error processing the file. Wait a few and try again
Thread.Sleep(500);
}
}
} finally {
try {
File.Delete(discoverResultFile);
} catch (Exception) { //
//Unable to delete for some reason
//We leave the file behind in this case, its in TEMP so eventually OS will clean up
}
}
List<NodejsTestInfo> testCases = new List<NodejsTestInfo>();
List<DiscoveredTest> discoveredTests = (List<DiscoveredTest>)JsonConvert.DeserializeObject(testInfo, typeof(List<DiscoveredTest>));
if (discoveredTests != null) {
foreach (DiscoveredTest discoveredTest in discoveredTests) {
var line = discoveredTest.Line + 1;
var column = discoveredTest.Column + 1;
NodejsTestInfo test = new NodejsTestInfo(discoveredTest.File, discoveredTest.Test, Name, line, column);
testCases.Add(test);
}
}
return testCases;
}
示例7: DiscoverTests
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
{
// indicate start of discovery
logger.SendMessage(TestMessageLevel.Informational, Strings.DISCOVERER_STARTING);
int discoveredSpecCount = 0;
int sourcesWithSpecs = 0;
foreach (string assemblyPath in sources)
{
try
{
ISpecificationDiscoverer specificationDiscoverer = this.adapterFactory.CreateDiscover();
// only bother discovering if mspec is available and the assembly to san has a reference to mspec
if (specificationDiscoverer.SourceDirectoryContainsMSpec(assemblyPath) && specificationDiscoverer.AssemblyContainsMSpecReference(assemblyPath))
{
sourcesWithSpecs++;
// indicate which assembly we are looking in
logger.SendMessage(TestMessageLevel.Informational, string.Format(Strings.DISCOVERER_LOOKINGIN, assemblyPath));
// do the actual discovery
foreach (TestCase discoveredTest in this.GetTestCases((ISpecificationDiscoverer)specificationDiscoverer, assemblyPath))
{
discoveredSpecCount++;
if (discoverySink != null)
{
discoverySink.SendTestCase(discoveredTest);
}
}
}
}
catch (Exception discoverException)
{
logger.SendMessage(TestMessageLevel.Error, string.Format(Strings.DISCOVERER_ERROR, assemblyPath, discoverException.Message));
}
}
// indicate that we are finished discovering
logger.SendMessage(TestMessageLevel.Informational, string.Format(Strings.DISCOVERER_COMPLETE, discoveredSpecCount, sources.Count(), sourcesWithSpecs));
}
示例8: DiscoverTests
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
{
Guard.ArgumentNotNull("sources", sources);
Guard.ArgumentNotNull("logger", logger);
Guard.ArgumentNotNull("discoverySink", discoverySink);
try
{
RemotingUtility.CleanUpRegisteredChannels();
List<SourceSink> sourceSinks = new List<SourceSink>();
using (AssemblyHelper.SubscribeResolve())
try
{
foreach (string source in sources)
{
try
{
if (cancelled)
break;
if (IsXunitTestAssembly(source))
{
var framework = new Xunit2(SourceInformationProvider, source, configFileName: null, shadowCopy: true);
var sink = new VsDiscoveryVisitor(source, framework, logger, discoverySink, () => cancelled);
sourceSinks.Add(new SourceSink { Framework = framework, Source = source, Sink = sink });
framework.Find(includeSourceInformation: true, messageSink: sink);
}
}
catch (Exception e)
{
logger.SendMessage(TestMessageLevel.Error, String.Format("xUnit.net: Exception discovering tests from {0}: {1}", source, e));
}
}
foreach (var sourceSink in sourceSinks)
sourceSink.Sink.Finished.WaitOne();
}
finally
{
foreach (var sourceSink in sourceSinks)
{
sourceSink.Sink.Dispose();
sourceSink.Framework.Dispose();
}
}
}
catch
{
}
}
示例9: DiscoverTests
public void DiscoverTests(IEnumerable<string> sources, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
{
Guard.ArgumentNotNull("sources", sources);
Guard.ArgumentNotNull("logger", logger);
Guard.ArgumentNotNull("discoverySink", discoverySink);
foreach (string source in sources)
try {
if (IsXunitTestAssembly(source))
using (ExecutorWrapper executor = new ExecutorWrapper(source, configFilename: null, shadowCopy: true))
foreach (TestCase testCase in GetTestCases(executor))
discoverySink.SendTestCase(testCase);
}
catch (Exception e) {
logger.SendMessage(TestMessageLevel.Error, String.Format("xUnit.net: Exception discovering tests from {0}: {1}", source, e));
}
}
示例10: EvaluateJavaScript
private string EvaluateJavaScript(string nodeExePath, string testFile, string discoverResultFile, IMessageLogger logger, string workingDirectory) {
workingDirectory = workingDirectory.TrimEnd(new char['\\']);
string arguments = WrapWithQuotes(_findTestsScriptFile)
+ " " + Name +
" " + WrapWithQuotes(testFile) +
" " + WrapWithQuotes(discoverResultFile) +
" " + WrapWithQuotes(workingDirectory);
var processStartInfo = new ProcessStartInfo(nodeExePath, arguments);
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardOutput = true;
string stdout = String.Empty;
try {
using (var process = Process.Start(processStartInfo)) {
process.EnableRaisingEvents = true;
process.OutputDataReceived += (sender, args) => {
stdout += args.Data + Environment.NewLine;
};
process.ErrorDataReceived += (sender, args) => {
stdout += args.Data + Environment.NewLine;
};
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
#if DEBUG
logger.SendMessage(TestMessageLevel.Informational, String.Format(" Process exited: {0}", process.ExitCode));
#endif
}
#if DEBUG
logger.SendMessage(TestMessageLevel.Informational, String.Format(" StdOut:{0}", stdout));
#endif
} catch (FileNotFoundException e) {
logger.SendMessage(TestMessageLevel.Error, String.Format("Error starting node.exe.\n {0}", e));
}
return stdout;
}
示例11: Initialize
// The Adapter is constructed using the default constructor.
// We don't have any info to initialize it until one of the
// ITestDiscovery or ITestExecutor methods is called. The
// each Discover or Execute method must call this method.
protected virtual void Initialize(IMessageLogger messageLogger)
{
Verbosity = 0; // In case we throw below
AdapterVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
try
{
var registry = RegistryCurrentUser.OpenRegistryCurrentUser(@"Software\nunit.org\VSAdapter");
UseVsKeepEngineRunning = registry.Exist("UseVsKeepEngineRunning") && (registry.Read<int>("UseVsKeepEngineRunning") == 1);
ShadowCopy = registry.Exist("ShadowCopy") && (registry.Read<int>("ShadowCopy") == 1);
#if DEBUG && VERBOSE
Verbosity = 1;
#else
Verbosity = (registry.Exist("Verbosity")) ? registry.Read<int>("Verbosity") : 0;
#endif
}
catch (Exception e)
{
messageLogger.SendMessage(TestMessageLevel.Error, "Unable to access registry. Default settings will be used");
messageLogger.SendMessage(TestMessageLevel.Error, e.ToString());
}
TestEngine = new TestEngine();
TestLog = new TestLogger(messageLogger, Verbosity);
}
示例12: DiscoverTests
public void DiscoverTests(string source, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
{
foreach (var test in ExternalTestExecutor.GetTestCases(source, s => logger.SendMessage(TestMessageLevel.Error, s)).Select(c => CreateTestCase(source, c)))
discoverySink.SendTestCase(test);
}
示例13: SendMessage
private static void SendMessage(TestMessageLevel level, string message, IMessageLogger logger)
{
if (logger != null)
{
logger.SendMessage(level, message);
}
}
示例14: DiscoverTests
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) {
ValidateArg.NotNull(sources, "sources");
ValidateArg.NotNull(discoverySink, "discoverySink");
var buildEngine = new MSBuild.ProjectCollection();
try {
// Load all the test containers passed in (.pyproj msbuild files)
foreach (string source in sources) {
buildEngine.LoadProject(source);
}
foreach (var proj in buildEngine.LoadedProjects) {
using (var provider = new MSBuildProjectInterpreterFactoryProvider(_interpreterService, proj)) {
try {
provider.DiscoverInterpreters();
} catch (InvalidDataException) {
// This exception can be safely ignored here.
}
var factory = provider.ActiveInterpreter;
if (factory == _interpreterService.NoInterpretersValue) {
if (logger != null) {
logger.SendMessage(TestMessageLevel.Warning, "No interpreters available for project " + proj.FullPath);
}
continue;
}
var projectHome = Path.GetFullPath(Path.Combine(proj.DirectoryPath, proj.GetPropertyValue(PythonConstants.ProjectHomeSetting) ?? "."));
// Do the analysis even if the database is not up to date. At
// worst, we'll get no results.
using (var analyzer = new TestAnalyzer(
factory,
proj.FullPath,
projectHome,
TestExecutor.ExecutorUri
)) {
// Provide all files to the test analyzer
foreach (var item in proj.GetItems("Compile")) {
string fileAbsolutePath = CommonUtils.GetAbsoluteFilePath(projectHome, item.EvaluatedInclude);
string fullName;
try {
fullName = ModulePath.FromFullPath(fileAbsolutePath).ModuleName;
} catch (ArgumentException) {
if (logger != null) {
logger.SendMessage(TestMessageLevel.Warning, "File has an invalid module name: " + fileAbsolutePath);
}
continue;
}
try {
using (var reader = new StreamReader(fileAbsolutePath)) {
analyzer.AddModule(fullName, fileAbsolutePath, reader);
}
} catch (FileNotFoundException) {
// user deleted file, we send the test update, but the project
// isn't saved.
#if DEBUG
} catch (Exception ex) {
if (logger != null) {
logger.SendMessage(TestMessageLevel.Warning, "Failed to discover tests in " + fileAbsolutePath);
logger.SendMessage(TestMessageLevel.Informational, ex.ToString());
}
}
#else
} catch (Exception) {
if (logger != null) {
logger.SendMessage(TestMessageLevel.Warning, "Failed to discover tests in " + fileAbsolutePath);
}
}
#endif
}
示例15: DiscoverTests
/// <summary>
/// ITestDiscover, Given a list of test sources this method pulls out the test cases
/// </summary>
/// <param name="sources">List of test sources passed from client (Client can be VS or command line)</param>
/// <param name="discoveryContext">Context and runSettings for current run. Discoverer pulls out the tests based on current context</param>
/// <param name="logger">Used to relay messages to registered loggers</param>
/// <param name="discoverySink">Callback used to notify client upon discovery of test cases</param>
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) {
ValidateArg.NotNull(sources, "sources");
ValidateArg.NotNull(discoverySink, "discoverySink");
ValidateArg.NotNull(logger, "logger");
using (var buildEngine = new MSBuild.ProjectCollection()) {
try {
// Load all the test containers passed in (.njsproj msbuild files)
foreach (string source in sources) {
buildEngine.LoadProject(source);
}
foreach (var proj in buildEngine.LoadedProjects) {
var projectHome = Path.GetFullPath(Path.Combine(proj.DirectoryPath, "."));
Dictionary<string, List<TestFileEntry>> testItems = new Dictionary<string,List<TestFileEntry>>(StringComparer.OrdinalIgnoreCase);
// Provide all files to the test analyzer
foreach (var item in proj.Items.Where(item => item.ItemType == "Compile" || item.ItemType == "TypeScriptCompile")) {
//Check to see if this is a TestCase
string value = item.GetMetadataValue("TestFramework");
if (!TestContainerDiscoverer.IsValidTestFramework(value)) {
continue;
}
string fileAbsolutePath = CommonUtils.GetAbsoluteFilePath(projectHome, item.EvaluatedInclude);
bool typeScriptTest = TypeScript.TypeScriptHelpers.IsTypeScriptFile(fileAbsolutePath);
if(typeScriptTest){
fileAbsolutePath = TypeScript.TypeScriptHelpers.GetTypeScriptBackedJavaScriptFile(proj,fileAbsolutePath);
} else if (!Path.GetExtension(fileAbsolutePath).Equals(".js", StringComparison.OrdinalIgnoreCase)) {
continue;
}
List<TestFileEntry> fileList;
if (!testItems.TryGetValue(value, out fileList)){
fileList = new List<TestFileEntry>();
testItems.Add(value, fileList);
}
fileList.Add(new TestFileEntry(fileAbsolutePath,typeScriptTest));
}
//Debug.Fail("Before Discover");
DiscoverTests(testItems, proj, discoverySink, logger);
}
} catch (Exception ex) {
logger.SendMessage(TestMessageLevel.Error, ex.Message);
throw;
} finally {
// Disposing buildEngine does not clear the document cache in
// VS 2013, so manually unload all projects before disposing.
buildEngine.UnloadAllProjects();
}
}
}