本文整理汇总了C#中Microsoft.Build.UnitTests.MockEngine.AssertLogContains方法的典型用法代码示例。如果您正苦于以下问题:C# MockEngine.AssertLogContains方法的具体用法?C# MockEngine.AssertLogContains怎么用?C# MockEngine.AssertLogContains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.UnitTests.MockEngine
的用法示例。
在下文中一共展示了MockEngine.AssertLogContains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NoLanguage
public void NoLanguage()
{
WriteCodeFragment task = new WriteCodeFragment();
MockEngine engine = new MockEngine(true);
task.BuildEngine = engine;
task.OutputFile = new TaskItem("foo");
bool result = task.Execute();
Assert.AreEqual(false, result);
engine.AssertLogContains("MSB3098");
}
示例2: NoFileOrDirectory
public void NoFileOrDirectory()
{
WriteCodeFragment task = new WriteCodeFragment();
MockEngine engine = new MockEngine(true);
task.BuildEngine = engine;
task.Language = "c#";
bool result = task.Execute();
Assert.AreEqual(false, result);
engine.AssertLogContains("MSB3711");
}
示例3: VerifyFindInvalidProjectReferences
public void VerifyFindInvalidProjectReferences()
{
// Create the engine.
MockEngine engine = new MockEngine();
FindInvalidProjectReferences t = new FindInvalidProjectReferences();
t.TargetPlatformVersion = "8.0";
t.TargetPlatformIdentifier = "Windows";
Dictionary<string, string> proj1 = new Dictionary<string, string>();
proj1["TargetPlatformMoniker"] = "Windows, Version=7.0";
Dictionary<string, string> proj2 = new Dictionary<string, string>();
proj2["TargetPlatformMoniker"] = "Windows, Version=8.0";
Dictionary<string, string> proj3 = new Dictionary<string, string>();
proj3["TargetPlatformMoniker"] = "Windows, Version=8.1";
Dictionary<string, string> proj4 = new Dictionary<string, string>();
proj4["TargetPlatformMoniker"] = "Windows, Version=8.2";
t.ProjectReferences = new TaskItem[] { new TaskItem("proj1.proj", proj1), new TaskItem("proj2.proj", proj2), new TaskItem("proj3.proj", proj3), new TaskItem("proj4.proj", proj4) };
t.BuildEngine = engine;
bool succeeded = t.Execute();
Assert.True(succeeded);
string warning1 = ResourceUtilities.FormatResourceString("FindInvalidProjectReferences.WarnWhenVersionIsIncompatible", "Windows", "8.0", "proj1.proj", "Windows, Version=7.0");
engine.AssertLogDoesntContain(warning1);
string warning2 = ResourceUtilities.FormatResourceString("FindInvalidProjectReferences.WarnWhenVersionIsIncompatible", "Windows", "8.0", "proj2.proj", "Windows, Version=8.0");
engine.AssertLogDoesntContain(warning2);
string warning3 = ResourceUtilities.FormatResourceString("FindInvalidProjectReferences.WarnWhenVersionIsIncompatible", "Windows", "8.0", "proj3.proj", "Windows, Version=8.1");
engine.AssertLogContains(warning3);
string warning4 = ResourceUtilities.FormatResourceString("FindInvalidProjectReferences.WarnWhenVersionIsIncompatible", "Windows", "8.0", "proj4.proj", "Windows, Version=8.2");
engine.AssertLogContains(warning4);
Assert.Equal(t.InvalidReferences.Length, 2);
Assert.Equal(t.InvalidReferences[0].ItemSpec, "proj3.proj");
Assert.Equal(t.InvalidReferences[1].ItemSpec, "proj4.proj");
}
示例4: GetResolvedRuleSetPath_FullPath_NonExistent
public void GetResolvedRuleSetPath_FullPath_NonExistent()
{
MockEngine mockEngine = new MockEngine();
ResolveCodeAnalysisRuleSet task = new ResolveCodeAnalysisRuleSet();
task.BuildEngine = mockEngine;
string codeAnalysisRuleSet = @"C:\foo\bar\CodeAnalysis.ruleset";
task.CodeAnalysisRuleSet = codeAnalysisRuleSet;
task.MSBuildProjectDirectory = null;
task.CodeAnalysisRuleSetDirectories = null;
bool result = task.Execute();
string resolvedRuleSet = task.ResolvedCodeAnalysisRuleSet;
Assert.AreEqual(expected: true, actual: result);
Assert.AreEqual(expected: null, actual: resolvedRuleSet);
mockEngine.AssertLogContains("MSB3884");
}
示例5: ErrorWhenTextSentToStandardError
public void ErrorWhenTextSentToStandardError()
{
using (MyTool t = new MyTool())
{
MockEngine engine = new MockEngine();
t.BuildEngine = engine;
t.LogStandardErrorAsError = true;
t.MockCommandLineCommands = "/C Echo 'Who made you king anyways' 1>&2";
Assert.IsFalse(t.Execute());
engine.AssertLogDoesntContain("MSB3073");
engine.AssertLogContains("Who made you king anyways");
Assert.AreEqual(-1, t.ExitCode);
Assert.AreEqual(1, engine.Errors);
}
}
示例6: TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath
public void TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath()
{
string tempDirectory = Path.Combine(Path.GetTempPath(), "TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath");
string framework41Directory = Path.Combine(tempDirectory, "MyFramework\\v4.1\\");
string redistListDirectory = Path.Combine(framework41Directory, "RedistList");
string redistListFile = Path.Combine(redistListDirectory, "FrameworkList.xml");
try
{
Directory.CreateDirectory(framework41Directory);
Directory.CreateDirectory(redistListDirectory);
string redistListContents =
"<FileList Redist='Microsoft-Windows-CLRCoreComp' IncludeFramework='v4.*' Name='Chained oh noes'>" +
"<File AssemblyName='System.Xml' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" +
"<File AssemblyName='Microsoft.Build.Engine' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" +
"</FileList >";
File.WriteAllText(redistListFile, redistListContents);
string targetFrameworkMoniker = "MyFramework, Version=v4.1";
MockEngine engine = new MockEngine();
GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
getReferencePaths.BuildEngine = engine;
getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker;
getReferencePaths.RootPath = tempDirectory;
getReferencePaths.Execute();
string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
Assert.Equal(0, returnedPaths.Length);
string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
Assert.Null(displayName);
FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker);
engine.AssertLogContains("MSB3643");
}
finally
{
if (Directory.Exists(framework41Directory))
{
Directory.Delete(framework41Directory, true);
}
}
}
示例7: InvalidDirectoryPath
public void InvalidDirectoryPath()
{
WriteCodeFragment task = new WriteCodeFragment();
MockEngine engine = new MockEngine(true);
task.BuildEngine = engine;
task.Language = "c#";
task.AssemblyAttributes = new TaskItem[] { new TaskItem("aa") };
task.OutputDirectory = new TaskItem("||invalid||");
bool result = task.Execute();
Assert.AreEqual(false, result);
engine.AssertLogContains("MSB3713");
}
示例8: ToolExeIsFoundOnToolPath
public void ToolExeIsFoundOnToolPath()
{
using (MyTool t = new MyTool())
{
MockEngine engine = new MockEngine();
t.BuildEngine = engine;
t.FullToolName = "cmd.exe";
string systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
t.ToolPath = systemPath;
t.Execute();
Assert.AreEqual(Path.Combine(systemPath, "cmd.exe"), t.PathToToolUsed);
engine.AssertLogContains("cmd.exe");
engine.Log = String.Empty;
t.ToolExe = "xcopy.exe";
t.Execute();
Assert.AreEqual(Path.Combine(systemPath, "xcopy.exe"), t.PathToToolUsed);
engine.AssertLogContains("xcopy.exe");
engine.AssertLogDoesntContain("cmd.exe");
}
}
示例9: TestGeneralFrameworkMonikerNonExistent
public void TestGeneralFrameworkMonikerNonExistent()
{
MockEngine engine = new MockEngine();
GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
getReferencePaths.BuildEngine = engine;
// Make a framework which does not exist, intentional mispelling of framework
getReferencePaths.TargetFrameworkMoniker = ".NetFramewok, Version=v99.0";
getReferencePaths.Execute();
string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
Assert.Equal(0, returnedPaths.Length);
string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
Assert.Null(displayName);
FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker);
string message = ResourceUtilities.FormatResourceString("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkMoniker.ToString());
engine.AssertLogContains(message);
}
示例10: OverrideStdOutImportanceToHigh
public void OverrideStdOutImportanceToHigh()
{
string tempFile = FileUtilities.GetTemporaryFile();
File.WriteAllText(tempFile, @"hello world");
using (MyTool t = new MyTool())
{
MockEngine engine = new MockEngine();
engine.MinimumMessageImportance = MessageImportance.High;
t.BuildEngine = engine;
t.FullToolName = "find.exe";
t.MockCommandLineCommands = "\"hello\" \"" + tempFile + "\"";
t.StandardOutputImportance = "High";
Assert.IsTrue(t.Execute());
Assert.AreEqual(0, t.ExitCode);
Assert.AreEqual(0, engine.Errors);
engine.AssertLogContains("hello world");
}
File.Delete(tempFile);
}
示例11: DoNotRetryWhenDestinationLockedDueToAcl
public void DoNotRetryWhenDestinationLockedDueToAcl()
{
string tempDirectory = Path.Combine(Path.GetTempPath(), "DoNotRetryWhenDestinationLockedDueToAcl");
string destinationFile = Path.Combine(tempDirectory, "DestinationFile.txt");
string sourceFile = Path.Combine(tempDirectory, "SourceFile.txt");
if (Directory.Exists(tempDirectory))
{
FileUtilities.DeleteDirectoryNoThrow(tempDirectory, true);
}
Directory.CreateDirectory(tempDirectory);
File.WriteAllText(destinationFile, "Destination");
File.WriteAllText(sourceFile, "SourceFile");
string userAccount = string.Format(@"{0}\{1}", System.Environment.UserDomainName, System.Environment.UserName);
FileSystemAccessRule denyFile = new FileSystemAccessRule(userAccount, FileSystemRights.Write | FileSystemRights.Delete | FileSystemRights.DeleteSubdirectoriesAndFiles | FileSystemRights.WriteData, AccessControlType.Deny);
FileSystemAccessRule denyDirectory = new FileSystemAccessRule(userAccount, FileSystemRights.DeleteSubdirectoriesAndFiles, AccessControlType.Deny);
FileSecurity fSecurity = File.GetAccessControl(destinationFile);
DirectorySecurity dSecurity = Directory.GetAccessControl(tempDirectory);
try
{
fSecurity.AddAccessRule(denyFile);
File.SetAccessControl(destinationFile, fSecurity);
dSecurity.AddAccessRule(denyDirectory);
Directory.SetAccessControl(tempDirectory, dSecurity);
Copy t = new Copy();
t.RetryDelayMilliseconds = 1; // speed up tests!
// Allow the task's default (false) to have a chance
if (useHardLinks)
{
t.UseHardlinksIfPossible = useHardLinks;
}
MockEngine engine = new MockEngine();
t.BuildEngine = engine;
t.SourceFiles = new TaskItem[] { new TaskItem(sourceFile) };
t.DestinationFiles = new TaskItem[] { new TaskItem(destinationFile) };
bool result = t.Execute();
Assert.IsFalse(result);
engine.AssertLogContains("MSB3021"); // copy failed
engine.AssertLogDoesntContain("MSB3026"); // Didn't retry
Assert.IsTrue(engine.Errors == 1);
Assert.IsTrue(engine.Warnings == 0);
}
finally
{
fSecurity.RemoveAccessRule(denyFile);
File.SetAccessControl(destinationFile, fSecurity);
dSecurity.RemoveAccessRule(denyDirectory);
Directory.SetAccessControl(tempDirectory, dSecurity);
if (Directory.Exists(tempDirectory))
{
FileUtilities.DeleteDirectoryNoThrow(tempDirectory, true);
}
}
}
示例12: SuccessAfterOneRetryContinueToNextFile
public void SuccessAfterOneRetryContinueToNextFile()
{
Copy t = new Copy();
t.RetryDelayMilliseconds = 1; // speed up tests!
// Allow the task's default (false) to have a chance
if (useHardLinks)
{
t.UseHardlinksIfPossible = useHardLinks;
}
MockEngine engine = new MockEngine(true /* log to console */);
t.BuildEngine = engine;
t.SourceFiles = new ITaskItem[] { new TaskItem("c:\\source"), new TaskItem("c:\\source2") };
t.DestinationFiles = new ITaskItem[] { new TaskItem("c:\\destination"), new TaskItem("c:\\destination2") };
t.Retries = 1;
t.RetryDelayMilliseconds = 1; // Can't really test the delay, but at least try passing in a value
CopyFunctor copyFunctor = new CopyFunctor(2, false /* do not throw on failure */);
bool result = t.Execute(copyFunctor.Copy);
Assert.AreEqual(true, result);
engine.AssertLogContains("MSB3026");
engine.AssertLogDoesntContain("MSB3027");
Assert.AreEqual(copyFunctor.FilesCopiedSuccessfully[0].Name, "c:\\source");
Assert.AreEqual(copyFunctor.FilesCopiedSuccessfully[1].Name, "c:\\source2");
}
示例13: CopyToDestinationFolderWithHardLinkFallbackNetwork
// Ignore: Flaky test
public void CopyToDestinationFolderWithHardLinkFallbackNetwork()
{
string sourceFile = FileUtilities.GetTemporaryFile();
string temp = @"\\localhost\c$\temp";
string destFolder = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A398");
string destFile = Path.Combine(destFolder, Path.GetFileName(sourceFile));
try
{
if (!Directory.Exists(destFolder))
{
Directory.CreateDirectory(destFolder);
}
string nothingFile = Path.Combine(destFolder, "nothing.txt");
File.WriteAllText(nothingFile, "nothing");
File.Delete(nothingFile);
}
catch (Exception)
{
Console.WriteLine("CopyToDestinationFolderWithHardLinkFallbackNetwork test could not access the network.");
// Something caused us to not be able to access our "network" share, don't fail.
return;
}
try
{
using (StreamWriter sw = new StreamWriter(sourceFile, true)) // HIGHCHAR: Test writes in UTF8 without preamble.
sw.Write("This is a source temp file.");
ITaskItem[] sourceFiles = new ITaskItem[] { new TaskItem(sourceFile) };
Copy t = new Copy();
t.RetryDelayMilliseconds = 1; // speed up tests!
t.UseHardlinksIfPossible = true;
MockEngine me = new MockEngine(true);
t.BuildEngine = me;
t.SourceFiles = sourceFiles;
t.DestinationFolder = new TaskItem(destFolder);
t.SkipUnchangedFiles = true;
bool success = t.Execute();
Assert.IsTrue(success, "success");
Assert.IsTrue(File.Exists(destFile), "destination exists");
Microsoft.Build.UnitTests.MockEngine.GetStringDelegate resourceDelegate = new Microsoft.Build.UnitTests.MockEngine.GetStringDelegate(AssemblyResources.GetString);
me.AssertLogContainsMessageFromResource(resourceDelegate, "Copy.HardLinkComment", sourceFile, destFile);
// Can't do this below, because the real message doesn't end with String.Empty, it ends with a CLR exception string, and so matching breaks in PLOC.
// Instead look for the HRESULT that CLR unfortunately puts inside its exception string. Something like this
// The system cannot move the file to a different disk drive. (Exception from HRESULT: 0x80070011)
// me.AssertLogContainsMessageFromResource(resourceDelegate, "Copy.RetryingAsFileCopy", sourceFile, destFile, String.Empty);
me.AssertLogContains("0x80070011");
string destinationFileContents;
using (StreamReader sr = new StreamReader(destFile))
destinationFileContents = sr.ReadToEnd();
Assert.IsTrue
(
destinationFileContents == "This is a source temp file.",
"Expected the destination file to contain the contents of source file."
);
Assert.AreEqual(1, t.DestinationFiles.Length);
Assert.AreEqual(1, t.CopiedFiles.Length);
Assert.AreEqual(destFile, t.DestinationFiles[0].ItemSpec);
Assert.AreEqual(destFile, t.CopiedFiles[0].ItemSpec);
// Now we will write new content to the source file
// we'll then check that the destination file automatically
// has the same content (i.e. it's been hard linked)
using (StreamWriter sw = new StreamWriter(sourceFile, false)) // HIGHCHAR: Test writes in UTF8 without preamble.
sw.Write("This is another source temp file.");
// Read the destination file (it should have the same modified content as the source)
using (StreamReader sr = new StreamReader(destFile))
destinationFileContents = sr.ReadToEnd();
Assert.IsTrue
(
destinationFileContents == "This is a source temp file.",
"Expected the destination copied file to contain the contents of original source file only."
);
((MockEngine)t.BuildEngine).AssertLogDoesntContain("MSB3026"); // Didn't do retries
}
finally
{
File.Delete(sourceFile);
File.Delete(destFile);
Directory.Delete(destFolder, true);
}
}
示例14: AssemblyFoldersFromConfigFileMalformed
public void AssemblyFoldersFromConfigFileMalformed()
{
var assemblyConfig = Path.GetTempFileName();
File.WriteAllText(assemblyConfig, "<<<>><>!" + TestFile);
var moniker = "{AssemblyFoldersFromConfig:" + assemblyConfig + ",v4.5}";
try
{
MockEngine engine = new MockEngine();
ResolveAssemblyReference t = new ResolveAssemblyReference
{
BuildEngine = engine,
Assemblies = new ITaskItem[] { new TaskItem("assemblyfromconfig2") },
SearchPaths = new[] { moniker }
};
var success = Execute(t);
Assert.False(success);
Assert.Equal(0, t.ResolvedFiles.Length);
engine.AssertLogContains(") specified in Microsoft.Common.CurrentVersion.targets was invalid. The error was: ");
}
finally
{
FileUtilities.DeleteNoThrow(assemblyConfig);
}
}
示例15: LogMessageWithUnmatchedCurly
public void LogMessageWithUnmatchedCurly()
{
MockEngine mockEngine = new MockEngine();
Task t = new MockTask();
t.BuildEngine = mockEngine;
t.Log.LogMessage("echo {");
t.Log.LogMessageFromText("{1", MessageImportance.High);
t.Log.LogCommandLine("{2");
t.Log.LogWarning("{3");
t.Log.LogError("{4");
mockEngine.AssertLogContains("echo {");
mockEngine.AssertLogContains("{1");
mockEngine.AssertLogContains("{2");
mockEngine.AssertLogContains("{3");
mockEngine.AssertLogContains("{4");
}