Ejemplo n.º 1
0
            /// <summary>
            /// Decompresses the items.
            /// </summary>
            private void DecompressItems()
            {
                ErrorUtilities.VerifyThrow(_uncompressedItems == null, "Items already decompressed.");
                using (MemoryStream serializedStream = new MemoryStream(_compressedItems, 0, _compressedItems.Length, writable: false, publiclyVisible: true))
                {
                    using (DeflateStream inflateStream = new DeflateStream(serializedStream, CompressionMode.Decompress))
                    {
                        INodePacketTranslator   serializedBufferTranslator = NodePacketTranslator.GetReadTranslator(inflateStream, null);
                        LookasideStringInterner interner = new LookasideStringInterner(serializedBufferTranslator);

                        byte[] buffer = null;
                        serializedBufferTranslator.Translate(ref buffer);
                        ErrorUtilities.VerifyThrow(buffer != null, "Unexpected null items buffer during decompression.");

                        using (MemoryStream itemsStream = new MemoryStream(buffer, 0, buffer.Length, writable: false, publiclyVisible: true))
                        {
                            INodePacketTranslator itemTranslator = NodePacketTranslator.GetReadTranslator(itemsStream, null);
                            _uncompressedItems = new TaskItem[_itemsCount];
                            for (int i = 0; i < _uncompressedItems.Length; i++)
                            {
                                _uncompressedItems[i] = TaskItem.FactoryForDeserialization(itemTranslator, interner);
                            }
                        }
                    }
                }

                _compressedItems = null;
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Generate results for the targets requested to be built. Using the TestDataProvider also simulate any
        /// P2P callbacks on the first target. In order to test the cancels there is also functionality to allow the
        /// target execution to wait on a cancel event before exiting
        /// </summary>
        private BuildResult GenerateResults(string[] targetNames)
        {
            bool        simulatedResults = false;
            BuildResult result           = new BuildResult(this.requestEntry.Request);

            foreach (string target in targetNames)
            {
                if (!simulatedResults)
                {
                    SimulateCallBacks();
                    simulatedResults = true;
                }

                // Wait for this to be cancelled
                if (this.testDefinition.WaitForCancel)
                {
                    this.cancellationToken.WaitHandle.WaitOne();
                    this.buildDone.Set();
                    throw new BuildAbortedException();
                }

                if (this.testDefinition.ExecutionTime > 0)
                {
                    Thread.Sleep(this.testDefinition.ExecutionTime);
                }

                TaskItem[]   items        = new TaskItem[] { new TaskItem("itemValue", this.requestEntry.RequestConfiguration.ProjectFullPath) };
                TargetResult targetResult = new TargetResult(items, TestUtilities.GetSuccessResult());
                result.AddResultsForTarget(target, targetResult);
            }

            buildDone.Set();
            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes the results with specified items and result.
 /// </summary>
 /// <param name="items">The items produced by the target.</param>
 /// <param name="result">The overall result for the target.</param>
 internal TargetResult(TaskItem[] items, WorkUnitResult result)
 {
     ErrorUtilities.VerifyThrowArgumentNull(items, "items");
     ErrorUtilities.VerifyThrowArgumentNull(result, "result");
     _itemsStore = new ItemsStore(items);
     _result = result;
 }
Ejemplo n.º 4
0
        public void TestEquivalence()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");
            TaskItem right = new TaskItem("foo", "bar.proj");

            Assert.IsTrue(left == right);
            Assert.IsFalse(left != right);
        }
Ejemplo n.º 5
0
        public void TestEquivalence()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");
            TaskItem right = new TaskItem("foo", "bar.proj");

            Assert.Equal(left, right);
            Assert.Equal(left, right);
        }
Ejemplo n.º 6
0
        public void TestEquivalence()
        {
            TaskItem left  = new TaskItem("foo", "bar.proj");
            TaskItem right = new TaskItem("foo", "bar.proj");

            Assert.Equal(left, right);
            Assert.Equal(left, right);
        }
Ejemplo n.º 7
0
 public void TestConstructorWithItems()
 {
     TaskItem item = new TaskItem("foo", "bar.proj");
     TargetResult result = new TargetResult(new TaskItem[] { item }, TestUtilities.GetStopWithErrorResult());
     Assert.Equal(1, result.Items.Length);
     Assert.Equal(item.ItemSpec, result.Items[0].ItemSpec);
     Assert.Equal(TargetResultCode.Failure, result.ResultCode);
 }
Ejemplo n.º 8
0
        public void TestEquivalence()
        {
            TaskItem left  = new TaskItem("foo", "bar.proj");
            TaskItem right = new TaskItem("foo", "bar.proj");

            Assert.IsTrue(left == right);
            Assert.IsFalse(left != right);
        }
Ejemplo n.º 9
0
        public void TestConstructorWithExceptionNull()
        {
            TaskItem     item   = new TaskItem("foo", "bar.proj");
            TargetResult result = new TargetResult(new TaskItem[] { item }, BuildResultUtilities.GetStopWithErrorResult());

            Assert.Single(result.Items);
            Assert.Null(result.Exception);
            Assert.Equal(TargetResultCode.Failure, result.ResultCode);
        }
Ejemplo n.º 10
0
        public void TestConstructorWithExceptionNull()
        {
            TaskItem     item   = new TaskItem("foo", "bar.proj");
            TargetResult result = new TargetResult(new TaskItem[] { item }, TestUtilities.GetStopWithErrorResult());

            Assert.AreEqual(1, result.Items.Length);
            Assert.IsNull(result.Exception);
            Assert.AreEqual(TargetResultCode.Failure, result.ResultCode);
        }
Ejemplo n.º 11
0
 public void TestConstructorWithException()
 {
     TaskItem item = new TaskItem("foo", "bar.proj");
     TargetResult result = new TargetResult(new TaskItem[] { item }, TestUtilities.GetStopWithErrorResult(new ArgumentException()));
     Assert.Equal(1, result.Items.Length);
     Assert.NotNull(result.Exception);
     Assert.Equal(typeof(ArgumentException), result.Exception.GetType());
     Assert.Equal(TargetResultCode.Failure, result.ResultCode);
 }
Ejemplo n.º 12
0
        public void TestConstructorWithItems()
        {
            TaskItem     item   = new TaskItem("foo", "bar.proj");
            TargetResult result = new TargetResult(new TaskItem[] { item }, TestUtilities.GetStopWithErrorResult());

            Assert.AreEqual(1, result.Items.Length);
            Assert.AreEqual(item.ItemSpec, result.Items[0].ItemSpec);
            Assert.AreEqual(TargetResultCode.Failure, result.ResultCode);
        }
Ejemplo n.º 13
0
        public void TestInequivalenceWithDifferentCustomMetadataCount()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");

            left.SetMetadata("a", "b");
            TaskItem right = new TaskItem("foo", "bar.proj");

            Assert.NotEqual(left, right);
            Assert.NotEqual(left, right);
        }
Ejemplo n.º 14
0
        public void TestEquivalenceWithCustomMetadata()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");
            left.SetMetadata("a", "b");
            TaskItem right = new TaskItem("foo", "bar.proj");
            right.SetMetadata("a", "b");

            Assert.IsTrue(left == right);
            Assert.IsFalse(left != right);
        }
Ejemplo n.º 15
0
        public void TestConstructorWithException()
        {
            TaskItem     item   = new TaskItem("foo", "bar.proj");
            TargetResult result = new TargetResult(new TaskItem[] { item }, TestUtilities.GetStopWithErrorResult(new ArgumentException()));

            Assert.Equal(1, result.Items.Length);
            Assert.NotNull(result.Exception);
            Assert.Equal(typeof(ArgumentException), result.Exception.GetType());
            Assert.Equal(TargetResultCode.Failure, result.ResultCode);
        }
Ejemplo n.º 16
0
        public void TestInequivalenceWithDifferentCustomMetadataCount()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");

            left.SetMetadata("a", "b");
            TaskItem right = new TaskItem("foo", "bar.proj");

            Assert.IsFalse(left == right);
            Assert.IsTrue(left != right);
        }
