public void ProjectInstanceShouldRespectSharingPolicy(EvaluationContext.SharingPolicy policy) { try { var seenContexts = new HashSet <EvaluationContext>(); EvaluationContext.TestOnlyHookOnCreate = c => seenContexts.Add(c); var collection = _env.CreateProjectCollection().Collection; var context = EvaluationContext.Create(policy); const int numIterations = 10; for (int i = 0; i < numIterations; i++) { ProjectInstance.FromProjectRootElement( ProjectRootElement.Create(), new ProjectOptions { ProjectCollection = collection, EvaluationContext = context, LoadSettings = ProjectLoadSettings.IgnoreMissingImports }); } int expectedNumContexts = policy == EvaluationContext.SharingPolicy.Shared ? 1 : numIterations; seenContexts.Count.ShouldBe(expectedNumContexts); seenContexts.ShouldAllBe(c => c.Policy == policy); } finally { EvaluationContext.TestOnlyHookOnCreate = null; } }
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; } }); }
public static ProjectInstance ProjectInstanceFromXml(string xml) { var settings = new XmlReaderSettings { XmlResolver = null, // Prevent external calls for namespaces. }; using (var stringReader = new StringReader(xml)) using (var xmlReader = XmlReader.Create(stringReader, settings)) { ProjectRootElement projectRootElement = ProjectRootElement.Create(xmlReader); return(ProjectInstance.FromProjectRootElement(projectRootElement, new ProjectOptions())); } }
public static ProjectInstance CreateProjectInstanceFromRootElement(ProjectRootElement projectRootElement) { // Use a new project collection to avoid collisions in the global one. // TODO! Refactor tests to be more isolated, both ProjectCollection-wide and disk-wise var projectCollection = new ProjectCollection(); var projectOptions = new ProjectOptions { GlobalProperties = _globalProperties, ProjectCollection = projectCollection, }; return(ProjectInstance.FromProjectRootElement(projectRootElement, projectOptions)); }