public void RemoveAllIntermediateItems1() { BuildItemGroup group = new BuildItemGroup(); // virtual group XmlElement element = CreatePersistedItemGroupElement(); BuildItem item1 = CreatePersistedBuildItem(element, "i", "i1"); BuildItem item2 = CreatePersistedBuildItem(element, "i", "i2"); group.AddExistingItem(item1); group.AddExistingItem(item2); group.AddNewItem("j", "j1"); Assertion.AssertEquals(3, group.Count); group.RemoveAllIntermediateItems(); Assertion.AssertEquals(2, group.Count); }
public void ModifyItemInProjectPreviouslyModifiedAndGottenThroughGetItem() { // Create some project state with an item with m=m1 and n=n1 Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase); BuildItem item1 = new BuildItem("i1", "a2"); item1.SetMetadata("m", "m1"); BuildItemGroup group0 = new BuildItemGroup(); group0.AddExistingItem(item1); table1["i1"] = group0; Lookup lookup = LookupHelpers.CreateLookup(table1); lookup.EnterScope(); // Make a modification to the item to be m=m2 Dictionary <string, string> newMetadata = new Dictionary <string, string>(); newMetadata.Add("m", "m2"); BuildItemGroup group = new BuildItemGroup(); group.AddItem(item1); lookup.ModifyItems(item1.Name, group, newMetadata); // Get the item (under the covers, it cloned it in order to apply the modification) BuildItemGroup group2 = lookup.GetItems(item1.Name); Assertion.AssertEquals(1, group2.Count); BuildItem item1b = group2[0]; // Modify to m=m3 Dictionary <string, string> newMetadata2 = new Dictionary <string, string>(); newMetadata2.Add("m", "m3"); BuildItemGroup group3 = new BuildItemGroup(); group3.AddItem(item1b); lookup.ModifyItems(item1b.Name, group3, newMetadata2); // Modifications are visible BuildItemGroup group4 = lookup.GetItems(item1b.Name); Assertion.AssertEquals(1, group4.Count); Assertion.AssertEquals("m3", group4[0].GetMetadata("m")); // Leave scope lookup.LeaveScope(); // Still visible BuildItemGroup group5 = lookup.GetItems(item1b.Name); Assertion.AssertEquals(1, group5.Count); Assertion.AssertEquals("m3", group5[0].GetMetadata("m")); // And the one in the project is changed Assertion.AssertEquals("m3", item1.GetMetadata("m")); }
public void RemoveItemFromProjectPreviouslyModifiedAndGottenThroughGetItem() { // Create some project state with an item with m=m1 and n=n1 Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase); BuildItem item1 = new BuildItem("i1", "a2"); item1.SetMetadata("m", "m1"); BuildItemGroup group0 = new BuildItemGroup(); group0.AddExistingItem(item1); table1["i1"] = group0; Lookup lookup = LookupHelpers.CreateLookup(table1); lookup.EnterScope(); // Make a modification to the item to be m=m2 Dictionary <string, string> newMetadata = new Dictionary <string, string>(); newMetadata.Add("m", "m2"); BuildItemGroup group = new BuildItemGroup(); group.AddItem(item1); lookup.ModifyItems(item1.Name, group, newMetadata); // Get the item (under the covers, it cloned it in order to apply the modification) BuildItemGroup group2 = lookup.GetItems(item1.Name); Assertion.AssertEquals(1, group2.Count); BuildItem item1b = group2[0]; // Remove the item lookup.RemoveItem(item1b); // There's now no items at all BuildItemGroup group3 = lookup.GetItems(item1.Name); Assertion.AssertEquals(0, group3.Count); // Leave scope lookup.LeaveScope(); // And now none left in the project either Assertion.AssertEquals(0, ((BuildItemGroup)table1["i1"]).Count); }