Ejemplo n.º 17
0
        public void TestTranslation()
        {
            // need to touch the type so that the static constructor runs
            _ = ItemGroupLoggingHelper.OutputItemParameterMessagePrefix;

            TaskItem        item          = new TaskItem("Hello", "my.proj");
            List <TaskItem> targetOutputs = new List <TaskItem>();

            targetOutputs.Add(item);

            string _initialTargetOutputLogging = Environment.GetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING");

            Environment.SetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING", "1");
            try {
                BuildEventArgs[] testArgs = new BuildEventArgs[]
                {
                    new BuildFinishedEventArgs("Message", "Keyword", true),
                    new BuildStartedEventArgs("Message", "Help"),
                    new BuildMessageEventArgs("Message", "help", "sender", MessageImportance.Low),
                    new TaskStartedEventArgs("message", "help", "projectFile", "taskFile", "taskName")
                    {
                        LineNumber   = 345,
                        ColumnNumber = 123
                    },
                    new TaskFinishedEventArgs("message", "help", "projectFile", "taskFile", "taskName", true),
                    new TaskCommandLineEventArgs("commandLine", "taskName", MessageImportance.Low),
                    CreateTaskParameter(),
                    new BuildWarningEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"),
                    new BuildErrorEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"),
                    new TargetStartedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile"),
                    new TargetFinishedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile", true, targetOutputs),
                    new ProjectStartedEventArgs(-1, "message", "help", "ProjectFile", "targetNames", null, null, null),
                    new ProjectFinishedEventArgs("message", "help", "ProjectFile", true),
                    new ExternalProjectStartedEventArgs("message", "help", "senderName", "projectFile", "targetNames"),
                    CreateProjectEvaluationStarted(),
                    CreateProjectEvaluationFinished(),
                    CreateTargetSkipped()
                };

                foreach (BuildEventArgs arg in testArgs)
                {
                    LogMessagePacket packet = new LogMessagePacket(new KeyValuePair <int, BuildEventArgs>(0, arg));

                    ((ITranslatable)packet).Translate(TranslationHelpers.GetWriteTranslator());
                    INodePacket tempPacket = LogMessagePacket.FactoryForDeserialization(TranslationHelpers.GetReadTranslator()) as LogMessagePacket;

                    LogMessagePacket deserializedPacket = tempPacket as LogMessagePacket;

                    CompareLogMessagePackets(packet, deserializedPacket);
                }
            } finally {
                Environment.SetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING", _initialTargetOutputLogging);
            }
        }
Ejemplo n.º 18
0
        public void TestDeepClone()
        {
            TaskItem parent = new TaskItem("foo", "bar.proj");

            parent.SetMetadata("a", "b");
            parent.SetMetadata("c", "d");

            TaskItem clone = parent.DeepClone();

            Assert.True(parent.Equals(clone));                   // "The parent and the clone should be equal"
            Assert.False(object.ReferenceEquals(parent, clone)); // "The parent and the child should not be the same object"
        }
Ejemplo n.º 19
0
        public void TestEquivalenceWithCustomMetadata()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");

            left.SetMetadata("a", "b");
            TaskItem right = new TaskItem("foo", "bar.proj");

            right.SetMetadata("a", "b");

            Assert.Equal(left, right);
            Assert.Equal(left, right);
        }
Ejemplo n.º 20
0
        public void Serialization()
        {
            TaskItem item = new TaskItem("foo", "bar.proj");
            item.SetMetadata("a", "b");

            TranslationHelpers.GetWriteTranslator().Translate(ref item, TaskItem.FactoryForDeserialization);
            TaskItem deserializedItem = null;
            TranslationHelpers.GetReadTranslator().Translate(ref deserializedItem, TaskItem.FactoryForDeserialization);

            Assert.AreEqual(item.ItemSpec, deserializedItem.ItemSpec);
            Assert.AreEqual(item.MetadataCount, deserializedItem.MetadataCount);
            Assert.AreEqual(item.GetMetadata("a"), deserializedItem.GetMetadata("a"));
            Assert.AreEqual(item.GetMetadata(FileUtilities.ItemSpecModifiers.DefiningProjectFullPath), deserializedItem.GetMetadata(FileUtilities.ItemSpecModifiers.DefiningProjectFullPath));
        }
Ejemplo n.º 21
0
        public void TestTranslationWithException()
        {
            TaskItem item = new TaskItem("foo", "bar.proj");

            item.SetMetadata("a", "b");

            TargetResult result = new TargetResult(new TaskItem[] { item }, TestUtilities.GetStopWithErrorResult(new BuildAbortedException()));

            ((INodePacketTranslatable)result).Translate(TranslationHelpers.GetWriteTranslator());
            TargetResult deserializedResult = TargetResult.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            Assert.AreEqual(result.ResultCode, deserializedResult.ResultCode);
            Assert.IsTrue(TranslationHelpers.CompareCollections(result.Items, deserializedResult.Items, TaskItemComparer.Instance));
            Assert.IsTrue(TranslationHelpers.CompareExceptions(result.Exception, deserializedResult.Exception));
        }
Ejemplo n.º 22
0
        public void Serialization()
        {
            TaskItem item = new TaskItem("foo", "bar.proj");

            item.SetMetadata("a", "b");

            TranslationHelpers.GetWriteTranslator().Translate(ref item, TaskItem.FactoryForDeserialization);
            TaskItem deserializedItem = null;

            TranslationHelpers.GetReadTranslator().Translate(ref deserializedItem, TaskItem.FactoryForDeserialization);

            Assert.Equal(item.ItemSpec, deserializedItem.ItemSpec);
            Assert.Equal(item.MetadataCount, deserializedItem.MetadataCount);
            Assert.Equal(item.GetMetadata("a"), deserializedItem.GetMetadata("a"));
            Assert.Equal(item.GetMetadata(FileUtilities.ItemSpecModifiers.DefiningProjectFullPath), deserializedItem.GetMetadata(FileUtilities.ItemSpecModifiers.DefiningProjectFullPath));
        }
