Testdriven Remoting in C # - Do I need a separate AppDomain server?

I wanted to start by using Remoting under C # in testdriven, but I'm stuck.

One thing I found on this topic is the article in Marc Clifton's article , but it seems to be working on the server, manually starting it from the console.

I am trying to start a server (i.e. register a class of service) in a test device. I probably also use the interface incorrectly, but this will happen later.

I always get an exception (sorry for the German post) that the channel is already registered. System.Runtime.Remoting.RemotingException: Der Channel tcp wurde bereits registriert.

After commenting out the ChannelServices.RegisterChannell () line in the test method, this happens to call Activator.GetObject ().

I tried putting StartServer () on the stream, but that didn't help either. I found that creating a new AppDomain might be possible, but have not tried it yet.

Can you tell me if my approach is inherently wrong? How can i fix this?

using System; using NUnit.Framework; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace Bla.Tests.Remote { [TestFixture] public class VerySimpleProxyTest { int port = 8082; string proxyUri = "MyRemoteProxy"; string host = "localhost"; IChannel channel; [SetUp] public void SetUp() { StartServer(); } [TearDown] public void TearDown() { StopServer(); } [Test] public void UseRemoteService() { //IChannel clientChannel = new TcpClientChannel(); //ChannelServices.RegisterChannel(clientChannel, false); string uri = String.Format("tcp://{0}:{1}/{2}", host, port, proxyUri); IMyTestService remoteService = (IMyTestService)Activator.GetObject(typeof(IMyTestService), uri); Assert.IsTrue(remoteService.Ping()); //ChannelServices.UnregisterChannel(clientChannel); } private void StartServer() { channel = new TcpServerChannel(port); ChannelServices.RegisterChannel(channel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyTestService), proxyUri, WellKnownObjectMode.Singleton); } private void StopServer() { ChannelServices.UnregisterChannel(channel); } } public interface IMyTestService { bool Ping(); } public class MyTestService : MarshalByRefObject, IMyTestService { public bool Ping() { return true; } } } 
+3
source share
2 answers

I have no solution to your problem, but my advice would be, and not to write unit tests this way. See post . What code do you really want to check here. I'm sure Microsoft has done a lot of testing of the Remoting feature that comes with .net. The class that implements your Service Interface can be checked by the module in the process only by updating the implementation. The code that registers your service interface could be checked if the .net infrastructure did not use statics for the registration bit, but alas. You could try passing the IChannel mockup to ChannelServices.RegisterChannel and somehow check your registration code this way, but in my version it would be a waste of time.

I would just like to say that testing should be a means to an end, but not an end in itself.

+1
source

I found a great way to do exactly what I wanted to do, just using WCF instead of Remoting.

I have ported the source code given in Yair Cohen's article on NUnit in less than 5 minutes, and it works out of the box.

0
source

All Articles