2 // MonoTests.System.Runtime.Remoting.BaseCalls.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2003 (C) Copyright, Novell, Inc.
10 using System
.Threading
;
11 using System
.Collections
;
12 using System
.Runtime
.Remoting
;
13 using System
.Runtime
.Remoting
.Activation
;
14 using System
.Runtime
.Remoting
.Contexts
;
15 using NUnit
.Framework
;
17 namespace MonoTests
.System
.Runtime
.Remoting
20 public class NeedsContextAttribute
: Attribute
, IContextAttribute
22 public void GetPropertiesForNewContext (IConstructionCallMessage msg
) {}
23 public bool IsContextOK (Context ctx
, IConstructionCallMessage msg
) { return false; }
26 [NeedsContextAttribute
]
27 public class TestCbo
: ContextBoundObject
29 public Context
GetContext ()
31 return Thread
.CurrentContext
;
36 public class ContextTest
38 TestCbo cbo
= new TestCbo ();
40 LocalDataStoreSlot slot
;
43 public void TestDoCallback ()
45 otherCtx
= cbo
.GetContext ();
46 Assert
.IsTrue (Thread
.CurrentContext
!= otherCtx
, "New context not created");
48 otherCtx
.DoCallBack (new CrossContextDelegate (DelegateTarget
));
51 void DelegateTarget ()
53 Assert
.IsTrue (Thread
.CurrentContext
== otherCtx
, "Wrong context");
57 public void TestDatastore ()
59 otherCtx
= cbo
.GetContext ();
61 slot
= Context
.AllocateDataSlot ();
62 LocalDataStoreSlot namedSlot1
= Context
.AllocateNamedDataSlot ("slot1");
63 LocalDataStoreSlot namedSlot2
= Context
.GetNamedDataSlot ("slot2");
65 Context
.SetData (slot
, "data");
66 Context
.SetData (namedSlot1
, "data1");
67 Context
.SetData (namedSlot2
, "data2");
69 otherCtx
.DoCallBack (new CrossContextDelegate (CheckOtherContextDatastore
));
71 Assert
.IsTrue (Context
.GetData (slot
).Equals ("data"), "Wrong data 1");
72 Assert
.IsTrue (Context
.GetData (namedSlot1
).Equals ("data1"), "Wrong data 2");
73 Assert
.IsTrue (Context
.GetData (namedSlot2
).Equals ("data2"), "Wrong data 3");
77 namedSlot1
= Context
.AllocateNamedDataSlot ("slot1");
78 Assert
.Fail ("Exception expected");
82 Context
.FreeNamedDataSlot ("slot1");
83 Context
.FreeNamedDataSlot ("slot2");
87 namedSlot1
= Context
.AllocateNamedDataSlot ("slot1");
91 Assert
.Fail ("Exception not expected");
94 Context
.FreeNamedDataSlot ("slot1");
97 void CheckOtherContextDatastore ()
99 LocalDataStoreSlot namedSlot1
= Context
.GetNamedDataSlot ("slot1");
100 LocalDataStoreSlot namedSlot2
= Context
.GetNamedDataSlot ("slot2");
102 Assert
.IsTrue (Context
.GetData (slot
) == null, "Slot already has data");
103 Assert
.IsTrue (Context
.GetData (namedSlot1
) == null, "Slot already has data");
104 Assert
.IsTrue (Context
.GetData (namedSlot2
) == null, "Slot already has data");
106 Context
.SetData (slot
, "other data");
107 Context
.SetData (namedSlot1
, "other data1");
108 Context
.SetData (namedSlot2
, "other data2");