Ejemplo n.º 23
0
        public void TestLiveTargetOutputs()
        {
            IDictionary targetOutputs     = new Hashtable();
            IDictionary projectProperties = new Hashtable();

            _taskHost.BuildProjectFile("ProjectFile", new string[] { "Build" }, projectProperties, targetOutputs);

            Assert.NotNull(((ITaskItem[])targetOutputs["Build"])[0]);

            TaskItem targetOutputItem = ((ITaskItem[])targetOutputs["Build"])[0] as TaskItem;
            TaskItem mockItemInCache  = _mockRequestCallback.BuildResultsToReturn[0].ResultsByTarget["Build"].Items[0] as TaskItem;

            // Assert the contents are the same
            Assert.True(targetOutputItem.Equals(mockItemInCache));

            // Assert they are different instances.
            Assert.False(object.ReferenceEquals(targetOutputItem, mockItemInCache));
        }
Ejemplo n.º 24
0
        public void TestTranslationNoException()
        {
            TaskItem item = new TaskItem("foo", "bar.proj");

            item.SetMetadata("a", "b");
            var buildEventContext = new Framework.BuildEventContext(1, 2, 3, 4, 5, 6, 7);

            TargetResult result = new TargetResult(
                new TaskItem[] { item },
                BuildResultUtilities.GetStopWithErrorResult(),
                buildEventContext);

            ((ITranslatable)result).Translate(TranslationHelpers.GetWriteTranslator());
            TargetResult deserializedResult = TargetResult.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            Assert.Equal(result.ResultCode, deserializedResult.ResultCode);
            Assert.True(TranslationHelpers.CompareCollections(result.Items, deserializedResult.Items, TaskItemComparer.Instance));
            Assert.True(TranslationHelpers.CompareExceptions(result.Exception, deserializedResult.Exception));
            Assert.Equal(result.OriginalBuildEventContext, deserializedResult.OriginalBuildEventContext);
        }
Ejemplo n.º 25
0
        public void TestTranslation()
        {
            BuildRequest request = new BuildRequest(1, 1, 2, new string[] { "alpha", "omega" }, null, new BuildEventContext(1, 1, 2, 3, 4, 5), null);
            BuildResult  result  = new BuildResult(request, new BuildAbortedException());

            TaskItem fooTaskItem = new TaskItem("foo", "asdf.proj");

            fooTaskItem.SetMetadata("meta1", "metavalue1");
            fooTaskItem.SetMetadata("meta2", "metavalue2");

            result.InitialTargets = new List <string> {
                "a", "b"
            };
            result.DefaultTargets = new List <string> {
                "c", "d"
            };

            result.AddResultsForTarget("alpha", new TargetResult(new TaskItem[] { fooTaskItem }, BuildResultUtilities.GetSuccessResult()));
            result.AddResultsForTarget("omega", new TargetResult(new TaskItem[] { }, BuildResultUtilities.GetStopWithErrorResult(new ArgumentException("The argument was invalid"))));

            Assert.Equal(NodePacketType.BuildResult, (result as INodePacket).Type);
            ((ITranslatable)result).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = BuildResult.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            BuildResult deserializedResult = packet as BuildResult;

            Assert.Equal(result.ConfigurationId, deserializedResult.ConfigurationId);
            Assert.True(TranslationHelpers.CompareCollections(result.DefaultTargets, deserializedResult.DefaultTargets, StringComparer.Ordinal));
            Assert.True(TranslationHelpers.CompareExceptions(result.Exception, deserializedResult.Exception));
            Assert.Equal(result.Exception.Message, deserializedResult.Exception.Message);
            Assert.Equal(result.GlobalRequestId, deserializedResult.GlobalRequestId);
            Assert.True(TranslationHelpers.CompareCollections(result.InitialTargets, deserializedResult.InitialTargets, StringComparer.Ordinal));
            Assert.Equal(result.NodeRequestId, deserializedResult.NodeRequestId);
            Assert.Equal(result["alpha"].ResultCode, deserializedResult["alpha"].ResultCode);
            Assert.True(TranslationHelpers.CompareExceptions(result["alpha"].Exception, deserializedResult["alpha"].Exception));
            Assert.True(TranslationHelpers.CompareCollections(result["alpha"].Items, deserializedResult["alpha"].Items, TaskItemComparer.Instance));
            Assert.Equal(result["omega"].ResultCode, deserializedResult["omega"].ResultCode);
            Assert.True(TranslationHelpers.CompareExceptions(result["omega"].Exception, deserializedResult["omega"].Exception));
            Assert.True(TranslationHelpers.CompareCollections(result["omega"].Items, deserializedResult["omega"].Items, TaskItemComparer.Instance));
        }
Ejemplo n.º 26
0
        public void TestTranslation()
        {
            TaskItem        item          = new TaskItem("Hello", "my.proj");
            List <TaskItem> targetOutputs = new List <TaskItem>();

            targetOutputs.Add(item);

            Environment.SetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING", "1");
            BuildEventArgs[] testArgs = new BuildEventArgs[]
            {
                new BuildFinishedEventArgs("Message", "Keyword", true),
                new BuildStartedEventArgs("Message", "Help"),
                new BuildMessageEventArgs("Message", "help", "sender", MessageImportance.Low),
                new TaskStartedEventArgs("message", "help", "projectFile", "taskFile", "taskName"),
                new TaskFinishedEventArgs("message", "help", "projectFile", "taskFile", "taskName", true),
                new TaskCommandLineEventArgs("commandLine", "taskName", MessageImportance.Low),
                new BuildWarningEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"),
                new BuildErrorEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"),
                new TargetStartedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile"),
                new TargetFinishedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile", true, targetOutputs),
                new ProjectStartedEventArgs(-1, "message", "help", "ProjectFile", "targetNames", null, null, null),
                new ProjectFinishedEventArgs("message", "help", "ProjectFile", true),
                new ExternalProjectStartedEventArgs("message", "help", "senderName", "projectFile", "targetNames")
            };

            foreach (BuildEventArgs arg in testArgs)
            {
                LogMessagePacket packet = new LogMessagePacket(new KeyValuePair <int, BuildEventArgs>(0, arg));

                ((INodePacketTranslatable)packet).Translate(TranslationHelpers.GetWriteTranslator());
                INodePacket tempPacket = LogMessagePacket.FactoryForDeserialization(TranslationHelpers.GetReadTranslator()) as LogMessagePacket;

                LogMessagePacket deserializedPacket = tempPacket as LogMessagePacket;

                CompareLogMessagePackets(packet, deserializedPacket);
            }

            Environment.SetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING", null);
        }
Ejemplo n.º 27
0
        public void TestTranslation()
        {
            TaskItem item = new TaskItem("Hello", "my.proj");
            List<TaskItem> targetOutputs = new List<TaskItem>();
            targetOutputs.Add(item);

            Environment.SetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING", "1");
            BuildEventArgs[] testArgs = new BuildEventArgs[]
            {
                new BuildFinishedEventArgs("Message", "Keyword", true),
                new BuildStartedEventArgs("Message", "Help"),
                new BuildMessageEventArgs("Message", "help", "sender", MessageImportance.Low),
                new TaskStartedEventArgs("message", "help", "projectFile", "taskFile", "taskName"),
                new TaskFinishedEventArgs("message", "help", "projectFile", "taskFile", "taskName", true),
                new TaskCommandLineEventArgs("commandLine", "taskName", MessageImportance.Low),
                new BuildWarningEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"),
                new BuildErrorEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"),
                new TargetStartedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile"),
                new TargetFinishedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile", true, targetOutputs),
                new ProjectStartedEventArgs(-1, "message", "help", "ProjectFile", "targetNames", null, null, null),
                new ProjectFinishedEventArgs("message", "help", "ProjectFile", true),
                new ExternalProjectStartedEventArgs("message", "help", "senderName", "projectFile", "targetNames")
            };

            foreach (BuildEventArgs arg in testArgs)
            {
                LogMessagePacket packet = new LogMessagePacket(new KeyValuePair<int, BuildEventArgs>(0, arg));

                ((INodePacketTranslatable)packet).Translate(TranslationHelpers.GetWriteTranslator());
                INodePacket tempPacket = LogMessagePacket.FactoryForDeserialization(TranslationHelpers.GetReadTranslator()) as LogMessagePacket;

                LogMessagePacket deserializedPacket = tempPacket as LogMessagePacket;

                CompareLogMessagePackets(packet, deserializedPacket);
            }

            Environment.SetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING", null);
        }
