From: Steve M. <Ste...@mp...> - 2005-07-14 20:31:45
|
The actual software creates objects that are derived from System.ComponentModel.Component that are added to containers that provide services that are added to a ServiceContainer object. The objects call GetService(System.Type serviceType) on the Component base class and they receive a reference to the service of that type that has been added to the container. For testing purposes I am trying to put mock objects into the service container so I can mock the services that connect to a larger system that I don't want involved in the testing process. The test fixture below is a self contained test fixture that exhibits a minimal case of the problem. The interface IinterfaceToMock represents a service available on the container. The mock object should be able to be added to container and when retrieved the returned instance should be the same as the one passed in. =20 The test dies when the object is being added to the container, because down in the service container code (viewed through Reflector). -----Original Message----- From: Nat Pryce [mailto:nat...@gm...]=20 Sent: Thursday, July 14, 2005 11:22 AM To: Steve Mitcham Subject: Re: [Nmock-general] Transparent Proxy issue in NMock2 I don't understand enough of what your code is doing to look into the problem. Can you distil the problem into a self-contained failing unit test? --Nat. On 7/14/05, Steve Mitcham <Ste...@mp...> wrote: > I've got a situation where the transparent proxy fails. I don't know=20 > enough about the mechanism of the proxy so this may be a .NET issue. =20 > I can't figure out where a good place would be to stick a hack either. >=20 > [TestFixture] > public class ServiceContainerTests > { > ServiceContainer container; >=20 > private interface IInterfaceToMock > { > void SampleMethod(); > } >=20 > [Test] > public void MockObjectsCanBeUsedInServiceContainer() > { > container =3D new ServiceContainer(); > Mockery mockery =3D new Mockery(); > IInterfaceToMock mockInterface =3D > mockery.NewMock(typeof(IInterfaceToMock)) as IInterfaceToMock; >=20 > container.AddService(typeof(IInterfaceToMock),mockInterface); > IInterfaceToMock service =3D > container.GetService(typeof(IInterfaceToMock)) as IInterfaceToMock; > Assert.AreSame(mockInterface,service); > } > } >=20 > Inside the AddService call there is a call to the IsAssignableFrom=20 > method of the IInterfaceToMock interface which uses mockInterface as a > parameter and fails. >=20 > The use of service containers is fairly extensive in my codebase and=20 > the work around is very cumbersome. >=20 >=20 >=20 > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles,=20 > informative Webcasts and more! Get everything you need to get up to=20 > speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id=16492&opclick > _______________________________________________ > Nmock-general mailing list > Nmo...@li... > https://lists.sourceforge.net/lists/listinfo/nmock-general > |