Ejemplo n.º 1
0
        public static IEnumerable <object[]> ProjectInstanceHasEvaluationIdTestData()
        {
            // from file (new)
            yield return(new ProjectInstanceFactory[]
            {
                (f, xml, c) => new ProjectInstance(f, null, null, c)
            });

            // from file (factory method)
            yield return(new ProjectInstanceFactory[]
            {
                (f, xml, c) => ProjectInstance.FromFile(f, new ProjectOptions {
                    ProjectCollection = c
                })
            });

            // from Project
            yield return(new ProjectInstanceFactory[]
            {
                (f, xml, c) => new Project(f, null, null, c).CreateProjectInstance()
            });

            // from DeepCopy
            yield return(new ProjectInstanceFactory[]
            {
                (f, xml, c) => new ProjectInstance(f, null, null, c).DeepCopy()
            });

            // from ProjectRootElement (new)
            yield return(new ProjectInstanceFactory[]
            {
                (f, xml, c) => new ProjectInstance(xml, null, null, c)
            });

            // from ProjectRootElement (factory method)
            yield return(new ProjectInstanceFactory[]
            {
                (f, xml, c) => ProjectInstance.FromProjectRootElement(xml, new ProjectOptions {
                    ProjectCollection = c
                })
            });

            // from translated project instance
            yield return(new ProjectInstanceFactory[]
            {
                (f, xml, c) =>
                {
                    var pi = new ProjectInstance(f, null, null, c);
                    pi.AddItem("foo", "bar");
                    pi.TranslateEntireState = true;

                    ((ITranslatable)pi).Translate(TranslationHelpers.GetWriteTranslator());
                    var copy = ProjectInstance.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

                    return copy;
                }
            });
        }
Ejemplo n.º 2
0
        public void ProjectInstanceCanSerializeEntireStateViaTranslator(string projectContents)
        {
            projectContents = string.Format(projectContents, MSBuildConstants.CurrentToolsVersion);

            var original = new ProjectInstance(ProjectRootElement.Create(XmlReader.Create(new StringReader(ObjectModelHelpers.CleanupFileContents(projectContents)))));

            original.TranslateEntireState = true;

            ((INodePacketTranslatable)original).Translate(TranslationHelpers.GetWriteTranslator());
            var copy = ProjectInstance.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

            Assert.Equal(original, copy, new ProjectInstanceComparer());
        }