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); }
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); }