本文整理汇总了C#中Microsoft.Build.UnitTests.MockEngine类的典型用法代码示例。如果您正苦于以下问题:C# MockEngine类的具体用法?C# MockEngine怎么用?C# MockEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockEngine类属于Microsoft.Build.UnitTests命名空间,在下文中一共展示了MockEngine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: PokeNoNamespace
public void PokeNoNamespace()
{
MockEngine engine = new MockEngine(true);
string xmlInputPath;
Prepare(_xmlFileNoNs, out xmlInputPath);
XmlPoke p = new XmlPoke();
p.BuildEngine = engine;
p.XmlInputPath = new TaskItem(xmlInputPath);
p.Query = "//variable/@Name";
p.Value = new TaskItem("Mert");
p.Execute();
List<int> positions = new List<int>();
positions.AddRange(new int[] { 117, 172, 227 });
string result;
using (StreamReader sr = new StreamReader(xmlInputPath))
{
result = sr.ReadToEnd();
Regex r = new Regex("Mert");
MatchCollection mc = r.Matches(result);
foreach (Match m in mc)
{
Assert.True(positions.Contains(m.Index), "This test should effect 3 positions. There should be 3 occurances of 'Mert'\n" + result);
}
}
}
开发者ID:cameron314,项目名称:msbuild,代码行数:29,代码来源:XmlPoke_Tests.cs
示例2: PeekWithNamespaceNode
public void PeekWithNamespaceNode()
{
MockEngine engine = new MockEngine(true);
string xmlInputPath;
Prepare(_xmlFileWithNs, out xmlInputPath);
XmlPeek p = new XmlPeek();
p.BuildEngine = engine;
p.XmlInputPath = new TaskItem(xmlInputPath);
p.Query = "//s:variable/.";
p.Namespaces = "<Namespace Prefix=\"s\" Uri=\"http://nsurl\" />";
Assert.True(p.Execute()); // "Test should've passed"
Assert.Equal(3, p.Result.Length); // "result Length should be 3"
string[] results = new string[] {
"<s:variable Type=\"String\" Name=\"a\" xmlns:s=\"http://nsurl\"></s:variable>",
"<s:variable Type=\"String\" Name=\"b\" xmlns:s=\"http://nsurl\"></s:variable>",
"<s:variable Type=\"String\" Name=\"c\" xmlns:s=\"http://nsurl\"></s:variable>"
};
for (int i = 0; i < p.Result.Length; i++)
{
Assert.True(p.Result[i].ItemSpec.Equals(results[i]), "Results don't match: " + p.Result[i].ItemSpec);
}
}
开发者ID:cameron314,项目名称:msbuild,代码行数:27,代码来源:XmlPeek_Tests.cs
示例3: TestResourceAccess
public void TestResourceAccess()
{
MyToolTaskExtension t = new MyToolTaskExtension();
MockEngine engine = new MockEngine();
t.BuildEngine = engine;
// No need to actually check the outputted strings. We only care that this doesn't throw, which means that
// the resource strings were reachable.
// Normal CSC messages first, from private XMakeTasks resources. They should be accessible with t.Log
t.Log.LogErrorWithCodeFromResources("Csc.AssemblyAliasContainsIllegalCharacters", "PlanetSide", "Knights of the Old Republic");
t.Log.LogWarningWithCodeFromResources("Csc.InvalidParameter");
t.Log.LogMessageFromResources("Vbc.ParameterHasInvalidValue", "Rome Total War", "Need for Speed Underground");
// Now shared messages. Should be accessible with the private LogShared property
PropertyInfo logShared = typeof(ToolTask).GetProperty("LogShared", BindingFlags.Instance | BindingFlags.NonPublic);
TaskLoggingHelper log = (TaskLoggingHelper)logShared.GetValue(t, null);
log.LogWarningWithCodeFromResources("Shared.FailedCreatingTempFile", "Gothic II");
log.LogMessageFromResources("Shared.CannotConvertStringToBool", "foo");
// Now private Utilities messages. Should be accessible with the private LogPrivate property
PropertyInfo logPrivate = typeof(ToolTask).GetProperty("LogPrivate", BindingFlags.Instance | BindingFlags.NonPublic);
log = (TaskLoggingHelper)logPrivate.GetValue(t, null);
log.LogErrorWithCodeFromResources("ToolTask.CommandTooLong", "Painkiller");
log.LogWarningWithCodeFromResources("ToolTask.CouldNotStartToolExecutable", "Fallout Tactics", "Fallout 2");
log.LogMessageFromResources("ToolsLocationHelper.InvalidRedistFile", "Deus Ex", "Fallout");
}
开发者ID:cameron314,项目名称:msbuild,代码行数:28,代码来源:ToolTaskExtension_Tests.cs
示例4: ResourceAccessSanityCheck
public void ResourceAccessSanityCheck()
{
MyToolTaskExtension t = new MyToolTaskExtension();
MockEngine engine = new MockEngine();
t.BuildEngine = engine;
t.Log.LogErrorFromResources("Beyond Good and Evil");
}
开发者ID:ravpacheco,项目名称:msbuild,代码行数:8,代码来源:ToolTaskExtension_Tests.cs
示例5: ResourceAccessSanityCheck
public void ResourceAccessSanityCheck()
{
Csc t = new Csc();
MockEngine engine = new MockEngine();
t.BuildEngine = engine;
t.Log.LogErrorFromResources("Beyond Good and Evil");
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:8,代码来源:ToolTaskExtension_Tests.cs
示例6: PrepareExecWrapper
private ExecWrapper PrepareExecWrapper(string command)
{
IBuildEngine2 mockEngine = new MockEngine(true);
ExecWrapper exec = new ExecWrapper();
exec.BuildEngine = mockEngine;
exec.Command = command;
return exec;
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:8,代码来源:Exec_Tests.cs
示例7: 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");
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:11,代码来源:WriteCodeFragment_Tests.cs
示例8: 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");
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:11,代码来源:WriteCodeFragment_Tests.cs
示例9: ResourceAccessSanityCheck
public void ResourceAccessSanityCheck()
{
Assert.Throws<ArgumentException>(() =>
{
MyToolTaskExtension t = new MyToolTaskExtension();
MockEngine engine = new MockEngine();
t.BuildEngine = engine;
t.Log.LogErrorFromResources("Beyond Good and Evil");
}
);
}
开发者ID:cameron314,项目名称:msbuild,代码行数:12,代码来源:ToolTaskExtension_Tests.cs
示例10: TestGeneralFrameworkMonikerGood
public void TestGeneralFrameworkMonikerGood()
{
string targetFrameworkMoniker = ".NetFramework, Version=v4.5";
MockEngine engine = new MockEngine();
GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
getReferencePaths.BuildEngine = engine;
getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker;
getReferencePaths.Execute();
string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
Assert.Equal(ToolLocationHelper.GetPathToReferenceAssemblies(new FrameworkNameVersioning(targetFrameworkMoniker)).Count, returnedPaths.Length);
Assert.Equal(0, engine.Errors); // "Expected the log to contain no errors"
}
开发者ID:cameron314,项目名称:msbuild,代码行数:12,代码来源:GetReferencePaths_Tests.cs
示例11: Setup
public void Setup()
{
// Create a delegate helper to make the testing of a method which uses a lot of fileExists a bit easier
_mockExists = new MockFileExists(_defaultSdkToolsPath);
// We need an engine to see any logging messages the method may log
_mockEngine = new MockEngine();
// Dummy task to get a TaskLoggingHelper
TaskToLogFrom loggingTask = new TaskToLogFrom();
loggingTask.BuildEngine = _mockEngine;
_log = loggingTask.Log;
_log.TaskResources = AssemblyResources.PrimaryResources;
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:14,代码来源:SdkToolsPathUtility_Tests.cs
示例12: TestInputChecks1
public void TestInputChecks1()
{
MockEngine engine = new MockEngine();
SGenExtension sgen = new SGenExtension();
sgen.BuildEngine = engine;
sgen.BuildAssemblyName = "MyAsm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" + Path.GetInvalidPathChars()[0];
sgen.BuildAssemblyPath = "C:\\SomeFolder\\MyAsm.dll";
sgen.ShouldGenerateSerializer = true;
sgen.UseProxyTypes = false;
// This should result in a quoted parameter...
sgen.KeyFile = "c:\\Some Folder\\MyKeyFile.snk";
string commandLine = sgen.CommandLine();
Assert.IsTrue(engine.Errors == 1);
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:14,代码来源:SGen_Tests.cs
示例13: ErrorInNamespaceDecl
public void ErrorInNamespaceDecl()
{
MockEngine engine = new MockEngine(true);
string xmlInputPath;
Prepare(_xmlFileWithNs, out xmlInputPath);
XmlPeek p = new XmlPeek();
p.BuildEngine = engine;
p.XmlInputPath = new TaskItem(xmlInputPath);
p.Query = "//s:variable/@Name";
p.Namespaces = "<!THIS IS ERROR Namespace Prefix=\"s\" Uri=\"http://nsurl\" />";
bool executeResult = p.Execute();
Assert.IsTrue(engine.Log.Contains("MSB3742"), "Engine Log: " + engine.Log);
Assert.IsFalse(executeResult, "Execution should've failed");
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:16,代码来源:XmlPeek_Tests.cs
示例14: EmptyMessage
public void EmptyMessage()
{
MockEngine e = new MockEngine();
Message m = new Message();
m.BuildEngine = e;
// don't set text
bool retval = m.Execute();
Console.WriteLine("===");
Console.WriteLine(e.Log);
Console.WriteLine("===");
Assert.IsTrue(retval);
Assert.IsTrue(e.Messages == 0);
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:17,代码来源:ErrorWarningMessage_Tests.cs
示例15: SomeInputsFailToCreate
public void SomeInputsFailToCreate()
{
string temp = Path.GetTempPath();
string file = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A38e");
string dir = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A38f");
string invalid = "[email protected]#$%^&*()|";
string dir2 = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A390");
try
{
FileStream fs = File.Create(file);
fs.Close(); //we're gonna try to delete it
MakeDir t = new MakeDir();
MockEngine engine = new MockEngine();
t.BuildEngine = engine;
t.Directories = new ITaskItem[]
{
new TaskItem(dir),
new TaskItem(file),
new TaskItem(invalid),
new TaskItem(dir2)
};
bool success = t.Execute();
Assert.IsTrue(!success);
Assert.AreEqual(2, t.DirectoriesCreated.Length);
Assert.AreEqual(dir, t.DirectoriesCreated[0].ItemSpec);
Assert.AreEqual(dir2, t.DirectoriesCreated[1].ItemSpec);
Assert.IsTrue
(
engine.Log.Contains
(
String.Format(AssemblyResources.GetString("MakeDir.Comment"), dir)
)
);
}
finally
{
Directory.Delete(dir);
File.Delete(file);
Directory.Delete(dir2);
}
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:46,代码来源:MakeDir_Tests.cs
示例16: CombineFileDirectory
public void CombineFileDirectory()
{
WriteCodeFragment task = new WriteCodeFragment();
MockEngine engine = new MockEngine(true);
task.BuildEngine = engine;
task.Language = "c#";
task.AssemblyAttributes = new TaskItem[] { new TaskItem("aa") };
task.OutputFile = new TaskItem("CombineFileDirectory.tmp");
task.OutputDirectory = new TaskItem(Path.GetTempPath());
bool result = task.Execute();
Assert.AreEqual(true, result);
string file = Path.Combine(Path.GetTempPath(), "CombineFileDirectory.tmp");
Assert.AreEqual(file, task.OutputFile.ItemSpec);
Assert.AreEqual(true, File.Exists(file));
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:17,代码来源:WriteCodeFragment_Tests.cs
示例17: MultilineMessage
public void MultilineMessage()
{
MockEngine e = new MockEngine();
Message m = new Message();
m.BuildEngine = e;
m.Text = "messagetext\n messagetext2 \n\nmessagetext3";
bool retval = m.Execute();
Console.WriteLine("===");
Console.WriteLine(e.Log);
Console.WriteLine("===");
Assert.IsTrue(retval);
Assert.IsTrue(e.Log.IndexOf("messagetext\n messagetext2 \n\nmessagetext3") != -1);
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:17,代码来源:ErrorWarningMessage_Tests.cs
示例18: Message
public void Message()
{
MockEngine e = new MockEngine();
Message m = new Message();
m.BuildEngine = e;
m.Text = "messagetext";
bool retval = m.Execute();
Console.WriteLine("===");
Console.WriteLine(e.Log);
Console.WriteLine("===");
Assert.True(retval);
Assert.NotEqual(-1, e.Log.IndexOf("messagetext"));
}
开发者ID:cameron314,项目名称:msbuild,代码行数:17,代码来源:ErrorWarningMessage_Tests.cs
示例19: 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");
}
开发者ID:JamesLinus,项目名称:msbuild,代码行数:19,代码来源:ResolveCodeAnalysisRuleSet_Tests.cs
示例20: TestGeneralFrameworkMonikerGoodWithRoot
public void TestGeneralFrameworkMonikerGoodWithRoot()
{
string tempDirectory = Path.Combine(Path.GetTempPath(), "TestGeneralFrameworkMonikerGoodWithRoot");
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' Name='.NET Framework 4.1'>" +
"<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;
string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
Assert.Equal(1, returnedPaths.Length);
Assert.True(returnedPaths[0].Equals(framework41Directory, StringComparison.OrdinalIgnoreCase));
Assert.Equal(0, engine.Log.Length); // "Expected the log to contain nothing"
Assert.True(displayName.Equals(".NET Framework 4.1", StringComparison.OrdinalIgnoreCase));
}
finally
{
if (Directory.Exists(framework41Directory))
{
Directory.Delete(framework41Directory, true);
}
}
}
开发者ID:cameron314,项目名称:msbuild,代码行数:41,代码来源:GetReferencePaths_Tests.cs
注:本文中的Microsoft.Build.UnitTests.MockEngine类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论