Beispiel #1
0
        public void CopyMetadataToDoesNotCopyExtension()
        {
            TaskItem from = new TaskItem("myfile.txt");
            TaskItem to = new TaskItem("myfile.bin");

            from.CopyMetadataTo(to);
            
            Assertion.AssertEquals(".bin", to.GetMetadata("Extension"));
        }
Beispiel #2
0
 public void SimpleCopyMetadataTo()
 {
     TaskItem from = new TaskItem("myfile.txt");
     from.SetMetadata("Culture", "fr");
     
     TaskItem to = new TaskItem("myfile.bin");
     from.CopyMetadataTo(to);
     
     Assertion.AssertEquals("fr", to.GetMetadata("Culture"));
 }
Beispiel #3
0
        public void CopyMetadataToWithDefaults()
        {
            BuildItem fromBuildItem = BuildItem_Tests.GetXmlBackedItemWithDefinitionLibrary(); // i1;  has m=m1 (default) and n=n1 (regular)
            TaskItem from = new TaskItem(fromBuildItem);

            TaskItem to = new TaskItem("i2");
            from.CopyMetadataTo(to);

            Assertion.AssertEquals("n1", to.GetMetadata("n"));
            Assertion.AssertEquals("m1", to.GetMetadata("m"));
        }
Beispiel #4
0
        /// <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,
            BuildItem[] actualItems,
            bool orderOfItemsShouldMatch
        )
        {
            ITaskItem[] actualTaskItems = new ITaskItem[actualItems.Length];

            int i = 0;

            foreach (BuildItem actualItem in actualItems)
            {
                actualTaskItems[i++] = new Microsoft.Build.BuildEngine.TaskItem(actualItem);
            }

            ObjectModelHelpers.AssertItemsMatch(expectedItemsString, actualTaskItems, orderOfItemsShouldMatch);
        }
Beispiel #5
0
        /// <summary>
        /// Convert the given array of BuildItems into ITaskItems (BuildItem names are lost)
        /// </summary>
        /// <param name="originalItems"></param>
        /// <returns></returns>
        internal static ITaskItem[] ConvertBuildItemArrayToTaskItems(BuildItem[] originalItems)
        {
            if (originalItems == null)
            {
                return null;
            }

            ITaskItem[] convertedItems = new TaskItem[originalItems.Length];

            for (int i = 0; i < originalItems.Length; i++)
            {
                if (originalItems[i].IsUninitializedItem)
                {
                    convertedItems[i] = new TaskItem(originalItems[i].FinalItemSpecEscaped);
                    foreach (DictionaryEntry metadata in originalItems[i].GetAllCustomEvaluatedMetadata())
                    {
                        convertedItems[i].SetMetadata((string)metadata.Key, EscapingUtilities.UnescapeAll((string)metadata.Value));
                    }
                }
                else
                {
                    convertedItems[i] = new TaskItem(originalItems[i]);
                }
            }

            return convertedItems;
        }
Beispiel #6
0
        /// <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, 
            BuildItem[] actualItems, 
            bool orderOfItemsShouldMatch
            )
        {
            ITaskItem[] actualTaskItems = new ITaskItem[actualItems.Length];

            int i = 0;
            foreach (BuildItem actualItem in actualItems)
            {
                actualTaskItems[i++] = new Microsoft.Build.BuildEngine.TaskItem(actualItem);
            }

            ObjectModelHelpers.AssertItemsMatch(expectedItemsString, actualTaskItems, orderOfItemsShouldMatch);
        }
Beispiel #7
0
 public void CreateNullNamedMetadata()
 {
     TaskItem item = new TaskItem("foo");
     item.SetMetadata(null, "x");
 }
Beispiel #8
0
 public void CreateEmptyNamedMetadata()
 {
     TaskItem item = new TaskItem("foo");
     item.SetMetadata("", "x");
 }