public void PluginStatusCollectionEvents()
        {
            var ctx = MiniContext.CreateMiniContext( "PluginStatusCollectionEvents" );

            PluginStatusCollectionChangingEventArgs lastChanging = null;
            PluginStatusCollectionChangedEventArgs lastChanged = null;
            int changingCount = 0;
            int changedCount = 0;

            PluginStatusCollection collection = new PluginStatusCollection( ctx.ConfigManager.SystemConfiguration as SystemConfiguration );
            collection.Changing += ( o, e ) => { lastChanging = e; changingCount++; };
            collection.Changed += ( o, e ) => { lastChanged = e; changedCount++; };

            // check add
            collection.SetStatus( Guid.Empty, ConfigPluginStatus.Manual );

            Assert.That( changingCount == 1 && changedCount == 1 );
            Assert.That( lastChanging.Action == CK.Core.ChangeStatus.Add );
            Assert.That( lastChanged.Action == CK.Core.ChangeStatus.Add );
            Assert.That( lastChanging.Collection == collection );
            Assert.That( lastChanged.Collection == collection );
            Assert.That( lastChanging.PluginID == Guid.Empty );
            Assert.That( lastChanged.PluginID == Guid.Empty );
            Assert.That( lastChanging.Status == ConfigPluginStatus.Manual );
            Assert.That( lastChanged.Status == ConfigPluginStatus.Manual );

            changedCount = 0; changingCount = 0;

            // check update
            collection.SetStatus( Guid.Empty, ConfigPluginStatus.Disabled );

            Assert.That( changingCount == 1 && changedCount == 1 );
            Assert.That( lastChanging.Action == CK.Core.ChangeStatus.Update );
            Assert.That( lastChanged.Action == CK.Core.ChangeStatus.Update );
            Assert.That( lastChanging.Collection == collection );
            Assert.That( lastChanged.Collection == collection );
            Assert.That( lastChanging.PluginID == Guid.Empty );
            Assert.That( lastChanged.PluginID == Guid.Empty );
            Assert.That( lastChanging.Status == ConfigPluginStatus.Disabled );
            Assert.That( lastChanged.Status == ConfigPluginStatus.Disabled );

            changedCount = 0; changingCount = 0;

            // check delete
            IPluginStatus status = collection.GetPluginStatus( Guid.Empty );
            status.Destroy();

            Assert.That( changingCount == 1 && changedCount == 1 );
            Assert.That( lastChanging.Action == CK.Core.ChangeStatus.Delete );
            Assert.That( lastChanged.Action == CK.Core.ChangeStatus.Delete );
            Assert.That( lastChanging.Collection == collection );
            Assert.That( lastChanged.Collection == collection );
            Assert.That( lastChanging.PluginID == Guid.Empty );
            Assert.That( lastChanged.PluginID == Guid.Empty );
            Assert.That( lastChanging.Status == ConfigPluginStatus.Disabled );
            Assert.That( lastChanged.Status == ConfigPluginStatus.Disabled );

            changedCount = 0; changingCount = 0;

            // check clear
            collection.Clear();

            Assert.That( changingCount == 1 && changedCount == 1 );
            Assert.That( lastChanging.Action == CK.Core.ChangeStatus.ContainerClear );
            Assert.That( lastChanged.Action == CK.Core.ChangeStatus.ContainerClear );
            Assert.That( lastChanging.Collection == collection );
            Assert.That( lastChanged.Collection == collection );
            Assert.That( lastChanging.PluginID == Guid.Empty );
            Assert.That( lastChanged.PluginID == Guid.Empty );
            Assert.That( lastChanging.Status == 0 );
            Assert.That( lastChanged.Status == 0 );
        }
        public void PluginStatusCollectionMerge()
        {
            Guid id1 = Guid.NewGuid();
            Guid id2 = Guid.NewGuid();
            Guid id3 = Guid.NewGuid();

            var ctx = MiniContext.CreateMiniContext( "PluginStatusCollectionMerge" );

            PluginStatusCollection collection = new PluginStatusCollection( ctx.ConfigManager.SystemConfiguration as SystemConfiguration );

            collection.SetStatus( id1, ConfigPluginStatus.Manual );

            string path = TestBase.GetTestFilePath( "PluginStatusCollectionMerge" );
            using( Stream s = new FileStream( path, FileMode.Create ) )
            {
                using( var w = SimpleStructuredWriter.CreateWriter( s, null ) )
                {
                    PluginStatusCollection collection2 = new PluginStatusCollection( ctx.ConfigManager.SystemConfiguration as SystemConfiguration );
                    collection2.SetStatus( id1, ConfigPluginStatus.Disabled );
                    collection2.SetStatus( id2, ConfigPluginStatus.Disabled );
                    collection2.SetStatus( id3, ConfigPluginStatus.AutomaticStart );
                    w.WriteInlineObjectStructuredElement( "PC", collection2 );
                }
            }

            int changingCount = 0, changedCount = 0;
            PluginStatusCollectionChangingEventArgs lastChanging = null;
            PluginStatusCollectionChangedEventArgs lastChanged = null;
            collection.Changing += ( o, e ) => { lastChanging = e; changingCount++; };
            collection.Changed += ( o, e ) => 
            { 
                lastChanged = e; changedCount++; 
            };

            using( Stream s = new FileStream( path, FileMode.Open ) )
            {
                using( var r = SimpleStructuredReader.CreateReader( s, null ) )
                {
                    r.ReadInlineObjectStructuredElement( "PC", collection );
                }
            }

            // Check event count & args 
            Assert.That( changingCount == 0 && changedCount == 1 );
            Assert.That( lastChanging == null );
            Assert.That( lastChanged.Action == CK.Core.ChangeStatus.ContainerUpdate );
            Assert.That( lastChanged.Collection == collection );
            Assert.That( lastChanged.PluginID == Guid.Empty );
            Assert.That( lastChanged.Status == 0 );

            // Check content
            Assert.That( collection.Count == 3 );
            Assert.That( collection.GetStatus( id1, ConfigPluginStatus.Manual ) == ConfigPluginStatus.Disabled );
            Assert.That( collection.GetStatus( id2, ConfigPluginStatus.Manual ) == ConfigPluginStatus.Disabled );
            Assert.That( collection.GetStatus( id3, ConfigPluginStatus.Manual ) == ConfigPluginStatus.AutomaticStart );
        }