1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MicroKernel
.Tests
19 using System
.Runtime
.Serialization
.Formatters
.Binary
;
20 using System
.Security
.Policy
;
22 using Castle
.MicroKernel
.Tests
.ClassComponents
;
23 using NUnit
.Framework
;
26 public class SerializationTestCase
29 [Ignore("For some reason the deserialization of kernel members is resulting in null values")]
30 public void KernelSerialization()
32 IKernel kernel
= new DefaultKernel();
33 kernel
.AddComponent("key", typeof(CustomerImpl
));
34 Assert
.IsTrue(kernel
.HasComponent("key"));
36 MemoryStream stream
= new MemoryStream();
37 BinaryFormatter formatter
= new BinaryFormatter();
39 formatter
.Serialize(stream
, kernel
);
43 IKernel desKernel
= (IKernel
) formatter
.Deserialize(stream
);
44 Assert
.IsTrue(desKernel
.HasComponent("key"));
48 [Ignore("To compile on Mono")]
49 public void RemoteAccess()
51 AppDomain current
= AppDomain
.CurrentDomain
;
53 AppDomain otherDomain
= AppDomain
.CreateDomain(
54 "other", new Evidence(current
.Evidence
), current
.SetupInformation
);
58 IKernel kernel
= (IKernel
)
59 otherDomain
.CreateInstanceAndUnwrap(
60 "Castle.MicroKernel", "Castle.MicroKernel.DefaultKernel");
62 kernel
.AddComponent("key", typeof(CustomerImpl
));
63 Assert
.IsTrue(kernel
.HasComponent("key"));
71 AppDomain
.Unload(otherDomain
);
77 [Ignore(@"problem running on mono 2.0 profile")]
79 public void RemoteAccessToComponentGraph()
81 AppDomain current
= AppDomain
.CurrentDomain
;
83 AppDomain otherDomain
= AppDomain
.CreateDomain(
84 "other", new Evidence(current
.Evidence
), current
.SetupInformation
);
88 IKernel kernel
= (IKernel
)
89 otherDomain
.CreateInstanceAndUnwrap(
90 "Castle.MicroKernel", "Castle.MicroKernel.DefaultKernel");
92 kernel
.AddComponent("key", typeof(CustomerImpl
));
93 Assert
.IsTrue(kernel
.HasComponent("key"));
95 GraphNode
[] nodes
= kernel
.GraphNodes
;
97 Assert
.IsNotNull(nodes
);
98 Assert
.AreEqual(1, nodes
.Length
);
106 AppDomain
.Unload(otherDomain
);