Ejemplo n.º 28
0
        public void ItemDefinitionMetadataCopiedToTaskItem2()
        {
            Project p = new Project(XmlReader.Create(new StringReader(
            @"<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
                <ItemDefinitionGroup>
                    <ItemA>
                        <MetaA>M-A(b)</MetaA>
                        <MetaB>M-B(b)</MetaB>
                    </ItemA>
                </ItemDefinitionGroup>
            </Project>")));

            Assert.IsTrue(p.ItemDefinitions.ContainsKey("ItemA"));

            ProjectInstance pi = p.CreateProjectInstance();
            ITaskItem noMetaItem = null;
            ITaskItem withMetaItem;

            List<ProjectItemDefinitionInstance> itemdefs = new List<ProjectItemDefinitionInstance>();
            itemdefs.Add(pi.ItemDefinitions["ItemA"]);

            noMetaItem = new TaskItem("NoMetaItem", pi.FullPath);
            noMetaItem.SetMetadata("MetaA", "NEWMETA_A");

            withMetaItem = new TaskItem("WithMetaItem", "WithMetaItem", null, itemdefs, ".", false, pi.FullPath);

            // Copy the metadata on the item with no metadata onto the item with metadata
            // from an item definition. The destination item's metadata should be maintained
            noMetaItem.CopyMetadataTo(withMetaItem);

            // New direct metadata takes precedence over item definitions on the destination item
            Assert.AreEqual("NEWMETA_A", withMetaItem.GetMetadata("MetaA"));
            Assert.AreEqual("M-B(b)", withMetaItem.GetMetadata("MetaB"));
        }
Ejemplo n.º 29
0
 public void TestConstructorWithExceptionNull()
 {
     TaskItem item = new TaskItem("foo", "bar.proj");
     TargetResult result = new TargetResult(new TaskItem[] { item }, TestUtilities.GetStopWithErrorResult());
     Assert.AreEqual(1, result.Items.Length);
     Assert.IsNull(result.Exception);
     Assert.AreEqual(TargetResultCode.Failure, result.ResultCode);
 }
Ejemplo n.º 30
0
        public void TestTranslationNoException()
        {
            TaskItem item = new TaskItem("foo", "bar.proj");
            item.SetMetadata("a", "b");

            TargetResult result = new TargetResult(new TaskItem[] { item }, TestUtilities.GetStopWithErrorResult());

            ((INodePacketTranslatable)result).Translate(TranslationHelpers.GetWriteTranslator());
            TargetResult deserializedResult = TargetResult.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            Assert.Equal(result.ResultCode, deserializedResult.ResultCode);
            Assert.True(TranslationHelpers.CompareCollections(result.Items, deserializedResult.Items, TaskItemComparer.Instance));
            Assert.True(TranslationHelpers.CompareExceptions(result.Exception, deserializedResult.Exception));
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Generate results for the targets requested to be built. Using the TestDataProvider also simulate any
        /// P2P callbacks on the first target. In order to test the cancels there is also functionality to allow the
        /// target execution to wait on a cancel event before exiting
        /// </summary>
        private BuildResult GenerateResults(string[] targetNames)
        {
            bool simulatedResults = false;
            BuildResult result = new BuildResult(_requestEntry.Request);
            foreach (string target in targetNames)
            {
                if (!simulatedResults)
                {
                    SimulateCallBacks();
                    simulatedResults = true;
                }

                // Wait for this to be cancelled
                if (_testDefinition.WaitForCancel)
                {
                    _cancellationToken.WaitHandle.WaitOne();
                    _buildDone.Set();
                    throw new BuildAbortedException();
                }

                if (_testDefinition.ExecutionTime > 0)
                {
                    Thread.Sleep(_testDefinition.ExecutionTime);
                }

                TaskItem[] items = new TaskItem[] { new TaskItem("itemValue", _requestEntry.RequestConfiguration.ProjectFullPath) };
                TargetResult targetResult = new TargetResult(items, TestUtilities.GetSuccessResult());
                result.AddResultsForTarget(target, targetResult);
            }

            _buildDone.Set();
            return result;
        }
Ejemplo n.º 32
0
        public void TestInequivalenceWithDifferentCustomMetadataCount2()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");
            left.SetMetadata("a", "b");
            TaskItem right = new TaskItem("foo", "bar.proj");
            right.SetMetadata("a", "b");
            right.SetMetadata("c", "d");

            Assert.NotEqual(left, right);
            Assert.NotEqual(left, right);
        }
Ejemplo n.º 33
0
        public void TestEquivalenceIdentity()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");

            Assert.True(left.Equals(left));
        }
Ejemplo n.º 34
0
        public void TestDeepClone()
        {
            TaskItem parent = new TaskItem("foo", "bar.proj");
            parent.SetMetadata("a", "b");
            parent.SetMetadata("c", "d");

            TaskItem clone = parent.DeepClone();
            Assert.IsTrue(parent.Equals(clone), "The parent and the clone should be equal");
            Assert.IsFalse(object.ReferenceEquals(parent, clone), "The parent and the child should not be the same object");
        }
Ejemplo n.º 35
0
 public void Metadata()
 {
     TaskItem item = BuildItem(
         definitions: new[] { ("a", "base"), ("b", "base") },
Ejemplo n.º 36
0
        public void TestEquivalenceIdentity()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");

            Assert.IsTrue(left.Equals(left));
        }
Ejemplo n.º 37
0
        public void TestInequivalenceWithDifferentCustomMetadataValues()
        {
            TaskItem left = new TaskItem("foo", "bar.proj");
            left.SetMetadata("a", "b");
            TaskItem right = new TaskItem("foo", "bar.proj");
            right.SetMetadata("a", "c");

            Assert.IsFalse(left == right);
            Assert.IsTrue(left != right);
        }
Ejemplo n.º 38
0
        public void TestTranslation()
        {
            BuildRequest request = new BuildRequest(1, 1, 2, new string[] { "alpha", "omega" }, null, new BuildEventContext(1, 1, 2, 3, 4, 5), null);
            BuildResult result = new BuildResult(request, new BuildAbortedException());

            TaskItem fooTaskItem = new TaskItem("foo", "asdf.proj");
            fooTaskItem.SetMetadata("meta1", "metavalue1");
            fooTaskItem.SetMetadata("meta2", "metavalue2");

            result.InitialTargets = new List<string> { "a", "b" };
            result.DefaultTargets = new List<string> { "c", "d" };

            result.AddResultsForTarget("alpha", new TargetResult(new TaskItem[] { fooTaskItem }, TestUtilities.GetSuccessResult()));
            result.AddResultsForTarget("omega", new TargetResult(new TaskItem[] { }, TestUtilities.GetStopWithErrorResult(new ArgumentException("The argument was invalid"))));

            Assert.AreEqual(NodePacketType.BuildResult, (result as INodePacket).Type);
            ((INodePacketTranslatable)result).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = BuildResult.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            BuildResult deserializedResult = packet as BuildResult;

            Assert.AreEqual(result.ConfigurationId, deserializedResult.ConfigurationId);
            Assert.IsTrue(TranslationHelpers.CompareCollections(result.DefaultTargets, deserializedResult.DefaultTargets, StringComparer.Ordinal));
            Assert.IsTrue(TranslationHelpers.CompareExceptions(result.Exception, deserializedResult.Exception));
            Assert.AreEqual(result.Exception.Message, deserializedResult.Exception.Message);
            Assert.AreEqual(result.GlobalRequestId, deserializedResult.GlobalRequestId);
            Assert.IsTrue(TranslationHelpers.CompareCollections(result.InitialTargets, deserializedResult.InitialTargets, StringComparer.Ordinal));
            Assert.AreEqual(result.NodeRequestId, deserializedResult.NodeRequestId);
            Assert.AreEqual(result["alpha"].ResultCode, deserializedResult["alpha"].ResultCode);
            Assert.IsTrue(TranslationHelpers.CompareExceptions(result["alpha"].Exception, deserializedResult["alpha"].Exception));
            Assert.IsTrue(TranslationHelpers.CompareCollections(result["alpha"].Items, deserializedResult["alpha"].Items, TaskItemComparer.Instance));
            Assert.AreEqual(result["omega"].ResultCode, deserializedResult["omega"].ResultCode);
            Assert.IsTrue(TranslationHelpers.CompareExceptions(result["omega"].Exception, deserializedResult["omega"].Exception));
            Assert.IsTrue(TranslationHelpers.CompareCollections(result["omega"].Items, deserializedResult["omega"].Items, TaskItemComparer.Instance));
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Create some items and log them
        /// </summary>
        /// <returns></returns>
        private void WriteAndValidateItems(BaseConsoleLogger cl, SimulatedConsole sc, bool expectToSeeLogging)
        {
            Hashtable items = new Hashtable();
            items.Add("type", (ITaskItem2)new TaskItem("spec", String.Empty));
            items.Add("type2", (ITaskItem2)new TaskItem("spec2", String.Empty));

            // ItemSpecs are expected to be escaped coming in
            ITaskItem2 taskItem3 = new TaskItem("%28spec%3b3", String.Empty);

            // As are metadata, when set with "SetMetadata"
            taskItem3.SetMetadata("f)oo", "%21%40%23");

            items.Add("type(3)", taskItem3);

            string item1type = string.Empty;
            string item2type = string.Empty;
            string item3type = string.Empty;
            string item1spec = string.Empty;
            string item2spec = string.Empty;
            string item3spec = string.Empty;
            string item3metadatum = string.Empty;

            if (cl is SerialConsoleLogger)
            {
                SortedList itemList = ((SerialConsoleLogger)cl).ExtractItemList(items);
                ((SerialConsoleLogger)cl).WriteItems(itemList);
                item1spec = "spec" + Environment.NewLine;
                item2spec = "spec2" + Environment.NewLine;
                item3spec = "(spec;3" + Environment.NewLine;
                item3metadatum = "f)oo = !@#" + Environment.NewLine;
            }
            else
            {
                BuildEventArgs buildEvent = new BuildErrorEventArgs("", "", "", 0, 0, 0, 0, "", "", "");
                buildEvent.BuildEventContext = new BuildEventContext(1, 2, 3, 4);
                ((ParallelConsoleLogger)cl).WriteItems(buildEvent, items);
                item1spec = Environment.NewLine + "    spec" + Environment.NewLine;
                item2spec = Environment.NewLine + "    spec2" + Environment.NewLine;
                item3spec = Environment.NewLine + "    (spec;3" + Environment.NewLine;
            }

            item1type = "type" + Environment.NewLine;
            item2type = "type2" + Environment.NewLine;
            item3type = "type(3)" + Environment.NewLine;

            string log = sc.ToString();

            Console.WriteLine("[" + log + "]");



            // Being careful not to make locale assumptions here, eg about sorting
            if (expectToSeeLogging)
            {
                Assert.IsTrue(log.Contains(item1type));
                Assert.IsTrue(log.Contains(item2type));
                Assert.IsTrue(log.Contains(item3type));
                Assert.IsTrue(log.Contains(item1spec));
                Assert.IsTrue(log.Contains(item2spec));
                Assert.IsTrue(log.Contains(item3spec));

                if (!String.Equals(item3metadatum, String.Empty, StringComparison.OrdinalIgnoreCase))
                {
                    Assert.IsTrue(log.Contains(item3metadatum));
                }
            }
            else
            {
                Assert.IsFalse(log.Contains(item1type));
                Assert.IsFalse(log.Contains(item2type));
                Assert.IsFalse(log.Contains(item3type));
                Assert.IsFalse(log.Contains(item1spec));
                Assert.IsFalse(log.Contains(item2spec));
                Assert.IsFalse(log.Contains(item3type));

                if (!String.Equals(item3metadatum, String.Empty, StringComparison.OrdinalIgnoreCase))
                {
                    Assert.IsFalse(log.Contains(item3metadatum));
                }
            }
        }
Ejemplo n.º 40
0
 /// <summary>
 /// Remember this TaskItem so that we can disconnect it when this Task has finished executing
 /// Only if we're passing TaskItems to another AppDomain is this necessary. This call
 /// Will make that determination for you.
 /// </summary>
 private void RecordItemForDisconnectIfNecessary(TaskItem item)
 {
     if (_remotedTaskItems != null)
     {
         // remember that we need to disconnect this item
         _remotedTaskItems.Add(item);
     }
 }
Ejemplo n.º 41
0
        public void ItemDefinitionMetadataCopiedToTaskItem3()
        {
            Project p = new Project(XmlReader.Create(new StringReader(
            @"<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
                <ItemDefinitionGroup>
                    <ItemA>
                        <MetaA>M-A(b)</MetaA>
                        <MetaB>M-B(b)</MetaB>
                    </ItemA>
                </ItemDefinitionGroup>
                <ItemGroup>
                    <ItemA Include='SomeItemA' />
                </ItemGroup>
            </Project>")));

            Assert.IsTrue(p.ItemDefinitions.ContainsKey("ItemA"));

            ProjectInstance pi = p.CreateProjectInstance();
            ITaskItem noMetaItem = null;
            ITaskItem withMetaItem = null;

            List<ProjectItemDefinitionInstance> itemdefs = new List<ProjectItemDefinitionInstance>();
            itemdefs.Add(pi.ItemDefinitions["ItemA"]);

            noMetaItem = new TaskItem("NoMetaItem", pi.FullPath);

            // No the ideal way to get the first item, but there is no other way since GetItems returns an IEnumerable :(
            foreach (ProjectItemInstance item in pi.GetItems("ItemA"))
            {
                withMetaItem = item;
            }

            // Copy the metadata on the item with no metadata onto the item with metadata
            // from an item definition. The destination item's metadata should be maintained
            noMetaItem.CopyMetadataTo(withMetaItem);

            Assert.AreEqual("M-A(b)", withMetaItem.GetMetadata("MetaA"));
            Assert.AreEqual("M-B(b)", withMetaItem.GetMetadata("MetaB"));
        }
Ejemplo n.º 42
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ItemsStore(TaskItem[] items)
 {
     ErrorUtilities.VerifyThrowArgumentNull(items, "items");
     _uncompressedItems = items;
     _itemsCount = items.Length;
 }