本文整理汇总了C#中Microsoft.Build.UnitTests.MockEngine.AssertLogContainsMessageFromResource方法的典型用法代码示例。如果您正苦于以下问题:C# MockEngine.AssertLogContainsMessageFromResource方法的具体用法?C# MockEngine.AssertLogContainsMessageFromResource怎么用?C# MockEngine.AssertLogContainsMessageFromResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.UnitTests.MockEngine
的用法示例。
在下文中一共展示了MockEngine.AssertLogContainsMessageFromResource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyToDestinationFolderWithHardLinkFallbackTooManyLinks
// Ignore: Flaky test
public void CopyToDestinationFolderWithHardLinkFallbackTooManyLinks()
{
string sourceFile = FileUtilities.GetTemporaryFile();
string temp = Path.GetTempPath();
string destFolder = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A398");
string destFile = Path.Combine(destFolder, Path.GetFileName(sourceFile));
try
{
using (StreamWriter sw = new StreamWriter(sourceFile, true)) // HIGHCHAR: Test writes in UTF8 without preamble.
sw.Write("This is a source temp file.");
if (!Directory.Exists(destFolder))
{
Directory.CreateDirectory(destFolder);
}
// Exhaust the number (1024) of directory entries that can be created for a file
// This is 1 + (1 x hard links)
// We need to test the fallback code path when we're out of directory entries for a file..
for (int n = 0; n < 1025 /* make sure */; n++)
{
string destLink = Path.Combine(destFolder, Path.GetFileNameWithoutExtension(sourceFile) + "." + n.ToString());
NativeMethods.CreateHardLink(destLink, sourceFile, IntPtr.Zero);
}
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
// Tried to create more than a few links to a file that is supported by the file system. (! yhMcE! Exception from HRESULT: Table c?! 0x80070476)
// me.AssertLogContainsMessageFromResource(resourceDelegate, "Copy.RetryingAsFileCopy", sourceFile, destFile, String.Empty);
me.AssertLogContains("0x80070476");
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);
}
}
示例2: 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);
}
}
示例3: CopyToDestinationFolder
public void CopyToDestinationFolder()
{
string sourceFile = FileUtilities.GetTemporaryFile();
string temp = Path.GetTempPath();
string destFolder = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A398");
string destFile = Path.Combine(destFolder, Path.GetFileName(sourceFile));
try
{
using (StreamWriter sw = new StreamWriter(sourceFile, true)) // HIGHCHAR: Test writes in UTF8 without preamble.
sw.Write("This is a source temp file.");
// Don't create the dest folder, let task do that
ITaskItem[] sourceFiles = new ITaskItem[] { new TaskItem(sourceFile) };
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 me = new MockEngine();
t.BuildEngine = me;
t.SourceFiles = sourceFiles;
t.DestinationFolder = new TaskItem(destFolder);
t.SkipUnchangedFiles = true;
bool success = t.Execute();
Assert.True(success); // "success"
Assert.True(File.Exists(destFile)); // "destination exists"
string destinationFileContents;
using (StreamReader sr = new StreamReader(destFile))
destinationFileContents = sr.ReadToEnd();
if (!useHardLinks)
{
Microsoft.Build.UnitTests.MockEngine.GetStringDelegate resourceDelegate = new Microsoft.Build.UnitTests.MockEngine.GetStringDelegate(AssemblyResources.GetString);
me.AssertLogDoesntContainMessageFromResource(resourceDelegate, "Copy.HardLinkComment", sourceFile, destFile);
}
else
{
Microsoft.Build.UnitTests.MockEngine.GetStringDelegate resourceDelegate = new Microsoft.Build.UnitTests.MockEngine.GetStringDelegate(AssemblyResources.GetString);
me.AssertLogContainsMessageFromResource(resourceDelegate, "Copy.HardLinkComment", sourceFile, destFile);
}
Assert.Equal(destinationFileContents, "This is a source temp file."); // "Expected the destination file to contain the contents of source file."
Assert.Equal(1, t.DestinationFiles.Length);
Assert.Equal(1, t.CopiedFiles.Length);
Assert.Equal(destFile, t.DestinationFiles[0].ItemSpec);
Assert.Equal(destFile, t.CopiedFiles[0].ItemSpec);
((MockEngine)t.BuildEngine).AssertLogDoesntContain("MSB3026"); // Didn't do retries
}
finally
{
Helpers.DeleteFiles(sourceFile, destFile);
}
}
示例4: CopyToDestinationFolderWithHardLinkCheck
public void CopyToDestinationFolderWithHardLinkCheck()
{
string sourceFile = FileUtilities.GetTemporaryFile();
string temp = Path.GetTempPath();
string destFolder = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A398");
string destFile = Path.Combine(destFolder, Path.GetFileName(sourceFile));
try
{
using (StreamWriter sw = new StreamWriter(sourceFile, true)) // HIGHCHAR: Test writes in UTF8 without preamble.
sw.Write("This is a source temp file.");
// Don't create the dest folder, let task do that
ITaskItem[] sourceFiles = new ITaskItem[] { new TaskItem(sourceFile) };
Copy t = new Copy();
t.RetryDelayMilliseconds = 1; // speed up tests!
// Allow the task's default (false) to have a chance
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);
string destinationFileContents;
using (StreamReader sr = new StreamReader(destFile))
destinationFileContents = sr.ReadToEnd();
Assert.IsTrue
(
destinationFileContents == "This is a source temp file.",
"Expected the destination hard linked 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 another source temp file.",
"Expected the destination hard linked file to contain the contents of source file. Even after modification of the source"
);
((MockEngine)t.BuildEngine).AssertLogDoesntContain("MSB3026"); // Didn't do retries
}
finally
{
Helpers.DeleteFiles(sourceFile, destFile);
}
}
示例5: CopyWithHardAndSymbolicLinks
public void CopyWithHardAndSymbolicLinks()
{
string sourceFile = FileUtilities.GetTemporaryFile();
string temp = Path.GetTempPath();
string destFolder = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A398");
string destFile = Path.Combine(destFolder, Path.GetFileName(sourceFile));
try
{
ITaskItem[] sourceFiles = { new TaskItem(sourceFile) };
MockEngine me = new MockEngine(true);
Copy t = new Copy
{
RetryDelayMilliseconds = 1, // speed up tests!
UseHardlinksIfPossible = true,
UseSymboliclinksIfPossible = true,
BuildEngine = me,
SourceFiles = sourceFiles,
DestinationFolder = new TaskItem(destFolder),
SkipUnchangedFiles = true
};
bool success = t.Execute();
Assert.False(success);
MockEngine.GetStringDelegate resourceDelegate = AssemblyResources.GetString;
me.AssertLogContainsMessageFromResource(resourceDelegate, "Copy.ExactlyOneTypeOfLink", "UseHardlinksIfPossible", "UseSymboliclinksIfPossible");
}
finally
{
Helpers.DeleteFiles(sourceFile, destFile);
}
}