public void TestClone2() { BuildItemGroup big = new BuildItemGroup(); big.AddNewItem("a", "a"); big.AddNewItem("b", "a"); BuildItemGroup big2 = big.Clone(true); BuildItem[] items = big2.ToArray(); Assert.AreEqual(2, big2.Count, "A1"); Assert.AreEqual(String.Empty, items [0].Condition, "A2"); Assert.AreEqual(String.Empty, items [0].Exclude, "A3"); Assert.AreEqual("a", items [0].FinalItemSpec, "A4"); Assert.AreEqual("a", items [0].Include, "A5"); Assert.IsFalse(items [0].IsImported, "A6"); Assert.AreEqual("a", items [0].Name, "A7"); Assert.AreEqual(String.Empty, items [1].Condition, "A8"); Assert.AreEqual(String.Empty, items [1].Exclude, "A9"); Assert.AreEqual("a", items [1].FinalItemSpec, "A10"); Assert.AreEqual("a", items [1].Include, "A11"); Assert.IsFalse(items [1].IsImported, "A12"); Assert.AreEqual("b", items [1].Name, "A13"); }
public void TestToArray1() { BuildItemGroup big = new BuildItemGroup(); BuildItem[] items = big.ToArray(); Assert.AreEqual(0, items.Length, "A1"); big.AddNewItem("a", "b"); big.AddNewItem("c", "d"); items = big.ToArray(); Assert.AreEqual("a", items [0].Name, "A2"); Assert.AreEqual("c", items [1].Name, "A3"); }
public void TestClone6() { Engine engine; Project project; string documentString = @" <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <ItemGroup> <Item Include='a' /> </ItemGroup> </Project> " ; engine = new Engine(Consts.BinPath); project = engine.CreateNewProject(); project.LoadXml(documentString); BuildItemGroup[] groups = new BuildItemGroup [1]; project.ItemGroups.CopyTo(groups, 0); BuildItemGroup big2 = groups [0].Clone(true); BuildItem[] items = big2.ToArray(); Assert.AreEqual(1, big2.Count, "A1"); Assert.AreEqual(String.Empty, items [0].Condition, "A2"); Assert.AreEqual(String.Empty, items [0].Exclude, "A3"); Assert.AreEqual("a", items [0].FinalItemSpec, "A4"); Assert.AreEqual("a", items [0].Include, "A5"); Assert.IsFalse(items [0].IsImported, "A6"); Assert.AreEqual("Item", items [0].Name, "A7"); }
/// <summary> /// Amazingly sophisticated :) helper function to determine if the set of ITaskItems returned from /// a task match the expected set of ITaskItems. It can also check that the ITaskItems have the expected /// metadata, and that the ITaskItems are returned in the correct order. /// /// The "expectedItemsString" is a formatted way of easily specifying which items you expect to see. /// The format is: /// /// itemspec1 : metadataname1=metadatavalue1 ; metadataname2=metadatavalue2 ; ... /// itemspec2 : metadataname3=metadatavalue3 ; metadataname4=metadatavalue4 ; ... /// itemspec3 : metadataname5=metadatavalue5 ; metadataname6=metadatavalue6 ; ... /// /// (Each item needs to be on its own line.) /// /// </summary> /// <param name="expectedItemsString"></param> /// <param name="actualItems"></param> /// <owner>RGoel</owner> static internal void AssertItemsMatch ( string expectedItemsString, BuildItemGroup actualItems, bool orderOfItemsShouldMatch ) { AssertItemsMatch(expectedItemsString, actualItems.ToArray(), orderOfItemsShouldMatch); }
public void ToArray() { XmlElement ig = CreatePersistedItemGroupElement(); BuildItemGroup group = new BuildItemGroup(ig, false, new Project()); BuildItem[] array = group.ToArray(); Assertion.AssertEquals(2, array.Length); Assertion.AssertEquals("i1", array[0].Include); Assertion.AssertEquals("i2", array[1].Include); }
public void ToArrayChangeMadeToArray() { project.LoadXml(ProjectContentWithOneBuildItemGroupThreeBuildItems); BuildItemGroup group = GetBuildItemGroupFromProject(project, false); BuildItem[] items = group.ToArray(); Assertion.AssertEquals(3, items.Length); items[0].Include = "New"; Dictionary <string, string> groupItems = GetDictionaryOfBuildItemsInBuildItemsGroup(group); Assertion.AssertEquals("New", items[0].Include); Assertion.AssertEquals("New", groupItems["n1"]); }
public void TestRemoveItemAt1() { BuildItemGroup big = new BuildItemGroup(); big.AddNewItem("a", "b"); big.AddNewItem("b", "c"); big.AddNewItem("c", "d"); big.RemoveItemAt(1); BuildItem[] items = big.ToArray(); Assert.AreEqual(2, big.Count, "A1"); Assert.AreEqual("a", items [0].Name, "A2"); Assert.AreEqual("c", items [1].Name, "A3"); }
public void ToArrayChangeMadeToGroup() { project.LoadXml(ProjectContentWithOneBuildItemGroupThreeBuildItems); BuildItemGroup group = GetBuildItemGroupFromProject(project, false); BuildItem[] items = group.ToArray(); Assertion.AssertEquals(3, items.Length); //// Change first item in group by removing it and re-adding it with a new itemInclude value group.RemoveItemAt(0); group.AddNewItem("n1", "New"); Dictionary <string, string> groupItems = GetDictionaryOfBuildItemsInBuildItemsGroup(group); Assertion.AssertEquals("i1", items[0].Include); Assertion.AssertEquals("New", groupItems["n1"]); }
/// <summary> /// Render feature list /// </summary> private void RenderFeatureList(List <Feature> features, string[][] templateFields, List <KeyValuePair <FeatureRendererAttribute, IFeatureRenderer> > renderers, BuildItemGroup fileItemGroup, BuildItemGroup mobileItemGroup, Dictionary <String, StringCollection> parameters) { // Scan the class repo and start processing foreach (Feature f in features) { System.Diagnostics.Trace.WriteLine(String.Format("Rendering C# for '{0}'...", f.Name), "debug"); // Is there a renderer for this feature KeyValuePair <FeatureRendererAttribute, IFeatureRenderer> fr = renderers.Find(o => o.Key.Feature == f.GetType()); // Was a renderer found? if (fr.Key == null) { System.Diagnostics.Trace.WriteLine(String.Format("can't find renderer for {0}", f.GetType().Name), "warn"); } else { string file = String.Empty; try // To write the file { // Start the rendering file = fr.Value.CreateFile(f, hostContext.Output); // Is the renderer for a file if (fr.Key.IsFile) { TextWriter tw = File.CreateText(file); try // Render the file { string Header = Template.Default; // Set the header to the default // Populate template fields foreach (String[] st in templateFields) { Header = Header.Replace(st[0], st[1]); } // Write header tw.Write(Header); // Render the template out fr.Value.Render(parameters["rimbapi-target-ns"][0], parameters["rimbapi-api-ns"][0], f, tw); } finally { tw.Close(); } // Add to the files in the project string projName = file.Replace(hostContext.Output, ""); if (projName.StartsWith(Path.DirectorySeparatorChar.ToString())) { projName = projName.Substring(1); } if (Array.Find <BuildItem>(fileItemGroup.ToArray(), itm => itm.Include.Equals(projName)) == null) { fileItemGroup.AddNewItem("Compile", projName); mobileItemGroup.AddNewItem("Compile", projName); } else { Trace.WriteLine(String.Format("Class '{0}' is defined more than once, second include is ignored", projName), "warn"); } } } catch (NotSupportedException) { if (!String.IsNullOrEmpty(file)) { File.Delete(file); } } catch (Exception e) { if (!String.IsNullOrEmpty(file)) { File.Delete(file); } System.Diagnostics.Trace.WriteLine(e.Message, "error"); } } } }