public void TestSerializeWithFactoryNull()
        {
            BaseClass value = null;

            TranslationHelpers.GetWriteTranslator().Translate(ref value, BaseClass.FactoryForDeserialization);

            BaseClass deserializedValue = null;

            TranslationHelpers.GetReadTranslator().Translate(ref deserializedValue, BaseClass.FactoryForDeserialization);

            Assert.AreEqual(value, deserializedValue);
        }
        public void TestSerializeDictionaryStringStringNull()
        {
            Dictionary <string, string> value = null;

            TranslationHelpers.GetWriteTranslator().TranslateDictionary(ref value, StringComparer.OrdinalIgnoreCase);

            Dictionary <string, string> deserializedValue = null;

            TranslationHelpers.GetReadTranslator().TranslateDictionary(ref deserializedValue, StringComparer.OrdinalIgnoreCase);

            Assert.AreEqual(value, deserializedValue);
        }
        public void TestSerializeDotNetNull()
        {
            ArgumentNullException value = null;

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

            ArgumentNullException deserializedValue = null;

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

            Assert.IsTrue(TranslationHelpers.CompareExceptions(value, deserializedValue));
        }
        public void TestSerializeINodePacketSerializableNull()
        {
            DerivedClass value = null;

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

            DerivedClass deserializedValue = null;

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

            Assert.AreEqual(value, deserializedValue);
        }
        /// <summary>
        /// Tests serializing enums.
        /// </summary>
        public void TestSerializeEnum()
        {
            TranslationDirection value = TranslationDirection.ReadFromStream;

            TranslationHelpers.GetWriteTranslator().TranslateEnum(ref value, (int)value);

            TranslationDirection deserializedValue = TranslationDirection.WriteToStream;

            TranslationHelpers.GetReadTranslator().TranslateEnum(ref deserializedValue, (int)deserializedValue);

            Assert.AreEqual(value, deserializedValue);
        }
        public void TestSerializeDotNet()
        {
            ArgumentNullException value = new ArgumentNullException("The argument was null", new InsufficientMemoryException());

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

            ArgumentNullException deserializedValue = null;

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

            Assert.IsTrue(TranslationHelpers.CompareExceptions(value, deserializedValue));
        }
        /// <summary>
        /// Helper for DateTime serialization.
        /// </summary>
        private void HelperTestSimpleType(DateTime initialValue, DateTime deserializedInitialValue)
        {
            DateTime value = initialValue;

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

            DateTime deserializedValue = deserializedInitialValue;

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

            Assert.Equal(value, deserializedValue);
        }
        /// <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));
        }
        /// <summary>
        /// Helper for string serialization.
        /// </summary>
        private void HelperTestSimpleType(string initialValue, string deserializedInitialValue)
        {
            string value = initialValue;

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

            string deserializedValue = deserializedInitialValue;

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

            Assert.Equal(value, deserializedValue);
        }
        /// <summary>
        /// Helper for int serialization.
        /// </summary>
        private void HelperTestSimpleType(int initialValue, int deserializedInitialValue)
        {
            int value = initialValue;

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

            int deserializedValue = deserializedInitialValue;

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

            Assert.Equal(value, deserializedValue);
        }
        /// <summary>
        /// Helper for TimeSpan serialization.
        /// </summary>
        private void HelperTestSimpleType(TimeSpan initialValue, TimeSpan deserializedInitialValue)
        {
            TimeSpan value = initialValue;

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

            TimeSpan deserializedValue = deserializedInitialValue;

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

            Assert.Equal(value, deserializedValue);
        }
        public void TestSerializeDictionaryStringTNoComparerNull()
        {
            Dictionary <string, BaseClass> value = null;

            TranslationHelpers.GetWriteTranslator().TranslateDictionary <Dictionary <string, BaseClass>, BaseClass>(ref value, BaseClass.FactoryForDeserialization);

            Dictionary <string, BaseClass> deserializedValue = null;

            TranslationHelpers.GetReadTranslator().TranslateDictionary <Dictionary <string, BaseClass>, BaseClass>(ref deserializedValue, BaseClass.FactoryForDeserialization);

            Assert.Equal(value, deserializedValue);
        }
