2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / Microsoft.Build.Tasks / Test / Microsoft.Build.Tasks / FindAppConfigFileTest.cs
blob5aaa23086b9873d294a760cd52fd43e04d44287a
1 //
2 // FindAppConfigFileTest.cs
3 //
4 // Author:
5 // Ankit Jain (jankit@novell.com)
6 //
7 // Copyright 2009 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #if NET_3_5
30 using System;
31 using System.Collections;
32 using Microsoft.Build.BuildEngine;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Tasks;
35 using Microsoft.Build.Utilities;
36 using NUnit.Framework;
37 using System.Text;
39 namespace MonoTests.Microsoft.Build.Tasks {
41 [TestFixture]
42 public class FindAppConfigFileTest {
44 [Test]
45 public void TestExecution1 ()
47 CheckOutput (new string [] {"app.config"}, new string [] {"app.config"}, "AppConfigWithTargetPath: app.config List1 Foo.exe.config");
50 [Test]
51 public void TestExecution2 ()
53 CheckOutput (new string [] {"foobar"}, new string [] {"app.config"}, "AppConfigWithTargetPath: app.config List2 Foo.exe.config");
56 [Test]
57 public void TestExecution3 ()
59 CheckOutput (new string [] {"foo\\app.config"}, new string [] {"app.config"}, "AppConfigWithTargetPath: app.config List2 Foo.exe.config");
62 [Category ("NotWorking")]
63 [Test]
64 public void TestExecution4 ()
66 CheckOutput (new string[] { "foo\\app.config" }, new string[] { "bar\\app.config" }, "AppConfigWithTargetPath: foo\\app.config List1 Foo.exe.config");
69 [Category ("NotWorking")]
70 [Test]
71 public void TestExecution5 ()
73 CheckOutput (new string[] { "foobar" }, new string[] { "bar\\app.config" }, "AppConfigWithTargetPath: bar\\app.config List2 Foo.exe.config");
76 [Test]
77 public void TestExecution6 ()
79 CheckOutput (new string[] { "foobar" }, new string[] { "bar\\foo.config" }, "AppConfigWithTargetPath: ");
82 [Test]
83 public void TestExecution7 () {
84 CheckOutput (new string[] { ".\\app.config" }, new string[] { "app.config" }, "AppConfigWithTargetPath: app.config List2 Foo.exe.config");
87 void CheckOutput (string[] primary_list, string[] secondary_list, string expected) {
88 StringBuilder sb = new StringBuilder ();
90 sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + ">");
91 sb.Append ("\t<ItemGroup>");
92 if (primary_list != null)
93 foreach (string s in primary_list)
94 sb.AppendFormat ("\t\t<List1 Include=\"{0}\"><Source>List1</Source></List1>", s);
96 if (secondary_list != null)
97 foreach (string s in secondary_list)
98 sb.AppendFormat ("\t\t<List2 Include=\"{0}\"><Source>List2</Source></List2>", s);
99 sb.Append ("\t</ItemGroup>");
101 sb.Append (@"
102 <Target Name='1'>
103 <FindAppConfigFile PrimaryList=""@(List1)"" SecondaryList=""@(List2)"" TargetPath=""Foo.exe.config"">
104 <Output TaskParameter=""AppConfigFile"" ItemName=""AppConfigWithTargetPath""/>
105 </FindAppConfigFile>
107 <Message Text=""AppConfigWithTargetPath: %(AppConfigWithTargetPath.Identity) %(AppConfigWithTargetPath.Source) %(AppConfigWithTargetPath.TargetPath)""/>
108 </Target>
109 </Project>");
111 string projectXml = sb.ToString ();
112 Engine engine = new Engine (Consts.BinPath);
113 TestMessageLogger testLogger = new TestMessageLogger ();
114 engine.RegisterLogger (testLogger);
116 Project project = engine.CreateNewProject ();
117 project.LoadXml (projectXml);
118 if (!project.Build ("1")) {
119 testLogger.DumpMessages ();
120 Assert.Fail ("Build failed");
122 testLogger.DumpMessages ();
124 Assert.AreEqual (1, testLogger.NormalMessageCount, "Expected number of messages");
125 testLogger.CheckLoggedMessageHead (expected, "A1");
129 #endif