2014-08-13 10:39:27 +01:00
//
// System.Runtime.Remoting.RemotingServices NUnit V2.0 test class
//
// Author Jean-Marc ANDRE (jean-marc.andre@polymtl.ca)
//
// ToDo: I didn't write test functions for the method not yep
// implemented by Mono
using System ;
using System.Collections ;
using NUnit.Framework ;
using System.Reflection ;
using System.Runtime.Remoting ;
using System.Threading ;
using System.Runtime.Remoting.Activation ;
using System.Runtime.Remoting.Messaging ;
using System.Runtime.Remoting.Proxies ;
using System.Runtime.Remoting.Channels ;
using System.Runtime.Remoting.Channels.Tcp ;
2017-10-19 20:04:20 +00:00
using MonoTests.Helpers ;
2014-08-13 10:39:27 +01:00
namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal
{
// We need our own proxy to intercept messages to remote object
// and forward them using RemotingServices.ExecuteMessage
public class MyProxy : RealProxy
{
MarshalByRefObject target ;
IMessageSink _sink ;
MethodBase _mthBase ;
bool methodOverloaded = false ;
public MethodBase MthBase {
get { return _mthBase ; }
}
public bool IsMethodOverloaded {
get { return methodOverloaded ; }
}
public MyProxy ( Type serverType , MarshalByRefObject target )
: base ( serverType )
{
this . target = target ;
IChannel [ ] registeredChannels = ChannelServices . RegisteredChannels ;
string ObjectURI ;
// A new IMessageSink chain has to be created
// since the RemotingServices.GetEnvoyChainForProxy() is not yet
// implemented.
foreach ( IChannel channel in registeredChannels ) {
IChannelSender channelSender = channel as IChannelSender ;
if ( channelSender ! = null ) {
_sink = ( IMessageSink ) channelSender . CreateMessageSink ( RemotingServices . GetObjectUri ( target ) , null , out ObjectURI ) ;
}
}
}
// Messages will be intercepted here and redirected
// to another object.
public override IMessage Invoke ( IMessage msg )
{
try {
if ( msg is IConstructionCallMessage ) {
IActivator remActivator = ( IActivator ) RemotingServices . Connect ( typeof ( IActivator ) , "tcp://localhost:1234/RemoteActivationService.rem" ) ;
IConstructionReturnMessage crm = remActivator . Activate ( ( IConstructionCallMessage ) msg ) ;
return crm ;
} else {
methodOverloaded = RemotingServices . IsMethodOverloaded ( ( IMethodMessage ) msg ) ;
_mthBase = RemotingServices . GetMethodBaseFromMethodMessage ( ( IMethodMessage ) msg ) ;
MethodCallMessageWrapper mcm = new MethodCallMessageWrapper ( ( IMethodCallMessage ) msg ) ;
mcm . Uri = RemotingServices . GetObjectUri ( ( MarshalByRefObject ) target ) ;
MarshalByRefObject objRem = ( MarshalByRefObject ) Activator . CreateInstance ( GetProxiedType ( ) ) ;
RemotingServices . ExecuteMessage ( ( MarshalByRefObject ) objRem , ( IMethodCallMessage ) msg ) ;
IMessage rtnMsg = null ;
try {
rtnMsg = _sink . SyncProcessMessage ( msg ) ;
} catch ( Exception e ) {
Console . WriteLine ( e . Message ) ;
}
Console . WriteLine ( "RR:" + rtnMsg ) ;
return rtnMsg ;
}
} catch ( Exception ex ) {
Console . WriteLine ( ex ) ;
return null ;
}
}
} // end MyProxy
// This class is used to create "CAO"
public class MarshalObjectFactory : MarshalByRefObject
{
public MarshalObject GetNewMarshalObject ( )
{
return new MarshalObject ( ) ;
}
}
// A class used by the tests
public class MarshalObject : ContextBoundObject
{
public MarshalObject ( )
{
}
public MarshalObject ( int id , string uri )
{
this . id = id ;
this . uri = uri ;
}
public int Id {
get { return id ; }
set { id = value ; }
}
public string Uri {
get { return uri ; }
}
public void Method1 ( )
{
_called + + ;
methodOneWay = RemotingServices . IsOneWay ( MethodBase . GetCurrentMethod ( ) ) ;
}
public void Method2 ( )
{
methodOneWay = RemotingServices . IsOneWay ( MethodBase . GetCurrentMethod ( ) ) ;
}
public void Method2 ( int i )
{
methodOneWay = RemotingServices . IsOneWay ( MethodBase . GetCurrentMethod ( ) ) ;
}
[OneWay ()]
public void Method3 ( )
{
methodOneWay = RemotingServices . IsOneWay ( MethodBase . GetCurrentMethod ( ) ) ;
}
public static int Called {
get { return _called ; }
}
public static bool IsMethodOneWay {
get { return methodOneWay ; }
}
private static int _called ;
private int id = 0 ;
private string uri ;
private static bool methodOneWay = false ;
}
// Another class used by the tests
public class DerivedMarshalObject : MarshalObject
{
public DerivedMarshalObject ( ) { }
public DerivedMarshalObject ( int id , string uri ) : base ( id , uri ) { }
}
interface A
{
}
interface B : A
{
}
public class CC : MarshalByRefObject
{
}
public class DD : MarshalByRefObject
{
}
} // namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal
namespace MonoTests.Remoting
{
using MonoTests.System.Runtime.Remoting.RemotingServicesInternal ;
// The main test class
[TestFixture]
2017-04-10 11:41:01 +00:00
public class RemotingServicesTest
2014-08-13 10:39:27 +01:00
{
private static int MarshalObjectId = 0 ;
public RemotingServicesTest ( )
{
MarshalObjectId = 0 ;
}
// Helper function that create a new
// MarshalObject with an unique ID
private static MarshalObject NewMarshalObject ( )
{
string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject" + MarshalObjectId . ToString ( ) ;
MarshalObject objMarshal = new MarshalObject ( MarshalObjectId , uri ) ;
MarshalObjectId + + ;
return objMarshal ;
}
// Another helper function
private DerivedMarshalObject NewDerivedMarshalObject ( )
{
string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.DerivedMarshalObject" + MarshalObjectId . ToString ( ) ;
DerivedMarshalObject objMarshal = new DerivedMarshalObject ( MarshalObjectId , uri ) ;
MarshalObjectId + + ;
return objMarshal ;
}
// The two folling method test RemotingServices.Marshal()
[Test]
public void Marshal1 ( )
{
MarshalObject objMarshal = NewMarshalObject ( ) ;
ObjRef objRef = RemotingServices . Marshal ( objMarshal ) ;
2017-04-10 11:41:01 +00:00
Assert . IsNotNull ( objRef . URI , "#A01" ) ;
2014-08-13 10:39:27 +01:00
MarshalObject objRem = ( MarshalObject ) RemotingServices . Unmarshal ( objRef ) ;
2017-04-10 11:41:01 +00:00
Assert . AreEqual ( objMarshal . Id , objRem . Id , "#A02" ) ;
2014-08-13 10:39:27 +01:00
objRem . Id = 2 ;
2017-04-10 11:41:01 +00:00
Assert . AreEqual ( objMarshal . Id , objRem . Id , "#A03" ) ;
2014-08-13 10:39:27 +01:00
// TODO: uncomment when RemotingServices.Disconnect is implemented
//RemotingServices.Disconnect(objMarshal);
objMarshal = NewMarshalObject ( ) ;
objRef = RemotingServices . Marshal ( objMarshal , objMarshal . Uri ) ;
2017-04-10 11:41:01 +00:00
Assert . IsTrue ( objRef . URI . EndsWith ( objMarshal . Uri ) , "#A04" ) ;
2014-08-13 10:39:27 +01:00
// TODO: uncomment when RemotingServices.Disconnect is implemented
//RemotingServices.Disconnect(objMarshal);
}
[Test]
public void Marshal2 ( )
{
DerivedMarshalObject derivedObjMarshal = NewDerivedMarshalObject ( ) ;
ObjRef objRef = RemotingServices . Marshal ( derivedObjMarshal , derivedObjMarshal . Uri , typeof ( MarshalObject ) ) ;
// Check that the type of the marshaled object is MarshalObject
2017-04-10 11:41:01 +00:00
Assert . IsTrue ( objRef . TypeInfo . TypeName . StartsWith ( ( typeof ( MarshalObject ) ) . ToString ( ) ) , "#A05" ) ;
2014-08-13 10:39:27 +01:00
// TODO: uncomment when RemotingServices.Disconnect is implemented
//RemotingServices.Disconnect(derivedObjMarshal);
}
// Tests RemotingServices.GetObjectUri()
[Test]
public void GetObjectUri ( )
{
MarshalObject objMarshal = NewMarshalObject ( ) ;
2017-04-10 11:41:01 +00:00
Assert . IsNull ( RemotingServices . GetObjectUri ( objMarshal ) , "#A06" ) ;
2014-08-13 10:39:27 +01:00
RemotingServices . Marshal ( objMarshal ) ;
2017-04-10 11:41:01 +00:00
Assert . IsNotNull ( RemotingServices . GetObjectUri ( objMarshal ) , "#A07" ) ;
2014-08-13 10:39:27 +01:00
// TODO: uncomment when RemotingServices.Disconnect is implemented
//RemotingServices.Disconnect(objMarshal);
}
// Tests RemotingServices.Connect
[Test]
public void Connect ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
2014-08-13 10:39:27 +01:00
MarshalObject objMarshal = NewMarshalObject ( ) ;
IDictionary props = new Hashtable ( ) ;
props [ "name" ] = objMarshal . Uri ;
2017-10-19 20:04:20 +00:00
props [ "port" ] = port ;
2014-08-13 10:39:27 +01:00
TcpChannel chn = new TcpChannel ( props , null , null ) ;
ChannelServices . RegisterChannel ( chn ) ;
try {
RemotingServices . Marshal ( objMarshal , objMarshal . Uri ) ;
2017-10-19 20:04:20 +00:00
MarshalObject objRem = ( MarshalObject ) RemotingServices . Connect ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/" + objMarshal . Uri ) ;
2017-04-10 11:41:01 +00:00
Assert . IsTrue ( RemotingServices . IsTransparentProxy ( objRem ) , "#A08" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
RemotingServices . Disconnect ( objMarshal ) ;
}
}
// Tests RemotingServices.Marshal()
[Test]
public void MarshalThrowException ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
2014-08-13 10:39:27 +01:00
MarshalObject objMarshal = NewMarshalObject ( ) ;
IDictionary props = new Hashtable ( ) ;
props [ "name" ] = objMarshal . Uri ;
2017-10-19 20:04:20 +00:00
props [ "port" ] = port ;
2014-08-13 10:39:27 +01:00
TcpChannel chn = new TcpChannel ( props , null , null ) ;
ChannelServices . RegisterChannel ( chn ) ;
try {
RemotingServices . Marshal ( objMarshal , objMarshal . Uri ) ;
2017-10-19 20:04:20 +00:00
MarshalObject objRem = ( MarshalObject ) RemotingServices . Connect ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/" + objMarshal . Uri ) ;
2014-08-13 10:39:27 +01:00
// This line should throw a RemotingException
// It is forbidden to export an object which is not
// a real object
try {
RemotingServices . Marshal ( objRem , objMarshal . Uri ) ;
2017-04-10 11:41:01 +00:00
Assert . Fail ( "#1" ) ;
2014-08-13 10:39:27 +01:00
} catch ( RemotingException e ) {
}
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
// TODO: uncomment when RemotingServices.Disconnect is implemented
//RemotingServices.Disconnect(objMarshal);
}
}
// Tests RemotingServices.ExecuteMessage()
// also tests GetMethodBaseFromMessage()
// IsMethodOverloaded()
[Test]
public void ExecuteMessage ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
TcpChannel chn = new TcpChannel ( port ) ;
2014-08-13 10:39:27 +01:00
ChannelServices . RegisterChannel ( chn ) ;
try {
MarshalObject objMarshal = NewMarshalObject ( ) ;
RemotingConfiguration . RegisterWellKnownServiceType ( typeof ( MarshalObject ) , objMarshal . Uri , WellKnownObjectMode . SingleCall ) ;
// use a proxy to catch the Message
2017-10-19 20:04:20 +00:00
MyProxy proxy = new MyProxy ( typeof ( MarshalObject ) , ( MarshalObject ) Activator . GetObject ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/" + objMarshal . Uri ) ) ;
2014-08-13 10:39:27 +01:00
MarshalObject objRem = ( MarshalObject ) proxy . GetTransparentProxy ( ) ;
objRem . Method1 ( ) ;
// Tests RemotingServices.GetMethodBaseFromMethodMessage()
2017-04-10 11:41:01 +00:00
Assert . AreEqual ( "Method1" , proxy . MthBase . Name , "#A09" ) ;
Assert . IsFalse ( proxy . IsMethodOverloaded , "#A09.1" ) ;
2014-08-13 10:39:27 +01:00
objRem . Method2 ( ) ;
2017-04-10 11:41:01 +00:00
Assert . IsTrue ( proxy . IsMethodOverloaded , "#A09.2" ) ;
2014-08-13 10:39:27 +01:00
// Tests RemotingServices.ExecuteMessage();
// If ExecuteMessage does it job well, Method1 should be called 2 times
2017-04-10 11:41:01 +00:00
Assert . AreEqual ( 2 , MarshalObject . Called , "#A10" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
}
}
// Tests the IsOneWay method
[Test]
public void IsOneWay ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
TcpChannel chn = new TcpChannel ( port ) ;
2014-08-13 10:39:27 +01:00
ChannelServices . RegisterChannel ( chn ) ;
try {
RemotingConfiguration . RegisterWellKnownServiceType ( typeof ( MarshalObject ) , "MarshalObject.rem" , WellKnownObjectMode . Singleton ) ;
2017-10-19 20:04:20 +00:00
MarshalObject objRem = ( MarshalObject ) Activator . GetObject ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/MarshalObject.rem" ) ;
2014-08-13 10:39:27 +01:00
2017-04-10 11:41:01 +00:00
Assert . IsTrue ( RemotingServices . IsTransparentProxy ( objRem ) , "#A10.1" ) ;
2014-08-13 10:39:27 +01:00
objRem . Method1 ( ) ;
Thread . Sleep ( 20 ) ;
2017-04-10 11:41:01 +00:00
Assert . IsFalse ( MarshalObject . IsMethodOneWay , "#A10.2" ) ;
2014-08-13 10:39:27 +01:00
objRem . Method3 ( ) ;
Thread . Sleep ( 20 ) ;
2017-04-10 11:41:01 +00:00
Assert . IsTrue ( MarshalObject . IsMethodOneWay , "#A10.3" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
}
}
[Test]
public void GetObjRefForProxy ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
TcpChannel chn = new TcpChannel ( port ) ;
2014-08-13 10:39:27 +01:00
ChannelServices . RegisterChannel ( chn ) ;
try {
// Register le factory as a SAO
RemotingConfiguration . RegisterWellKnownServiceType ( typeof ( MarshalObjectFactory ) , "MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap" , WellKnownObjectMode . Singleton ) ;
2017-10-19 20:04:20 +00:00
MarshalObjectFactory objFactory = ( MarshalObjectFactory ) Activator . GetObject ( typeof ( MarshalObjectFactory ) , $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap" ) ;
2014-08-13 10:39:27 +01:00
// Get a new "CAO"
MarshalObject objRem = objFactory . GetNewMarshalObject ( ) ;
ObjRef objRefRem = RemotingServices . GetObjRefForProxy ( ( MarshalByRefObject ) objRem ) ;
2017-04-10 11:41:01 +00:00
Assert . IsNotNull ( objRefRem , "#A11" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
}
}
// Tests GetRealProxy
[Test]
public void GetRealProxy ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
TcpChannel chn = new TcpChannel ( port ) ;
2014-08-13 10:39:27 +01:00
ChannelServices . RegisterChannel ( chn ) ;
try {
RemotingConfiguration . RegisterWellKnownServiceType ( typeof ( MarshalObject ) , "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap" , WellKnownObjectMode . Singleton ) ;
2017-10-19 20:04:20 +00:00
MyProxy proxy = new MyProxy ( typeof ( MarshalObject ) , ( MarshalByRefObject ) Activator . GetObject ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap" ) ) ;
2014-08-13 10:39:27 +01:00
MarshalObject objRem = ( MarshalObject ) proxy . GetTransparentProxy ( ) ;
RealProxy rp = RemotingServices . GetRealProxy ( objRem ) ;
2017-04-10 11:41:01 +00:00
Assert . IsNotNull ( rp , "#A12" ) ;
Assert . AreEqual ( "MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy" , rp . GetType ( ) . ToString ( ) , "#A13" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
}
}
// Tests SetObjectUriForMarshal()
[Test]
public void SetObjectUriForMarshal ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
TcpChannel chn = new TcpChannel ( port ) ;
2014-08-13 10:39:27 +01:00
ChannelServices . RegisterChannel ( chn ) ;
try {
MarshalObject objRem = NewMarshalObject ( ) ;
RemotingServices . SetObjectUriForMarshal ( objRem , objRem . Uri ) ;
RemotingServices . Marshal ( objRem ) ;
2017-10-19 20:04:20 +00:00
objRem = ( MarshalObject ) Activator . GetObject ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/" + objRem . Uri ) ;
2017-04-10 11:41:01 +00:00
Assert . IsNotNull ( objRem , "#A14" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
}
}
// Tests GetServeurTypeForUri()
[Test]
public void GetServeurTypeForUri ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
TcpChannel chn = new TcpChannel ( port ) ;
2014-08-13 10:39:27 +01:00
Type type = typeof ( MarshalObject ) ;
ChannelServices . RegisterChannel ( chn ) ;
try {
MarshalObject objRem = NewMarshalObject ( ) ;
RemotingServices . SetObjectUriForMarshal ( objRem , objRem . Uri ) ;
RemotingServices . Marshal ( objRem ) ;
Type typeRem = RemotingServices . GetServerTypeForUri ( RemotingServices . GetObjectUri ( objRem ) ) ;
2017-04-10 11:41:01 +00:00
Assert . AreEqual ( type , typeRem , "#A15" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
}
}
// Tests IsObjectOutOfDomain
// Tests IsObjectOutOfContext
[Test]
[Category ("NotWorking")]
public void IsObjectOutOf ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
TcpChannel chn = new TcpChannel ( port ) ;
2014-08-13 10:39:27 +01:00
ChannelServices . RegisterChannel ( chn ) ;
try {
RemotingConfiguration . RegisterWellKnownServiceType ( typeof ( MarshalObject ) , "MarshalObject2.rem" , WellKnownObjectMode . Singleton ) ;
2017-10-19 20:04:20 +00:00
MarshalObject objRem = ( MarshalObject ) Activator . GetObject ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/MarshalObject2.rem" ) ;
2014-08-13 10:39:27 +01:00
2017-04-10 11:41:01 +00:00
Assert . IsTrue ( RemotingServices . IsObjectOutOfAppDomain ( objRem ) , "#A16" ) ;
Assert . IsTrue ( RemotingServices . IsObjectOutOfContext ( objRem ) , "#A17" ) ;
2014-08-13 10:39:27 +01:00
MarshalObject objMarshal = new MarshalObject ( ) ;
2017-04-10 11:41:01 +00:00
Assert . IsFalse ( RemotingServices . IsObjectOutOfAppDomain ( objMarshal ) , "#A18" ) ;
Assert . IsFalse ( RemotingServices . IsObjectOutOfContext ( objMarshal ) , "#A19" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
}
}
[Test]
public void ApplicationNameTest ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
2014-08-13 10:39:27 +01:00
RemotingConfiguration . ApplicationName = "app" ;
2017-10-19 20:04:20 +00:00
TcpChannel chn = new TcpChannel ( port ) ;
2014-08-13 10:39:27 +01:00
ChannelServices . RegisterChannel ( chn ) ;
try {
RemotingConfiguration . RegisterWellKnownServiceType ( typeof ( MarshalObject ) , "obj3.rem" , WellKnownObjectMode . Singleton ) ;
2017-10-19 20:04:20 +00:00
MarshalObject objRem = ( MarshalObject ) Activator . GetObject ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/app/obj3.rem" ) ;
MarshalObject objRem2 = ( MarshalObject ) Activator . GetObject ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/obj3.rem" ) ;
2014-08-13 10:39:27 +01:00
2017-04-10 11:41:01 +00:00
Assert . IsTrue ( RemotingServices . IsTransparentProxy ( objRem ) , "#AN1" ) ;
Assert . IsTrue ( RemotingServices . IsTransparentProxy ( objRem2 ) , "#AN2" ) ;
2014-08-13 10:39:27 +01:00
2017-04-10 11:41:01 +00:00
Assert . IsNotNull ( RemotingServices . GetServerTypeForUri ( "obj3.rem" ) , "#AN3" ) ;
Assert . IsNotNull ( RemotingServices . GetServerTypeForUri ( "/app/obj3.rem" ) , "#AN4" ) ;
Assert . IsNull ( RemotingServices . GetServerTypeForUri ( "//app/obj3.rem" ) , "#AN5" ) ;
Assert . IsNull ( RemotingServices . GetServerTypeForUri ( "app/obj3.rem" ) , "#AN6" ) ;
Assert . IsNull ( RemotingServices . GetServerTypeForUri ( "/whatever/obj3.rem" ) , "#AN7" ) ;
Assert . IsNotNull ( RemotingServices . GetServerTypeForUri ( "/obj3.rem" ) , "#AN8" ) ;
Assert . IsNull ( RemotingServices . GetServerTypeForUri ( "//obj3.rem" ) , "#AN9" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
}
}
[Test]
public void GetObjectWithChannelDataTest ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
TcpChannel chn = new TcpChannel ( port ) ;
2014-08-13 10:39:27 +01:00
ChannelServices . RegisterChannel ( chn ) ;
try {
RemotingConfiguration . RegisterWellKnownServiceType ( typeof ( MarshalObject ) , "getobjectwithchanneldata.rem" , WellKnownObjectMode . Singleton ) ;
string channelData = "test" ;
2017-10-19 20:04:20 +00:00
Assert . IsNotNull ( Activator . GetObject ( typeof ( MarshalObject ) , $"tcp://localhost:{port}/getobjectwithchanneldata.rem" , channelData ) , "#01" ) ;
2014-08-13 10:39:27 +01:00
} finally {
ChannelServices . UnregisterChannel ( chn ) ;
}
}
[Test]
[Ignore ("We cannot test RemotingConfiguration.Configure() because it keeps channels registered. If we really need to test it, do it as a standalone case")]
public void ConnectProxyCast ( )
{
2017-10-19 20:04:20 +00:00
var port = NetworkHelpers . FindFreePort ( ) ;
2014-08-13 10:39:27 +01:00
object o ;
RemotingConfiguration . Configure ( null ) ;
2017-10-19 20:04:20 +00:00
o = RemotingServices . Connect ( typeof ( MarshalByRefObject ) , $"tcp://localhost:{port}/ff1.rem" ) ;
2017-04-10 11:41:01 +00:00
Assert . IsInstanceOfType ( typeof ( DD ) , o , "#m1" ) ;
Assert . IsInstanceOfType ( typeof ( A ) , o , "#m2" ) ;
Assert . IsInstanceOfType ( typeof ( B ) , o , "#m3" ) ;
AssertHelper . IsNotInstanceOfType ( typeof ( CC ) , ! ( o is CC ) , "#m4" ) ;
2014-08-13 10:39:27 +01:00
2017-10-19 20:04:20 +00:00
o = RemotingServices . Connect ( typeof ( A ) , $"tcp://localhost:{port}/ff3.rem" ) ;
2017-04-10 11:41:01 +00:00
Assert . IsInstanceOfType ( typeof ( DD ) , o , "#a1" ) ;
Assert . IsInstanceOfType ( typeof ( A ) , o , "#a2" ) ;
Assert . IsInstanceOfType ( typeof ( B ) , o , "#a3" ) ;
AssertHelper . IsNotInstanceOfType ( typeof ( CC ) , o , "#a4" ) ;
2014-08-13 10:39:27 +01:00
2017-10-19 20:04:20 +00:00
o = RemotingServices . Connect ( typeof ( DD ) , $"tcp://localhost:{port}/ff4.rem" ) ;
2017-04-10 11:41:01 +00:00
Assert . IsInstanceOfType ( typeof ( DD ) , o , "#d1" ) ;
Assert . IsInstanceOfType ( typeof ( A ) , o , "#d2" ) ;
Assert . IsInstanceOfType ( typeof ( B ) , o , "#d3" ) ;
AssertHelper . IsNotInstanceOfType ( typeof ( CC ) , o , "#d4" ) ;
2014-08-13 10:39:27 +01:00
2017-10-19 20:04:20 +00:00
o = RemotingServices . Connect ( typeof ( CC ) , $"tcp://localhost:{port}/ff5.rem" ) ;
2017-04-10 11:41:01 +00:00
AssertHelper . IsNotInstanceOfType ( typeof ( DD ) , o , "#c1" ) ;
Assert . IsInstanceOfType ( typeof ( A ) , o , "#c2" ) ;
Assert . IsInstanceOfType ( typeof ( B ) , o , "#c3" ) ;
Assert . IsInstanceOfType ( typeof ( CC ) , o , "#c4" ) ;
2014-08-13 10:39:27 +01:00
}
// Don't add any tests that must create channels
// after ConnectProxyCast (), because this test calls
// RemotingConfiguration.Configure ().
} // end class RemotingServicesTest
} // end of namespace MonoTests.Remoting