Пример #1
0
        public void TestPluginRequirementCollectionEnumerable()
        {
            Guid guid0 = Guid.NewGuid();
            Guid guid1 = Guid.NewGuid();
            Guid guid2 = Guid.NewGuid();

            IPluginRequirementCollection reqs = new PluginRequirementCollection( );

            PluginRequirement req0 = reqs.AddOrSet(guid0, RunningRequirement.MustExistAndRun);

            Assert.That(reqs.Count == 1);

            PluginRequirement req1 = reqs.AddOrSet(guid1, RunningRequirement.Optional);

            Assert.That(reqs.Count == 2);

            PluginRequirement req2 = reqs.AddOrSet(guid2, RunningRequirement.OptionalTryStart);

            Assert.That(reqs.Count == 3);

            Assert.That(reqs.Contains(req2) && reqs.Contains(req1) && reqs.Contains(req0));

            reqs.Remove(guid2);

            Assert.That(reqs.Count == 2);
            Assert.That(!reqs.Contains(req2));

            int passed = 0;

            foreach (PluginRequirement o in reqs)
            {
                if (o.PluginId == guid0)
                {
                    Assert.That(o.Requirement == RunningRequirement.MustExistAndRun);
                    passed++;
                }
                if (o.PluginId == guid1)
                {
                    Assert.That(o.Requirement == RunningRequirement.Optional);
                    passed++;
                }
            }
            Assert.That(passed, Is.EqualTo(2));

            reqs.Clear();

            Assert.That(reqs.Count == 0);
            Assert.That(((PluginRequirement)req0).Holder == null);
            Assert.That(((PluginRequirement)req1).Holder == null);
            Assert.That(((PluginRequirement)req2).Holder == null);

            passed = 0;
            foreach (PluginRequirement o in reqs)
            {
                passed++;
            }
            Assert.That(passed == 0);
        }
Пример #2
0
        void PluginRequirementCollectionEvents(PluginRequirementCollection collection)
        {
            Guid id = Guid.NewGuid();

            PluginRequirementCollectionChangingEventArgs lastChanging = null;
            PluginRequirementCollectionChangedEventArgs  lastChanged  = null;
            int changingCount = 0;
            int changedCount  = 0;

            collection.Changing += (o, e) => { lastChanging = e; changingCount++; };
            collection.Changed  += (o, e) => { lastChanged = e; changedCount++; };

            // Check add
            PluginRequirement req = collection.AddOrSet(id, RunningRequirement.MustExistAndRun);

            Assert.That(changedCount == 1 && changingCount == 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 == id);
            Assert.That(lastChanged.PluginId == id);
            Assert.That(lastChanging.Requirement == RunningRequirement.MustExistAndRun);
            Assert.That(lastChanged.Requirement == RunningRequirement.MustExistAndRun);

            changedCount = 0; changingCount = 0;

            // Check delete : from the collection
            collection.Remove(id);

            Assert.That(changedCount == 1 && changingCount == 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 == id);
            Assert.That(lastChanged.PluginId == id);
            Assert.That(lastChanging.Requirement == RunningRequirement.MustExistAndRun);
            Assert.That(lastChanged.Requirement == RunningRequirement.MustExistAndRun);

            changedCount = 0; changingCount = 0;

            // Check clear
            collection.Clear();

            Assert.That(changedCount == 1 && changingCount == 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.Requirement == 0);
            Assert.That(lastChanged.Requirement == 0);
        }
Пример #3
0
        public void TestPluginRequirementCollectionUpdate()
        {
            bool updated = false;
            Guid guid1   = Guid.NewGuid();
            Guid guid2   = Guid.NewGuid();
            Guid guid3   = Guid.NewGuid();

            IPluginRequirementCollection reqs = new PluginRequirementCollection( );

            reqs.Changed += (o, e) => { if (e.Action == CK.Core.ChangeStatus.Update)
                                        {
                                            updated = true;
                                        }
            };

            PluginRequirement req = reqs.AddOrSet(guid1, RunningRequirement.MustExistAndRun);

            Assert.That(reqs.Count == 1);
            //Assert.That( (req.Source == reqs.Source) && (reqs.Source == ctx) );

            PluginRequirement req1 = reqs.AddOrSet(guid2, RunningRequirement.MustExistAndRun);

            Assert.That(reqs.Count == 2);

            PluginRequirement req2 = reqs.AddOrSet(guid3, RunningRequirement.MustExistAndRun);

            Assert.That(reqs.Count == 3);

            Assert.That(reqs.Contains(req2) && reqs.Contains(req1) && reqs.Contains(req));

            PluginRequirement req3 = reqs.AddOrSet(guid3, RunningRequirement.Optional);

            Assert.That(updated);
            Assert.That(req2 == req3);
            Assert.That(reqs.Count == 3);
        }
