Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono-addins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Test/UnitTests/TestEvents.cs')
-rw-r--r--Test/UnitTests/TestEvents.cs86
1 files changed, 85 insertions, 1 deletions
diff --git a/Test/UnitTests/TestEvents.cs b/Test/UnitTests/TestEvents.cs
index 2b4b988..69fce20 100644
--- a/Test/UnitTests/TestEvents.cs
+++ b/Test/UnitTests/TestEvents.cs
@@ -479,5 +479,89 @@ namespace UnitTests
private void ExtensionNode_ExtensionNodeChanged (object sender, ExtensionNodeEventArgs args)
{
}
- }
+
+ [Test]
+ public void TestSubscriptionWithinHandler()
+ {
+ nestedEventSubscriptionSet = false;
+ nestedEventSubscriptionHandled = false;
+ try
+ {
+ AddinManager.AddExtensionNodeHandler("/SimpleApp/Writers", OnExtensionChange3);
+ }
+ finally
+ {
+ AddinManager.RemoveExtensionNodeHandler("/SimpleApp/Writers", OnExtensionChange3);
+ AddinManager.RemoveExtensionNodeHandler("/SystemInformation/Modules", OnExtensionChange4);
+ }
+ }
+
+ bool nestedEventSubscriptionSet;
+ bool nestedEventSubscriptionHandled;
+
+ void OnExtensionChange3(object s, ExtensionNodeEventArgs args)
+ {
+ if (args.Change == ExtensionChange.Add)
+ {
+ if (!nestedEventSubscriptionSet)
+ {
+ nestedEventSubscriptionSet = true;
+
+ // The OnExtensionChange4 handler should be invoked immediately for existing nodes.
+ AddinManager.AddExtensionNodeHandler("/SystemInformation/Modules", OnExtensionChange4);
+ Assert.IsTrue(nestedEventSubscriptionHandled);
+ }
+ }
+ }
+
+ void OnExtensionChange4(object s, ExtensionNodeEventArgs args)
+ {
+ nestedEventSubscriptionHandled = true;
+ }
+
+ int conditionedWriterCount = 0;
+
+ [Test]
+ public void TestSubscriptionWithinHandler2()
+ {
+ try
+ {
+ AddinManager.GetExtensionNodes("/SimpleApp/ConditionedWriters");
+ nestedEventSubscriptionSet = false;
+ GlobalInfoCondition.Value = "";
+
+ AddinManager.ExtensionChanged += ExtensionChanged6;
+
+ AddinManager.Registry.DisableAddin("SimpleApp.FileContentExtension,0.1.0");
+
+ Assert.AreEqual(1, conditionedWriterCount);
+ }
+ finally
+ {
+ AddinManager.Registry.EnableAddin("SimpleApp.FileContentExtension,0.1.0");
+ }
+ }
+
+ private void ExtensionChanged6 (object sender, ExtensionEventArgs args)
+ {
+ if (nestedEventSubscriptionSet)
+ return;
+
+ nestedEventSubscriptionSet = true;
+
+ GlobalInfoCondition.Value = "foo";
+
+ nestedEventSubscriptionSet = true;
+ AddinManager.AddExtensionNodeHandler("/SimpleApp/ConditionedWriters", OnConditionedWritersChanged);
+ Assert.AreEqual(1, conditionedWriterCount);
+ }
+
+ void OnConditionedWritersChanged(object s, ExtensionNodeEventArgs args)
+ {
+ if (args.Change == ExtensionChange.Add)
+ conditionedWriterCount++;
+ else
+ conditionedWriterCount--;
+ }
+ }
}