From 33fbc05483cabe36b9b291306541e3aca8edd123 Mon Sep 17 00:00:00 2001 From: eeichinger Date: Thu, 3 Sep 2009 22:56:22 +0000 Subject: [PATCH] added NullReferenceException test for SPRNET-1251 --- .../Remoting/SaoExporterTests.cs | 85 +++++++++++-------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/test/Spring/Spring.Services.Tests/Remoting/SaoExporterTests.cs b/test/Spring/Spring.Services.Tests/Remoting/SaoExporterTests.cs index a7fb4d96..08983dc1 100644 --- a/test/Spring/Spring.Services.Tests/Remoting/SaoExporterTests.cs +++ b/test/Spring/Spring.Services.Tests/Remoting/SaoExporterTests.cs @@ -77,11 +77,7 @@ namespace Spring.Remoting saoExporter.AfterPropertiesSet(); of.RegisterSingleton("simpleCounterExporter", saoExporter); // also tests SaoExporter.Dispose()! - ISimpleCounter client = (ISimpleCounter)Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/RemotedSaoSingletonCounter"); - client.Count(); - client.Count(); - - Assert.AreEqual(2, client.Counter); + AssertExportedService(saoExporter.ServiceName, 2); } } @@ -98,18 +94,15 @@ namespace Spring.Remoting saoExporter.AfterPropertiesSet(); of.RegisterSingleton("simpleCounterExporter", saoExporter); // also tests SaoExporter.Dispose()! - ISimpleCounter client = (ISimpleCounter)Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/RemotedSaoSingleCallCounter"); - client.Count(); - client.Count(); - Assert.AreEqual(0, client.Counter); + AssertExportedService(saoExporter.ServiceName, 0); } } /// - /// Checks that exp an IFactoryObject.ObjectType returns an interface type, + /// Checks that we can also export if IFactoryObject.ObjectType returns an interface type, /// [Test(Description = "http://jira.springframework.org/browse/SPRNET-1251")] - public void CanExportFromInterfaceTargetType() + public void CanExportFromFactoryObjectIfObjectTypeIsInterface() { using (DefaultListableObjectFactory of = new DefaultListableObjectFactory()) { @@ -127,33 +120,57 @@ namespace Spring.Remoting saoExporter.TargetName = "simpleCounter"; saoExporter.ServiceName = "RemotedSaoCallCounter"; saoExporter.AfterPropertiesSet(); + of.RegisterSingleton("simpleCounterExporter", saoExporter); // also tests SaoExporter.Dispose()! -// XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of); -// reader.LoadObjectDefinitions(new StringResource( -// @" -// -// -// -// -// -// -// -// -// -// -// -//")); -// SaoExporter saoExporter = (SaoExporter) of.GetObject("ISimpleCounterExporter"); -// Assert.IsNotNull(saoExporter); - - ISimpleCounter client = (ISimpleCounter)Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/RemotedSaoCallCounter"); - client.Count(); - client.Count(); - - Assert.AreEqual(2, client.Counter); + AssertExportedService(saoExporter.ServiceName, 2); mocks.VerifyAll(); } } + + /// + /// Checks that exp an IFactoryObject.ObjectType returns an interface type, + /// + [Test(Description = "http://jira.springframework.org/browse/SPRNET-1251")] + public void ThrowsTypeLoadExceptionIfProxyInterfacesValueIsSpecifiedInsteadOfListElement() + { + using (DefaultListableObjectFactory of = new DefaultListableObjectFactory()) + { + XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of); + reader.LoadObjectDefinitions(new StringResource( + @" + + + + + + + + + + + +")); + try + { + SaoExporter saoExporter = (SaoExporter) of.GetObject("ISimpleCounterExporter"); + Assert.Fail(); + } + catch (ObjectCreationException oce) + { + TypeLoadException tle = (TypeLoadException) oce.GetBaseException(); + Assert.AreEqual("Could not load type from string value ' Spring.Services.Tests'.", tle.Message); + } + } + } + + private void AssertExportedService(string serviceName, int expectedCount) + { + ISimpleCounter client = (ISimpleCounter)Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/" + serviceName); + client.Count(); + client.Count(); + + Assert.AreEqual(expectedCount, client.Counter); + } } }