Пример #4
0
        public void TestPluginRequirementCollectionEvents()
        {
            int createdEventFired = 0;
            int removedEventFired = 0;
            int updatedEventFired = 0;
            int clearedEventFired = 0;

            int creatingEventFired = 0;
            int removingEventFired = 0;
            int updatingEventFired = 0;
            int clearingEventFired = 0;

            bool cancel = false;

            Guid changingPluginId = Guid.Empty;
            RunningRequirement previousRequirement    = RunningRequirement.OptionalTryStart;
            RunningRequirement newRequirement         = RunningRequirement.OptionalTryStart;
            PluginRequirement  lastRequirementCreated = null;
            PluginRequirement  lastRequirementRemoved = null;

            IPluginRequirementCollection reqs = new PluginRequirementCollection();

            reqs.Changing += (sender, args) =>
            {
                switch (args.Action)
                {
                case CK.Core.ChangeStatus.Update:
                    updatingEventFired++;
                    if (!cancel)
                    {
                        previousRequirement = args.Collection.Find(args.PluginId).Requirement;
                    }
                    break;

                case CK.Core.ChangeStatus.Add:
                    creatingEventFired++;
                    break;

                case CK.Core.ChangeStatus.Delete:
                    removingEventFired++;
                    break;

                case CK.Core.ChangeStatus.ContainerClear:
                    clearingEventFired++;
                    break;
                }
                if (cancel)
                {
                    args.Cancel = true;
                }
            };

            reqs.Changed += (sender, args) =>
            {
                switch (args.Action)
                {
                case CK.Core.ChangeStatus.Update:
                    updatedEventFired++;
                    newRequirement = args.Requirement;
                    break;

                case CK.Core.ChangeStatus.Add:
                    lastRequirementCreated = args.Collection.Find(args.PluginId);
                    createdEventFired++;
                    break;

                case CK.Core.ChangeStatus.Delete:
                    lastRequirementRemoved = args.Collection.Find(args.PluginId);
                    removedEventFired++;
                    break;

                case CK.Core.ChangeStatus.ContainerClear:
                    clearedEventFired++;
                    break;
                }
            };

            PluginRequirement req = reqs.AddOrSet(Guid.NewGuid(), RunningRequirement.MustExistAndRun);

            Assert.That(lastRequirementCreated == req);
            Assert.That(createdEventFired == 1);
            Assert.That(creatingEventFired == 1);

            PluginRequirement req1 = reqs.AddOrSet(Guid.NewGuid(), RunningRequirement.MustExistAndRun);

            Assert.That(lastRequirementCreated == req1);
            Assert.That(createdEventFired == 2);
            Assert.That(creatingEventFired == 2);

            PluginRequirement req2 = reqs.AddOrSet(Guid.NewGuid(), RunningRequirement.MustExistAndRun);

            Assert.That(lastRequirementCreated == req2);
            Assert.That(createdEventFired == 3);
            Assert.That(creatingEventFired == 3);

            reqs.AddOrSet(req2.PluginId, RunningRequirement.MustExist);

            Assert.That(previousRequirement == RunningRequirement.MustExistAndRun);
            Assert.That(newRequirement == RunningRequirement.MustExist);
            Assert.That(updatingEventFired == 1);
            Assert.That(updatedEventFired == 1);

            // Now, cancel is true, nothing should be done
            cancel = true;
            reqs.AddOrSet(req2.PluginId, RunningRequirement.Optional);

            Assert.That(previousRequirement == RunningRequirement.MustExistAndRun);
            Assert.That(newRequirement == RunningRequirement.MustExist);
            Assert.That(updatingEventFired == 2);
            Assert.That(updatedEventFired == 1);

            cancel = false;

            reqs.Clear();

            Assert.That(clearedEventFired, Is.EqualTo(1));
        }