コード例 #1
0
        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);
        }
コード例 #2
0
        public void TestTranslation()
        {
            PropertyDictionary <ProjectPropertyInstance> properties = new PropertyDictionary <ProjectPropertyInstance>();

            properties.Set(ProjectPropertyInstance.Create("this", "that"));
            properties.Set(ProjectPropertyInstance.Create("foo", "bar"));

            BuildRequestData          data   = new BuildRequestData("file", properties.ToDictionary(), "4.0", new string[0], null);
            BuildRequestConfiguration config = new BuildRequestConfiguration(data, "2.0");

            Assert.Equal(NodePacketType.BuildRequestConfiguration, config.Type);

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

            BuildRequestConfiguration deserializedConfig = packet as BuildRequestConfiguration;

            Assert.Equal(config, deserializedConfig);
        }