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 ContextText
: Assertion
38 TestCbo cbo
= new TestCbo ();
40 LocalDataStoreSlot slot
;
43 public void TestDoCallback ()
45 otherCtx
= cbo
.GetContext ();
46 Assert ("New context not created", Thread
.CurrentContext
!= otherCtx
);
48 otherCtx
.DoCallBack (new CrossContextDelegate (DelegateTarget
));
51 void DelegateTarget ()
53 Assert ("Wrong context", Thread
.CurrentContext
== otherCtx
);
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 ("Wrong data 1", Context
.GetData (slot
).Equals ("data"));
72 Assert ("Wrong data 2", Context
.GetData (namedSlot1
).Equals ("data1"));
73 Assert ("Wrong data 3", Context
.GetData (namedSlot2
).Equals ("data2"));
77 namedSlot1
= Context
.AllocateNamedDataSlot ("slot1");
78 Assert ("Exception expected",false);
82 Context
.FreeNamedDataSlot ("slot1");
83 Context
.FreeNamedDataSlot ("slot2");
87 namedSlot1
= Context
.AllocateNamedDataSlot ("slot1");
91 Assert ("Exception not expected",false);
94 Context
.FreeNamedDataSlot ("slot1");
97 void CheckOtherContextDatastore ()
99 LocalDataStoreSlot namedSlot1
= Context
.GetNamedDataSlot ("slot1");
100 LocalDataStoreSlot namedSlot2
= Context
.GetNamedDataSlot ("slot2");
102 Assert ("Slot already has data", Context
.GetData (slot
) == null);
103 Assert ("Slot already has data", Context
.GetData (namedSlot1
) == null);
104 Assert ("Slot already has data", Context
.GetData (namedSlot2
) == null);
106 Context
.SetData (slot
, "other data");
107 Context
.SetData (namedSlot1
, "other data1");
108 Context
.SetData (namedSlot2
, "other data2");