本文整理汇总了C#中MonoTests.Microsoft.Build.Tasks.TestMessageLogger类的典型用法代码示例。如果您正苦于以下问题:C# TestMessageLogger类的具体用法?C# TestMessageLogger怎么用?C# TestMessageLogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestMessageLogger类属于MonoTests.Microsoft.Build.Tasks命名空间,在下文中一共展示了TestMessageLogger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test1
public void Test1 ()
{
string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<ResXFile Include=""Item1"">
<Culture>fr</Culture>
</ResXFile>
<ResXFile Include=""Item2"">
<Culture>fr</Culture>
</ResXFile>
<ResXFile Include=""Item3"">
<Culture>en</Culture>
</ResXFile>
<ResXFile Include=""Item4"">
<Culture>gb</Culture>
</ResXFile>
<ResXFile Include=""Item5"">
<Culture>fr</Culture>
</ResXFile>
<ResXFile Include=""Item6"">
<Culture>it</Culture>
</ResXFile>
</ItemGroup>
<Target Name=""ShowMessage"">
<Message
Text = ""Culture: %(ResXFile.Culture) -- ResXFile: @(ResXFile)"" />
</Target>
</Project>";
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (projectString);
Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
CheckMessage (testLogger, "fr", "Item1;Item2;Item5", "A2");
CheckMessage (testLogger, "en", "Item3", "A3");
CheckMessage (testLogger, "gb", "Item4", "A4");
CheckMessage (testLogger, "it", "Item6", "A5");
CheckEngineEventCounts (testLogger, 1, 1, 4, 4);
}
示例2: TestUnqualifiedMetadataReference
public void TestUnqualifiedMetadataReference ()
{
string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<ResXFile Include=""Item1"">
<Culture>fr</Culture>
</ResXFile>
<ResXFile Include=""Item5"" />
<ResXFile Include=""Item6"">
<Culture>it</Culture>
</ResXFile>
</ItemGroup>
<Target Name=""ShowMessage"">
<Message
Text = ""Culture: %(Culture) -- ResXFile: @(ResXFile)"" />
</Target>
</Project>";
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (projectString);
//Fails as Culture is being referenced unqualified, and no Culture is
//specified for "Item5"
bool result = project.Build ("ShowMessage");
if (result)
Assert.Fail ("A1: Build should have failed");
CheckEngineEventCounts (testLogger, 1, 1, 0, 0);
}
示例3: TestEmptyPropertyValue
public void TestEmptyPropertyValue ()
{
Engine engine;
Project project;
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<A>1</A>
</PropertyGroup>
<Target Name='1'>
<Message Text='Before: $(A)'/>
<CreateProperty Value=''>
<Output
TaskParameter='Value'
PropertyName='A'
/>
</CreateProperty>
<Message Text='After: $(A)'/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed");
}
testLogger.CheckLoggedMessageHead ("Before: 1", "A1");
testLogger.CheckLoggedMessageHead ("After: ", "A2");
Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected messages found");
}
示例4: TestTargetReturns
public void TestTargetReturns ()
{
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.Load (Path.Combine ("Test", Path.Combine ("resources", "TestReturns.csproj")));
var logger = new TestMessageLogger ();
engine.RegisterLogger (logger);
bool result = project.Build ("Main");
if (!result) {
logger.DumpMessages ();
Assert.Fail ("Build failed");
}
logger.CheckLoggedMessageHead ("Result: Bar", "A1");
Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found");
}
示例5: TestOverridingTargets
public void TestOverridingTargets ()
{
Engine engine;
Project project;
string second = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name='BeforeBuild'/>
<Target Name='AfterBuild'/>
<Target Name='Build' DependsOnTargets='BeforeBuild'>
<Message Text='Build executing'/>
<CallTarget Targets='AfterBuild'/>
</Target>
</Project>";
using (StreamWriter sw = new StreamWriter (Path.Combine ("Test", Path.Combine ("resources", "second.proj")))) {
sw.Write (second);
}
string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name='AfterBuild'>
<Message Text='Overriding AfterBuild'/>
</Target>
<Import Project='Test/resources/second.proj'/>
<Target Name='BeforeBuild'>
<Message Text='Overriding BeforeBuild'/>
</Target>
</Project>";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
engine.RegisterLogger (logger);
bool result = project.Build ("Build");
if (!result) {
logger.DumpMessages ();
Assert.Fail ("Build failed");
}
logger.CheckLoggedMessageHead ("Overriding BeforeBuild", "A1");
logger.CheckLoggedMessageHead ("Build executing", "A1");
Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found");
}
示例6: CreateLogger
TestMessageLogger CreateLogger (string projectXml)
{
var logger = new TestMessageLogger ();
var result = Build (projectXml, logger);
if (!result) {
logger.DumpMessages ();
Assert.Fail ("Build failed");
}
return logger;
}
示例7: TestCopy_Retries
public void TestCopy_Retries ()
{
Engine engine;
Project project;
string file_path = Path.Combine (source_path, "copyretries.txt");
string target_file = Path.Combine (target_path, "copyretries.txt");
using (File.CreateText (file_path)) { }
using (File.CreateText (target_file)) { }
File.SetAttributes (target_file, FileAttributes.ReadOnly);
Assert.AreEqual (FileAttributes.ReadOnly, File.GetAttributes (target_file), "A1");
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup><DestFile>" + target_file + @"</DestFile></PropertyGroup>
<ItemGroup>
<SFiles Include='" + file_path + @"'><Md>1</Md></SFiles>
<DFiles Include='$(DestFile)'><Mde>2</Mde></DFiles>
</ItemGroup>
<Target Name='1'>
<Copy SourceFiles='@(SFiles)' DestinationFiles='@(DFiles)' Retries='3' RetryDelayMilliseconds='2000'>
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
<Message Text=""I0 : @(I0), I1: @(I1)""/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
// remove the read-only flag from the file after a few secs,
// so copying works after retries
new Thread ( () => {
Thread.Sleep (3000);
File.SetAttributes (target_file, FileAttributes.Normal);
}).Start ();
if (!project.Build ("1")) {
var sb = new StringBuilder ();
testLogger.DumpMessages (sb);
Assert.Fail ("Build failed " + sb.ToString ());
}
testLogger.CheckLoggedAny ("Copying failed. Retries left: 3.", MessageImportance.Normal, "A2");
}
示例8: TestCopy_OverwriteReadOnlyTrue
public void TestCopy_OverwriteReadOnlyTrue ()
{
Engine engine;
Project project;
string file_path = Path.Combine (source_path, "copyro1.txt");
string target_file = Path.Combine (target_path, "copyro1.txt");
using (File.CreateText (file_path)) { }
using (File.CreateText (target_file)) { }
File.SetAttributes (target_file, FileAttributes.ReadOnly);
Assert.AreEqual (FileAttributes.ReadOnly, File.GetAttributes (target_file), "A1");
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
<PropertyGroup><DestFile>" + target_file + @"</DestFile></PropertyGroup>
<ItemGroup>
<SFiles Include='" + file_path + @"'><Md>1</Md></SFiles>
<DFiles Include='$(DestFile)'><Mde>2</Mde></DFiles>
</ItemGroup>
<Target Name='1'>
<Copy SourceFiles='@(SFiles)' DestinationFiles='@(DFiles)' OverwriteReadOnlyFiles='true'>
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
<Message Text=""I0 : @(I0), I1: @(I1)""/>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
if (!project.Build ("1")) {
var sb = new StringBuilder ();
testLogger.DumpMessages (sb);
Assert.Fail ("Build failed " + sb.ToString ());
}
Assert.IsTrue (File.Exists (target_file), "A2");
var target_file_attrs = File.GetAttributes (target_file);
if (Environment.OSVersion.Platform == PlatformID.Unix)
Assert.AreEqual (FileAttributes.Normal, File.GetAttributes (target_file), "A3");
else
// On Windows the Archive attribute will be set, not the Normal attribute.
Assert.AreEqual (FileAttributes.Archive, File.GetAttributes (target_file), "A3");
}
示例9: TestFilter
public void TestFilter ()
{
string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<fruit Include=""apple"">
<consistency>firm</consistency>
</fruit>
<fruit Include=""orange"">
<consistency>pulpy</consistency>
</fruit>
<fruit Include=""banana"">
<consistency>softish</consistency>
</fruit>
<fruit Include=""pear"">
<consistency>unsound</consistency>
</fruit>
<fruit Include=""apricot"">
<consistency>unsound</consistency>
</fruit>
</ItemGroup>
<Target Name=""Compost"">
<CreateItem Include=""@(fruit)"" Condition=""'%(consistency)' == 'pulpy' or '%(consistency)' == 'unsound' "">
<Output TaskParameter=""Include"" ItemName=""Final""/>
</CreateItem>
</Target>
</Project>";
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (projectString);
Assert.IsTrue (project.Build ("Compost"), "A1: Build failed");
BuildItemGroup include = project.GetEvaluatedItemsByName ("Final");
Assert.AreEqual (3, include.Count, "A2");
string [,] additional_metadata = new string [,] { { "Identity", "orange" } };
CreateItemTest.CheckBuildItem (include [0], "Final", additional_metadata, "orange", "A3");
additional_metadata = new string [,] { { "Identity", "pear" } };
CreateItemTest.CheckBuildItem (include [1], "Final", additional_metadata, "pear", "A4");
additional_metadata = new string [,] { { "Identity", "apricot" } };
CreateItemTest.CheckBuildItem (include [2], "Final", additional_metadata, "apricot", "A5");
CheckEngineEventCounts (testLogger, 1, 1, 2, 2);
}
示例10: TestMultipleMetadataReference2
public void TestMultipleMetadataReference2 ()
{
string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<GroupA Include=""file1.txt""/>
<GroupA Include=""file2.txt""/>
<GroupA Include=""file3.txt""/>
<GroupA Include=""file3.txt""/>
<GroupA Include=""file4.txt""/>
</ItemGroup>
<ItemGroup>
<GroupB Include=""file1.txt""/>
<GroupB Include=""file3.txt""/>
<GroupB Include=""file5.txt""/>
<GroupC Include=""PreExistingValue""/>
</ItemGroup>
<Target Name=""Build"">
<CreateItem Include=""@(GroupA)"" Condition=""'%(Identity)' != '' and '@(GroupA)' != '' and '@(GroupB)' != ''"" >
<Output TaskParameter=""Include"" ItemName=""GroupC""/>
</CreateItem>
<Message Text=""%(GroupC.Identity)""/>
</Target>
</Project>";
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (projectString);
Assert.IsTrue (project.Build ("Build"), "A1: Build failed");
BuildItemGroup include = project.GetEvaluatedItemsByName ("GroupC");
Assert.AreEqual (4, include.Count, "A2");
string [,] additional_metadata = new string [,] { { "Identity", "PreExistingValue" } };
CreateItemTest.CheckBuildItem (include [0], "GroupC", additional_metadata, "PreExistingValue", "A3");
additional_metadata = new string [,] { { "Identity", "file1.txt" } };
CreateItemTest.CheckBuildItem (include [1], "GroupC", additional_metadata, "file1.txt", "A4");
additional_metadata = new string [,] { { "Identity", "file3.txt" } };
CreateItemTest.CheckBuildItem (include [2], "GroupC", additional_metadata, "file3.txt", "A5");
CreateItemTest.CheckBuildItem (include [3], "GroupC", additional_metadata, "file3.txt", "A6");
CheckEngineEventCounts (testLogger, 1, 1, 5, 5);
}
示例11: TestIdentity
public void TestIdentity ()
{
string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<ExampColl Include=""Item1""/>
<ExampColl Include=""Item2""/>
<ExampColl Include=""Item3""/>
<ExampColl Include=""Item4""/>
<ExampColl Include=""Item4""/>
<ExampColl Include=""Item5""/>
<ExampColl Include=""Item6""/>
</ItemGroup>
<Target Name=""ShowMessage"">
<Message Text = ""Identity: %(IdenTIty) -- Items in ExampColl: @(ExampColl)""/>
</Target>
</Project>";
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (projectString);
Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
CheckLoggedMessageAny (testLogger, "Identity: Item1 -- Items in ExampColl: Item1", "A2");
CheckLoggedMessageAny (testLogger, "Identity: Item2 -- Items in ExampColl: Item2", "A3");
CheckLoggedMessageAny (testLogger, "Identity: Item3 -- Items in ExampColl: Item3", "A4");
CheckLoggedMessageAny (testLogger, "Identity: Item4 -- Items in ExampColl: Item4;Item4", "A5");
CheckLoggedMessageAny (testLogger, "Identity: Item5 -- Items in ExampColl: Item5", "A6");
CheckLoggedMessageAny (testLogger, "Identity: Item6 -- Items in ExampColl: Item6", "A7");
Assert.AreEqual (0, testLogger.NormalMessageCount, "A8");
Assert.AreEqual (0, testLogger.WarningMessageCount, "A7");
CheckEngineEventCounts (testLogger, 1, 1, 6, 6);
}
示例12: TestMultipleMetadataReference
public void TestMultipleMetadataReference ()
{
string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<ExampColl Include=""Item1"">
<Number>1</Number>
</ExampColl>
<ExampColl Include=""Item2"">
<Number>2</Number>
</ExampColl>
<ExampColl Include=""Item3"">
<Number>1</Number>
</ExampColl>
<ExampColl2 Include=""Item4"">
<Number>1</Number>
</ExampColl2>
<ExampColl2 Include=""Item5"">
<Number>2</Number>
<Color>Red</Color>
</ExampColl2>
<ExampColl2 Include=""Item6"">
<Number>3</Number>
<Color>Green</Color>
</ExampColl2>
</ItemGroup>
<Target Name=""ShowMessage"">
<Message Text = ""Number: %(Number) Color: %(ExampColl2.Color)-- Items in ExampColl: @(ExampColl) ExampColl2: @(ExampColl2)""/>
</Target>
</Project>";
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (projectString);
Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
CheckLoggedMessageAny (testLogger, "Number: 1 Color: -- Items in ExampColl: Item1;Item3 ExampColl2: Item4", "A2");
CheckLoggedMessageAny (testLogger, "Number: 2 Color: Red-- Items in ExampColl: ExampColl2: Item5", "A3");
CheckLoggedMessageAny (testLogger, "Number: 3 Color: Green-- Items in ExampColl: ExampColl2: Item6", "A4");
CheckLoggedMessageAny (testLogger, "Number: 2 Color: -- Items in ExampColl: Item2 ExampColl2: ", "A5");
Assert.AreEqual (0, testLogger.NormalMessageCount, "A6");
Assert.AreEqual (0, testLogger.WarningMessageCount, "A7");
CheckEngineEventCounts (testLogger, 1, 1, 4, 4);
}
示例13: TestConditionalBatching
public void TestConditionalBatching ()
{
string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<ResXFile Include=""Item1"">
<Culture>fr</Culture>
</ResXFile>
<ResXFile Include=""Item2"">
<Culture>fr</Culture>
</ResXFile>
<ResXFile Include=""Item3"">
<Culture>en</Culture>
</ResXFile>
<ResXFile Include=""Item4"">
<Culture>gb</Culture>
</ResXFile>
<ResXFile Include=""Item6"">
<Culture>it</Culture>
</ResXFile>
<NonResXFile Include=""Item7"">
<Culture>it</Culture>
</NonResXFile>
<NonResXFile Include=""Item8"">
<Culture>en</Culture>
</NonResXFile>
<NonResXFile Include=""Item9"">
<Culture>en</Culture>
</NonResXFile>
</ItemGroup>
<Target Name=""ShowMessage"">
<Message
Text = ""ResXFiles: @(ResXFile) NonResXFiles: @(NonResXFile)""
Condition = ""'%(Culture)' == 'fr'""/>
</Target>
</Project>";
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (projectString);
Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
testLogger.CheckLoggedMessageHead ("ResXFiles: Item1;Item2 NonResXFiles: ", "A2");
CheckEngineEventCounts (testLogger, 1, 1, 1, 1);
}
示例14: Test4
public void Test4 ()
{
string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<ResXFile Include=""Item1"">
<Culture>fr</Culture>
</ResXFile>
<ResXFile Include=""Item5"" />
<ResXFile Include=""Item6"">
<Culture>it</Culture>
</ResXFile>
</ItemGroup>
<Target Name=""ShowMessage"">
<Message
Text = ""Culture: %(ResXFile.Culture) -- ResXFile: @(ResXFile)"" />
</Target>
</Project>";
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (projectString);
//no Culture is specified for "Item5", but
//Culture is being referenced __qualified__, so works
Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
CheckMessage (testLogger, "fr", "Item1", "A2");
CheckMessage (testLogger, "", "Item5", "A3");
CheckMessage (testLogger, "it", "Item6", "A3");
CheckEngineEventCounts (testLogger, 1, 1, 3, 3);
}
示例15: TestCopy2
public void TestCopy2 ()
{
Engine engine;
Project project;
string [] file_paths = new string [] {
Path.Combine (source_path, "copy1.txt"),
Path.Combine (source_path, "copy2.txt")
};
using (File.CreateText (file_paths[0])) { }
using (File.CreateText (file_paths[1])) { }
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup><TargetPath>" + target_path + @"</TargetPath></PropertyGroup>
<ItemGroup>
<SFiles Include='" + file_paths [0] + @"'><Md>1</Md></SFiles>
<SFiles Include='" + file_paths [1] + @"'><Md>2</Md></SFiles>
</ItemGroup>
<Target Name='1'>
<Copy SourceFiles='@(SFiles)' DestinationFolder='$(TargetPath)' SkipUnchangedFiles='true' >
<Output TaskParameter='CopiedFiles' ItemName='I0'/>
<Output TaskParameter='DestinationFiles' ItemName='I1'/>
</Copy>
</Target>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
project.LoadXml (documentString);
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed");
}
CheckCopyBuildItems (project, file_paths, target_path, "A1");
// build again, this time files won't get copied because
// of SkipUnchangedFiles=true
if (!project.Build ("1")) {
testLogger.DumpMessages ();
Assert.Fail ("Build failed #2");
}
CheckCopyBuildItems (project, file_paths, target_path, "A2");
}