Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C#

Test Driven Prototyping - Learning About .NET Remoting

Rate me:
Please Sign up or sign in to vote.
4.90/5 (25 votes)
7 Apr 200719 min read 69.6K   144   79  
Use test driven development processes to determine the issues affecting application architecture and design with regards to .NET remoting.
using System;
using System.Runtime.Serialization;

using Vts.UnitTest;

using Interfaces;

namespace ClientTests
{
	[TestFixture]
	public class ConnectionTests
	{
		internal delegate void RemoteAsyncDelegate();

		[TestFixtureSetUp]
		public void TestFixtureSetup()
		{
			RemotingHelper.LoadConfiguration("clientConfig.xml");
		}

		[TestFixtureTearDown]
		public void TestFixtureTearDown()
		{
			RemotingHelper.UnloadConfiguration();
		}

		[Test]
		public void InstancePerCallTest()
		{
			ITest t1 = RemotingHelper.CreatePerCallTestObject();
			t1.Value1 = 1;
			t1.Value2 = 2;
			Assertion.Assert(t1.Value1 == 0, "Expected t1.Value1 to be 0 for a single call activation remote object.");
		}

		[Test]
		public void SingletonActivationTest()
		{
			ITest t1 = RemotingHelper.CreateSingletonTestObject();
			t1.Value1 = 1;
			t1.Value2 = 2;
			Assertion.Assert(t1.Value1 == 1, "Expected t1.Value1 to be 1 for a singleton remote object.");
			ITest t2 = RemotingHelper.CreateSingletonTestObject();
			Assertion.Assert(t2.Value1 == 1, "Expected t2.Value1 to be 1 for a second instance of the singleton object.");
		}

		[Test]
		public void SameReferenceTest()
		{
			ITest t1 = RemotingHelper.CreateSingletonTestObject();
			ITest t2 = RemotingHelper.CreateSingletonTestObject();
			Assertion.Assert(t1 == t2, "Expected t1==t2.");
		}

		[Test]
		public void FactoryActivationTest()
		{
			IFactory factory = RemotingHelper.CreateFactoryObject();
			ITest t1 = factory.CreateTest();
			t1.Value1 = 1;
			t1.Value2 = 2;
			Assertion.Assert(t1.Value1 == 1, "Expected t1.Value1 to be 1 for a factory created remote object.");
			ITest t2 = factory.CreateTest();
			Assertion.Assert(t2.Value1 == 0, "Expected t2.Value1 to be 0 for a second instance of a factory created remote object.");
		}

		[Test]
		public void FactoryDifferentReferenceTest()
		{
			IFactory factory = RemotingHelper.CreateFactoryObject();
			ITest t1 = factory.CreateTest();
			ITest t2 = factory.CreateTest();
			Assertion.Assert(t1 != t2, "Expected t1 != t2.");
		}

		[Test]
		[ExpectedException(typeof(Exception))]
		public void SystemExceptionTest()
		{
			ITest t1 = RemotingHelper.CreateSingletonTestObject();
			t1.CreateSystemException();
		}

		[Test]
		[ExpectedException(typeof(SerializationException))]
		public void CustomExceptionTest()
		{
			ITest t1 = RemotingHelper.CreateSingletonTestObject();
			t1.CreateCustomException();
		}

		[Test]
		[Ignore]
		public void InfiniteLoopTest()
		{
			ITest t1 = RemotingHelper.CreateSingletonTestObject();
			t1.InfiniteLoop();
		}

		[Test]
		public void AsyncReturnImmediateTest()
		{
			ITest t1 = RemotingHelper.CreateSingletonTestObject();
			RemoteAsyncDelegate remoteDlgt = new RemoteAsyncDelegate(t1.ReturnImmediately);
			remoteDlgt.BeginInvoke(null, null);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Interacx
United States United States
Blog: https://marcclifton.wordpress.com/
Home Page: http://www.marcclifton.com
Research: http://www.higherorderprogramming.com/
GitHub: https://github.com/cliftonm

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions