Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }