/// <summary>
        /// Helper for array serialization.
        /// </summary>
        private void HelperTestArray(string[] initialValue, IComparer <string> comparer)
        {
            string[] value = initialValue;
            TranslationHelpers.GetWriteTranslator().Translate(ref value);

            string[] deserializedValue = null;
            TranslationHelpers.GetReadTranslator().Translate(ref deserializedValue);

            Assert.True(TranslationHelpers.CompareCollections(value, deserializedValue, comparer));
        }
        public void TestSerializeArrayWithFactoryNull()
        {
            BaseClass[] value = null;
            TranslationHelpers.GetWriteTranslator().TranslateArray(ref value, BaseClass.FactoryForDeserialization);

            BaseClass[] deserializedValue = null;
            TranslationHelpers.GetReadTranslator().TranslateArray(ref deserializedValue, BaseClass.FactoryForDeserialization);

            Assert.True(TranslationHelpers.CompareCollections(value, deserializedValue, BaseClass.Comparer));
        }
        public void TestSerializeArrayNull()
        {
            DerivedClass[] value = null;
            TranslationHelpers.GetWriteTranslator().TranslateArray(ref value);

            DerivedClass[] deserializedValue = null;
            TranslationHelpers.GetReadTranslator().TranslateArray(ref deserializedValue);

            Assert.True(TranslationHelpers.CompareCollections(value, deserializedValue, DerivedClass.Comparer));
        }
        /// <summary>
        /// Helper for list serialization.
        /// </summary>
        private void HelperTestList(List <string> initialValue, IComparer <string> comparer)
        {
            List <string> value = initialValue;

            TranslationHelpers.GetWriteTranslator().Translate(ref value);

            List <string> deserializedValue = null;

            TranslationHelpers.GetReadTranslator().Translate(ref deserializedValue);

            Assert.True(TranslationHelpers.CompareCollections(value, deserializedValue, comparer));
        }
Ejemplo n.º 5
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.º 6
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.º 7
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));
        }