Ejemplo n.º 13
0
        public void TestTranslationWithNullDictionary()
        {
            TaskHostConfiguration config = new TaskHostConfiguration(1, Environment.CurrentDirectory, null, Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentUICulture, null, 1, 1, @"c:\my project\myproj.proj", _continueOnErrorDefault, "TaskName", @"c:\MyTasks\MyTask.dll", null);

            ((INodePacketTranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            TaskHostConfiguration deserializedConfig = packet as TaskHostConfiguration;

            Assert.AreEqual(config.TaskName, deserializedConfig.TaskName);
            Assert.AreEqual(config.TaskLocation, config.TaskLocation);
            Assert.IsNull(deserializedConfig.TaskParameters);
        }
        public void TestTranslationWithEmptyDictionary()
        {
            TaskHostTaskComplete complete = new TaskHostTaskComplete(new OutOfProcTaskHostTaskResult(TaskCompleteType.Success, new Dictionary <string, object>()), null);

            ((INodePacketTranslatable)complete).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = TaskHostTaskComplete.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            TaskHostTaskComplete deserializedComplete = packet as TaskHostTaskComplete;

            Assert.Equal(complete.TaskResult, deserializedComplete.TaskResult);
            Assert.NotNull(deserializedComplete.TaskOutputParameters);
            Assert.Equal(complete.TaskOutputParameters.Count, deserializedComplete.TaskOutputParameters.Count);
        }
Ejemplo n.º 15
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"),
                    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()
                };

                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.º 16
0
        public void TestTranslationHostObjectsWhenEmpty()
        {
            var          hostServices = new HostServices();
            BuildRequest request      = new BuildRequest(
                submissionId: 1,
                _nodeRequestId++,
                1,
                new string[] { "alpha", "omega" },
                hostServices: hostServices,
                BuildEventContext.Invalid,
                parentRequest: null);

            ((ITranslatable)request).Translate(TranslationHelpers.GetWriteTranslator());
            BuildRequest.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
        }
Ejemplo n.º 17
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));
        }
        public void TestTranslation()
        {
            BuildRequestConfigurationResponse response = new BuildRequestConfigurationResponse(1, 2, 3);

            Assert.Equal(response.Type, NodePacketType.BuildRequestConfigurationResponse);

            ((INodePacketTranslatable)response).Translate(TranslationHelpers.GetWriteTranslator());

            INodePacket deserializedPacket = BuildRequestConfigurationResponse.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
            BuildRequestConfigurationResponse deserializedResponse = deserializedPacket as BuildRequestConfigurationResponse;

            Assert.Equal(response.NodeConfigurationId, deserializedResponse.NodeConfigurationId);
            Assert.Equal(response.GlobalConfigurationId, deserializedResponse.GlobalConfigurationId);
            Assert.Equal(response.ResultsNodeId, deserializedResponse.ResultsNodeId);
        }
        public void TestTranslationWithITaskItemArrayInDictionary()
        {
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("TaskItemArrayValue", new ITaskItem[] { new TaskItem("Foo"), new TaskItem("Baz") });
            TaskHostConfiguration config = new TaskHostConfiguration(
                nodeId: 1,
                startupDirectory: Directory.GetCurrentDirectory(),
                buildProcessEnvironment: null,
                culture: Thread.CurrentThread.CurrentCulture,
                uiCulture: Thread.CurrentThread.CurrentUICulture,
#if FEATURE_APPDOMAIN
                appDomainSetup:
#if FEATURE_APPDOMAIN
                null,
#endif
                lineNumberOfTask:
#endif
                1,
                columnNumberOfTask: 1,
                projectFileOfTask: @"c:\my project\myproj.proj",
                continueOnError: _continueOnErrorDefault,
                taskName: "TaskName",
                taskLocation: @"c:\MyTasks\MyTask.dll",
                isTaskInputLoggingEnabled: false,
                taskParameters: parameters,
                globalParameters: null,
                warningsAsErrors: null,
                warningsNotAsErrors: null,
                warningsAsMessages: null);

            ((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            TaskHostConfiguration deserializedConfig = packet as TaskHostConfiguration;

            Assert.Equal(config.TaskName, deserializedConfig.TaskName);
#if !FEATURE_ASSEMBLYLOADCONTEXT
            Assert.Equal(config.TaskLocation, deserializedConfig.TaskLocation);
#endif
            Assert.NotNull(deserializedConfig.TaskParameters);
            Assert.Equal(config.TaskParameters.Count, deserializedConfig.TaskParameters.Count);

            ITaskItem[] itemArray             = (ITaskItem[])config.TaskParameters["TaskItemArrayValue"].WrappedParameter;
            ITaskItem[] deserializedItemArray = (ITaskItem[])deserializedConfig.TaskParameters["TaskItemArrayValue"].WrappedParameter;

            TaskHostPacketHelpers.AreEqual(itemArray, deserializedItemArray);
        }
        public void TestTranslation()
        {
            var globalProperties = new PropertyDictionary <ProjectPropertyInstance>();

            globalProperties["a"] = ProjectPropertyInstance.Create("a", "b");

            var initial = new ConfigurationMetadata("path", globalProperties);

            initial.Translate(TranslationHelpers.GetWriteTranslator());
            var copy = ConfigurationMetadata.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            copy.ProjectFullPath.ShouldBe(initial.ProjectFullPath);
            copy.ToolsVersion.ShouldBe(initial.ToolsVersion);

            Assert.Equal(copy.GlobalProperties.GetCopyOnReadEnumerable(), initial.GlobalProperties.GetCopyOnReadEnumerable(), EqualityComparer <ProjectPropertyInstance> .Default);
        }
        public void TestTranslationWithNullDictionary()
        {
            var expectedGlobalProperties = new Dictionary <string, string>
            {
                ["Property1"] = "Value1",
                ["Property2"] = "Value2"
            };

            TaskHostConfiguration config = new TaskHostConfiguration(
                nodeId: 1,
                startupDirectory: Directory.GetCurrentDirectory(),
                buildProcessEnvironment: null,
                culture: Thread.CurrentThread.CurrentCulture,
                uiCulture: Thread.CurrentThread.CurrentUICulture,
#if FEATURE_APPDOMAIN
                appDomainSetup:
#if FEATURE_APPDOMAIN
                null,
#endif
                lineNumberOfTask:
#endif
                1,
                columnNumberOfTask: 1,
                projectFileOfTask: @"c:\my project\myproj.proj",
                continueOnError: _continueOnErrorDefault,
                taskName: "TaskName",
                taskLocation: @"c:\MyTasks\MyTask.dll",
                isTaskInputLoggingEnabled: false,
                taskParameters: null,
                globalParameters: expectedGlobalProperties,
                warningsAsErrors: null,
                warningsNotAsErrors: null,
                warningsAsMessages: null);

            ((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            TaskHostConfiguration deserializedConfig = packet as TaskHostConfiguration;

            Assert.Equal(config.TaskName, deserializedConfig.TaskName);
#if !FEATURE_ASSEMBLYLOADCONTEXT
            Assert.Equal(config.TaskLocation, deserializedConfig.TaskLocation);
#endif
            Assert.Null(deserializedConfig.TaskParameters);

            Assert.Equal(expectedGlobalProperties, deserializedConfig.GlobalProperties);
        }
        public void TestTranslationWithWarningsAsErrors()
        {
            HashSet <string> WarningsAsErrors = new HashSet <string>();

            WarningsAsErrors.Add("MSB1234");
            WarningsAsErrors.Add("MSB1235");
            WarningsAsErrors.Add("MSB1236");
            WarningsAsErrors.Add("MSB1237");
            TaskHostConfiguration config = new TaskHostConfiguration(
                nodeId: 1,
                startupDirectory: Directory.GetCurrentDirectory(),
                buildProcessEnvironment: null,
                culture: Thread.CurrentThread.CurrentCulture,
                uiCulture: Thread.CurrentThread.CurrentUICulture,
#if FEATURE_APPDOMAIN
                appDomainSetup:
#if FEATURE_APPDOMAIN
                null,
#endif
                lineNumberOfTask:
#endif
                1,
                columnNumberOfTask: 1,
                projectFileOfTask: @"c:\my project\myproj.proj",
                continueOnError: _continueOnErrorDefault,
                taskName: "TaskName",
                taskLocation: @"c:\MyTasks\MyTask.dll",
                isTaskInputLoggingEnabled: false,
                taskParameters: null,
                globalParameters: null,
                warningsAsErrors: WarningsAsErrors,
                warningsNotAsErrors: null,
                warningsAsMessages: null);

            ((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            TaskHostConfiguration deserializedConfig = packet as TaskHostConfiguration;

            Assert.Equal(config.TaskName, deserializedConfig.TaskName);
#if !FEATURE_ASSEMBLYLOADCONTEXT
            Assert.Equal(config.TaskLocation, deserializedConfig.TaskLocation);
#endif
            Assert.NotNull(deserializedConfig.WarningsAsErrors);
            config.WarningsAsErrors.SequenceEqual(deserializedConfig.WarningsAsErrors, StringComparer.Ordinal).ShouldBeTrue();
        }
        public void TestTranslationWithITaskItemInDictionary()
        {
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("TaskItemValue", new TaskItem("Foo"));
            TaskHostTaskComplete complete = new TaskHostTaskComplete(new OutOfProcTaskHostTaskResult(TaskCompleteType.Success, parameters), null);

            ((INodePacketTranslatable)complete).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = TaskHostTaskComplete.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            TaskHostTaskComplete deserializedComplete = packet as TaskHostTaskComplete;

            Assert.Equal(complete.TaskResult, deserializedComplete.TaskResult);
            Assert.NotNull(deserializedComplete.TaskOutputParameters);
            Assert.Equal(complete.TaskOutputParameters.Count, deserializedComplete.TaskOutputParameters.Count);
            TaskHostPacketHelpers.AreEqual((ITaskItem)complete.TaskOutputParameters["TaskItemValue"].WrappedParameter, (ITaskItem)deserializedComplete.TaskOutputParameters["TaskItemValue"].WrappedParameter);
        }
Ejemplo n.º 24
0
        public void TestTranslationWithValueTypesInDictionary()
        {
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("Text", "Foo");
            parameters.Add("BoolValue", false);
            TaskHostConfiguration config = new TaskHostConfiguration(
                1,
                Directory.GetCurrentDirectory(),
                null,
#if FEATURE_THREAD_CULTURE
                Thread.CurrentThread.CurrentCulture,
                Thread.CurrentThread.CurrentUICulture,
#else
                CultureInfo.CurrentCulture,
                CultureInfo.CurrentCulture,
#endif
#if FEATURE_APPDOMAIN
                null,
#endif
                1,
                1,
                @"c:\my project\myproj.proj",
                _continueOnErrorDefault,
                "TaskName",
#if FEATURE_ASSEMBLY_LOADFROM
                @"c:\MyTasks\MyTask.dll",
#else
                new AssemblyName("MyTask"),
#endif
                parameters);

            ((INodePacketTranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            TaskHostConfiguration deserializedConfig = packet as TaskHostConfiguration;

            Assert.Equal(config.TaskName, deserializedConfig.TaskName);
#if FEATURE_ASSEMBLY_LOADFROM
            Assert.Equal(config.TaskLocation, config.TaskLocation);
#endif
            Assert.NotNull(deserializedConfig.TaskParameters);
            Assert.Equal(config.TaskParameters.Count, deserializedConfig.TaskParameters.Count);
            Assert.Equal(config.TaskParameters["Text"].WrappedParameter, deserializedConfig.TaskParameters["Text"].WrappedParameter);
            Assert.Equal(config.TaskParameters["BoolValue"].WrappedParameter, deserializedConfig.TaskParameters["BoolValue"].WrappedParameter);
        }
        public void TestTranslationWithEntireProjectState()
        {
            string projectBody = ObjectModelHelpers.CleanupFileContents(@"
<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<PropertyGroup>
    <One>1</One>
    <Two>2</Two>
    <Three>$(ThreeIn)</Three>
</PropertyGroup>
<Target Name='Build'>
    <CallTarget Targets='Foo'/>
</Target>
</Project>");

            Dictionary <string, string> globalProperties = new (StringComparer.OrdinalIgnoreCase);

            globalProperties["ThreeIn"] = "3";

            Project project = new Project(
                XmlReader.Create(new StringReader(projectBody)),
                globalProperties,
                ObjectModelHelpers.MSBuildDefaultToolsVersion,
                new ProjectCollection());

            project.FullPath = "foo";
            ProjectInstance instance = project.CreateProjectInstance();

            instance.TranslateEntireState = true;

            BuildRequestConfiguration configuration = new BuildRequestConfiguration(new BuildRequestData(instance, new string[] { }, null), "2.0");

            configuration.ConfigurationId = 1;

            ((ITranslatable)configuration).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = BuildRequestConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            BuildRequestConfiguration deserializedConfig = packet as BuildRequestConfiguration;

            deserializedConfig.ShouldNotBeNull();
            deserializedConfig.ShouldBe(configuration);
            deserializedConfig.Project.ShouldNotBeNull();

            // Verify that at least some data from 'entire project state' has been deserialized.
            deserializedConfig.Project.Directory.ShouldNotBeEmpty();
            deserializedConfig.Project.Directory.ShouldBe(configuration.Project.Directory);
        }
Ejemplo n.º 26
0
        public void TestSerializeDictionaryStringTNoComparer()
        {
            Dictionary <string, BaseClass> value = new Dictionary <string, BaseClass>();

            value["foo"]   = new BaseClass(1);
            value["alpha"] = new BaseClass(2);

            TranslationHelpers.GetWriteTranslator().TranslateDictionary <Dictionary <string, BaseClass>, BaseClass>(ref value, BaseClass.FactoryForDeserialization);

            Dictionary <string, BaseClass> deserializedValue = null;

            TranslationHelpers.GetReadTranslator().TranslateDictionary <Dictionary <string, BaseClass>, BaseClass>(ref deserializedValue, BaseClass.FactoryForDeserialization);

            Assert.Equal(value.Count, deserializedValue.Count);
            Assert.Equal(BaseClass.Comparer.Compare(value["foo"], deserializedValue["foo"]), 0);
            Assert.Equal(BaseClass.Comparer.Compare(value["alpha"], deserializedValue["alpha"]), 0);
            Assert.False(deserializedValue.ContainsKey("FOO"));
        }
Ejemplo n.º 27
0
        public void TestSerializeDictionaryStringT()
        {
            Dictionary <string, BaseClass> value = new Dictionary <string, BaseClass>(StringComparer.OrdinalIgnoreCase);

            value["foo"]   = new BaseClass(1);
            value["alpha"] = new BaseClass(2);

            TranslationHelpers.GetWriteTranslator().TranslateDictionary(ref value, StringComparer.OrdinalIgnoreCase, BaseClass.FactoryForDeserialization);

            Dictionary <string, BaseClass> deserializedValue = null;

            TranslationHelpers.GetReadTranslator().TranslateDictionary(ref deserializedValue, StringComparer.OrdinalIgnoreCase, BaseClass.FactoryForDeserialization);

            Assert.Equal(value.Count, deserializedValue.Count);
            Assert.Equal(BaseClass.Comparer.Compare(value["foo"], deserializedValue["foo"]), 0);
            Assert.Equal(BaseClass.Comparer.Compare(value["alpha"], deserializedValue["alpha"]), 0);
            Assert.Equal(BaseClass.Comparer.Compare(value["FOO"], deserializedValue["FOO"]), 0);
        }
Ejemplo n.º 28
0
        public void TestSerializeDictionaryStringString()
        {
            Dictionary <string, string> value = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            value["foo"]   = "bar";
            value["alpha"] = "omega";

            TranslationHelpers.GetWriteTranslator().TranslateDictionary(ref value, StringComparer.OrdinalIgnoreCase);

            Dictionary <string, string> deserializedValue = null;

            TranslationHelpers.GetReadTranslator().TranslateDictionary(ref deserializedValue, StringComparer.OrdinalIgnoreCase);

            Assert.Equal(value.Count, deserializedValue.Count);
            Assert.Equal(value["foo"], deserializedValue["foo"]);
            Assert.Equal(value["alpha"], deserializedValue["alpha"]);
            Assert.Equal(value["FOO"], deserializedValue["FOO"]);
        }
Ejemplo n.º 29
0
        public void TestTranslationWithITaskItemInDictionary()
        {
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("TaskItemValue", new TaskItem("Foo"));
            TaskHostConfiguration config = new TaskHostConfiguration(1, Environment.CurrentDirectory, null, Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentUICulture, null, 1, 1, @"c:\my project\myproj.proj", _continueOnErrorDefault, "TaskName", @"c:\MyTasks\MyTask.dll", parameters);

            ((INodePacketTranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            TaskHostConfiguration deserializedConfig = packet as TaskHostConfiguration;

            Assert.AreEqual(config.TaskName, deserializedConfig.TaskName);
            Assert.AreEqual(config.TaskLocation, config.TaskLocation);
            Assert.IsNotNull(deserializedConfig.TaskParameters);
            Assert.AreEqual(config.TaskParameters.Count, deserializedConfig.TaskParameters.Count);
            TaskHostPacketHelpers.AreEqual((ITaskItem)config.TaskParameters["TaskItemValue"].WrappedParameter, (ITaskItem)deserializedConfig.TaskParameters["TaskItemValue"].WrappedParameter);
        }
Ejemplo n.º 30
0
        public void TestTranslationWithITaskItemArrayInDictionary()
        {
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("TaskItemArrayValue", new ITaskItem[] { new TaskItem("Foo"), new TaskItem("Baz") });
            TaskHostConfiguration config = new TaskHostConfiguration(
                1,
                Directory.GetCurrentDirectory(),
                null,
#if FEATURE_THREAD_CULTURE
                Thread.CurrentThread.CurrentCulture,
                Thread.CurrentThread.CurrentUICulture,
#else
                CultureInfo.CurrentCulture,
                CultureInfo.CurrentCulture,
#endif
#if FEATURE_APPDOMAIN
                null,
#endif
                1,
                1,
                @"c:\my project\myproj.proj",
                _continueOnErrorDefault,
                "TaskName",
                @"c:\MyTasks\MyTask.dll",
                parameters);

            ((INodePacketTranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
            INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            TaskHostConfiguration deserializedConfig = packet as TaskHostConfiguration;

            Assert.Equal(config.TaskName, deserializedConfig.TaskName);
#if FEATURE_ASSEMBLY_LOADFROM
            Assert.Equal(config.TaskLocation, config.TaskLocation);
#endif
            Assert.NotNull(deserializedConfig.TaskParameters);
            Assert.Equal(config.TaskParameters.Count, deserializedConfig.TaskParameters.Count);

            ITaskItem[] itemArray             = (ITaskItem[])config.TaskParameters["TaskItemArrayValue"].WrappedParameter;
            ITaskItem[] deserializedItemArray = (ITaskItem[])deserializedConfig.TaskParameters["TaskItemArrayValue"].WrappedParameter;

            TaskHostPacketHelpers.AreEqual(itemArray, deserializedItemArray);
        }