Added ifdef DOTNET35
[castle.git] / InversionOfControl / Castle.MicroKernel.Tests / SerializationTestCase.cs
blob4c254fc2d8d02396855c2edcb6a8fbeca1db14d7
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.IO;
19 using System.Runtime.Serialization.Formatters.Binary;
20 using System.Security.Policy;
21 using Castle.Core;
22 using Castle.MicroKernel.Tests.ClassComponents;
23 using NUnit.Framework;
25 [TestFixture]
26 public class SerializationTestCase
28 [Test]
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);
41 stream.Position = 0;
43 IKernel desKernel = (IKernel) formatter.Deserialize(stream);
44 Assert.IsTrue(desKernel.HasComponent("key"));
47 [Test]
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);
56 try
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"));
65 catch(Exception ex)
67 throw ex;
69 finally
71 AppDomain.Unload(otherDomain);
75 [Test]
76 #if MONO2
77 [Ignore(@"problem running on mono 2.0 profile")]
78 #endif
79 public void RemoteAccessToComponentGraph()
81 AppDomain current = AppDomain.CurrentDomain;
83 AppDomain otherDomain = AppDomain.CreateDomain(
84 "other", new Evidence(current.Evidence), current.SetupInformation);
86 try
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);
100 catch(Exception ex)
102 throw ex;
104 finally
106 AppDomain.Unload(otherDomain);