public void RemovingGlobalPropertiesOnCollectionUpdatesProjects2()
        {
            ProjectCollection collection = new ProjectCollection();
            collection.SetGlobalProperty("g1", "v1");

            Project project1 = new Project(collection);
            project1.FullPath = "c:\\y"; // load into collection
            project1.SetGlobalProperty("g1", "v0"); // mask collection property
            Helpers.ClearDirtyFlag(project1.Xml);

            collection.RemoveGlobalProperty("g1"); // should modify the project

            Assert.Equal(0, project1.GlobalProperties.Count);
            Assert.Equal(true, project1.IsDirty);
        }
        public void SettingGlobalPropertiesOnCollectionUpdatesProjects()
        {
            ProjectCollection collection = new ProjectCollection();
            Project project1 = new Project(collection);
            project1.FullPath = "c:\\y"; // load into collection
            Assert.Equal(0, project1.GlobalProperties.Count);

            collection.SetGlobalProperty("g1", "v1");
            collection.SetGlobalProperty("g2", "v2");
            collection.SetGlobalProperty("g2", "v2"); // try dupe

            Assert.Equal(2, project1.GlobalProperties.Count);

            collection.RemoveGlobalProperty("g2");
            Project project2 = new Project(collection);
            project2.FullPath = "c:\\x"; // load into collection

            Assert.Equal(1, project1.GlobalProperties.Count);
            Assert.Equal("v1", project2.GlobalProperties["g1"]);

            Assert.Equal(1, project2.GlobalProperties.Count);
            Assert.Equal("v1", project2.GlobalProperties["g1"]);
        }
        public void RemovingGlobalPropertiesOnCollectionUpdatesProjects()
        {
            ProjectCollection collection = new ProjectCollection();
            Project project1 = new Project(collection);
            project1.FullPath = "c:\\y"; // load into collection
            Assert.Equal(0, project1.GlobalProperties.Count);

            Helpers.ClearDirtyFlag(project1.Xml);

            collection.SetGlobalProperty("g1", "v1"); // should make both dirty
            collection.SetGlobalProperty("g2", "v2"); // should make both dirty

            Assert.Equal(true, project1.IsDirty);

            Project project2 = new Project(collection);
            project2.FullPath = "c:\\x"; // load into collection

            Assert.Equal(true, project2.IsDirty);

            Assert.Equal(2, project1.GlobalProperties.Count);
            Assert.Equal("v1", project2.GlobalProperties["g1"]);

            Assert.Equal(2, project2.GlobalProperties.Count);
            Assert.Equal("v1", project2.GlobalProperties["g1"]);

            Helpers.ClearDirtyFlag(project1.Xml);
            Helpers.ClearDirtyFlag(project2.Xml);

            collection.RemoveGlobalProperty("g2"); // should make both dirty

            Assert.Equal(true, project1.IsDirty);
            Assert.Equal(true, project2.IsDirty);

            Assert.Equal(1, project1.GlobalProperties.Count);
            Assert.Equal(1, project2.GlobalProperties.Count);

            collection.RemoveGlobalProperty("g1");

            Assert.Equal(0, project1.GlobalProperties.Count);
            Assert.Equal(0, project2.GlobalProperties.Count);
        }
        public void ProjectCollectionChangedEvent()
        {
            ProjectCollection collection = new ProjectCollection();
            bool dirtyRaised = false;
            ProjectCollectionChangedState expectedChange = ProjectCollectionChangedState.Loggers;
            collection.ProjectCollectionChanged +=
                (sender, e) =>
                {
                    Assert.Same(collection, sender);
                    Assert.Equal(expectedChange, e.Changed);
                    dirtyRaised = true;
                };
            Assert.False(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.DisableMarkDirty;
            dirtyRaised = false;
            collection.DisableMarkDirty = true; // LEAVE THIS TRUE for rest of the test, to verify it doesn't suppress these events
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.IsBuildEnabled;
            dirtyRaised = false;
            collection.IsBuildEnabled = !collection.IsBuildEnabled;
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.OnlyLogCriticalEvents;
            dirtyRaised = false;
            collection.OnlyLogCriticalEvents = !collection.OnlyLogCriticalEvents;
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.SkipEvaluation;
            dirtyRaised = false;
            collection.SkipEvaluation = !collection.SkipEvaluation;
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.GlobalProperties;
            dirtyRaised = false;
            collection.SetGlobalProperty("a", "b");
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.GlobalProperties;
            dirtyRaised = false;
            collection.RemoveGlobalProperty("a");
            Assert.True(dirtyRaised);

            // Verify HostServices changes raise the event.
            expectedChange = ProjectCollectionChangedState.HostServices;
            dirtyRaised = false;
            collection.HostServices = new Execution.HostServices();
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.Loggers;
            dirtyRaised = false;
            collection.RegisterLogger(new MockLogger());
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.Loggers;
            dirtyRaised = false;
            collection.RegisterLoggers(new Microsoft.Build.Framework.ILogger[] { new MockLogger(), new MockLogger() });
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.Loggers;
            dirtyRaised = false;
            collection.UnregisterAllLoggers();
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.Toolsets;
            dirtyRaised = false;
            collection.AddToolset(new Toolset("testTools", Path.GetTempPath(), collection, Path.GetTempPath()));
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.DefaultToolsVersion;
            dirtyRaised = false;
            collection.DefaultToolsVersion = "testTools";
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.Toolsets;
            dirtyRaised = false;
            collection.RemoveToolset("testTools");
            Assert.True(dirtyRaised);

            expectedChange = ProjectCollectionChangedState.Toolsets;
            dirtyRaised = false;
            collection.RemoveAllToolsets();
            Assert.True(dirtyRaised);
        }