diff --git a/packaging/nuget/nservicebus.acceptancetests.nuspec b/packaging/nuget/nservicebus.acceptancetests.nuspec index 3aa7409e8f..8195f217db 100644 --- a/packaging/nuget/nservicebus.acceptancetests.nuspec +++ b/packaging/nuget/nservicebus.acceptancetests.nuspec @@ -21,6 +21,6 @@ - + diff --git a/packaging/nuget/nservicebus.containertests.nuspec b/packaging/nuget/nservicebus.containertests.nuspec new file mode 100644 index 0000000000..3a03424085 --- /dev/null +++ b/packaging/nuget/nservicebus.containertests.nuspec @@ -0,0 +1,25 @@ + + + + NServiceBus.ContainerTests.Sources + Source only package containing the NServiceBus container test suite + $version$ + NServiceBus Ltd + NServiceBus Ltd + http://particular.net/LicenseAgreement + http://particular.net/ + http://s3.amazonaws.com/nuget.images/NServiceBus_32.png + true + Container tests for nservicebus core functionality + + Copyright 2010-2014 NServiceBus. All rights reserved + nservicebus servicebus msmq cqrs publish subscribe + + + + + + + + + diff --git a/src/NServiceBus.AcceptanceTests/Exceptions/StackTraceAssert.cs b/src/NServiceBus.AcceptanceTests/Exceptions/StackTraceAssert.cs index 4d093f2243..a6293edae7 100644 --- a/src/NServiceBus.AcceptanceTests/Exceptions/StackTraceAssert.cs +++ b/src/NServiceBus.AcceptanceTests/Exceptions/StackTraceAssert.cs @@ -9,18 +9,19 @@ namespace NServiceBus.AcceptanceTests.Exceptions { static class StackTraceAssert { - public static void AreEqual(string expected, string actual) +// ReSharper disable once UnusedParameter.Global + public static void StartsWith(string expected, string actual) { - if (actual == null || expected == null) + if (actual == null) { - Assert.AreEqual(expected, actual); + Assert.Fail(); } else { - var cleanStackTrace = actual.CleanStackTrace(); + var cleanStackTrace = CleanStackTrace(actual); try { - Assert.AreEqual(expected.Replace("\r\n", "\n"), cleanStackTrace.Replace("\r\n", "\n")); + Assert.IsTrue(cleanStackTrace.Replace("\r\n", "\n").StartsWith(expected.Replace("\r\n", "\n"))); } catch (Exception) { @@ -29,7 +30,7 @@ public static void AreEqual(string expected, string actual) } } } - public static string CleanStackTrace(this string stackTrace) + static string CleanStackTrace(string stackTrace) { if (stackTrace== null) { diff --git a/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_Begin_and_different_End_throws.cs b/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_Begin_and_different_End_throws.cs index ee7d9548cd..dd749160b7 100644 --- a/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_Begin_and_different_End_throws.cs +++ b/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_Begin_and_different_End_throws.cs @@ -29,18 +29,17 @@ public void Should_receive_AggregateException_with_both_exceptions() #if (!DEBUG) - StackTraceAssert.AreEqual( + StackTraceAssert.StartsWith( @"at NServiceBus.UnitOfWorkBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.ChildContainerBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.ProcessingStatisticsBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1 pipelineAction, T context) at NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) -at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message) -at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action()", context.StackTrace); +at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message)", context.StackTrace); - StackTraceAssert.AreEqual( -@"at NServiceBus.AcceptanceTests.Exceptions.When_Uow_Begin_and_different_End_throws.Endpoint.UnitOfWorkThatThrowsInEnd.End(Exception ex) -at NServiceBus.UnitOfWorkBehavior.AppendEndExceptionsAndRethrow(Exception initialException)", context.InnerExceptionTwoStackTrace); + StackTraceAssert.StartsWith( +string.Format(@"at NServiceBus.AcceptanceTests.Exceptions.When_Uow_Begin_and_different_End_throws.Endpoint.{0}.End(Exception ex) +at NServiceBus.UnitOfWorkBehavior.AppendEndExceptionsAndRethrow(Exception initialException)", context.TypeName), context.InnerExceptionTwoStackTrace); #endif @@ -55,6 +54,8 @@ public class Context : ScenarioContext public string InnerExceptionTwoStackTrace { get; set; } public Type InnerExceptionOneType { get; set; } public Type InnerExceptionTwoType { get; set; } + public bool FirstOneExecuted { get; set; } + public string TypeName { get; set; } } public class Endpoint : EndpointConfigurationBuilder @@ -66,8 +67,8 @@ public Endpoint() b.RegisterComponents(c => { c.ConfigureComponent(DependencyLifecycle.SingleInstance); - c.ConfigureComponent(DependencyLifecycle.InstancePerUnitOfWork); - c.ConfigureComponent(DependencyLifecycle.InstancePerUnitOfWork); + c.ConfigureComponent(DependencyLifecycle.InstancePerUnitOfWork); + c.ConfigureComponent(DependencyLifecycle.InstancePerUnitOfWork); }); b.DisableFeature(); }) @@ -103,30 +104,63 @@ public void Init(Address address) } } - public class UnitOfWorkThatThrowsInBegin : IManageUnitsOfWork + public class UnitOfWorkThatThrows1 : IManageUnitsOfWork { + public Context Context { get; set; } + + bool throwAtEnd; + [MethodImpl(MethodImplOptions.NoInlining)] public void Begin() { - throw new BeginException(); + if (Context.FirstOneExecuted) + { + throw new BeginException(); + } + + Context.FirstOneExecuted = throwAtEnd = true; } + [MethodImpl(MethodImplOptions.NoInlining)] public void End(Exception ex = null) { + if (throwAtEnd) + { + Context.TypeName = GetType().Name; + + throw new EndException(); + } } } - public class UnitOfWorkThatThrowsInEnd : IManageUnitsOfWork + public class UnitOfWorkThatThrows2 : IManageUnitsOfWork { + public Context Context { get; set; } + + bool throwAtEnd; + [MethodImpl(MethodImplOptions.NoInlining)] public void Begin() { + if (Context.FirstOneExecuted) + { + throw new BeginException(); + } + + Context.FirstOneExecuted = throwAtEnd = true; } + [MethodImpl(MethodImplOptions.NoInlining)] public void End(Exception ex = null) { - throw new EndException(); + if (throwAtEnd) + { + Context.TypeName = GetType().Name; + + throw new EndException(); + } } } + class Handler : IHandleMessages { [MethodImpl(MethodImplOptions.NoInlining)] diff --git a/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_Begin_throws.cs b/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_Begin_throws.cs index ef8c34eeac..9b6ca1fec1 100644 --- a/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_Begin_throws.cs +++ b/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_Begin_throws.cs @@ -25,15 +25,14 @@ public void Should_receive_exception_thrown_from_begin() Assert.AreEqual(typeof(BeginException), context.ExceptionType); #if (!DEBUG) - StackTraceAssert.AreEqual( + StackTraceAssert.StartsWith( @"at NServiceBus.AcceptanceTests.Exceptions.When_Uow_Begin_throws.Endpoint.UnitOfWorkThatThrowsInBegin.Begin() at NServiceBus.UnitOfWorkBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.ChildContainerBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.ProcessingStatisticsBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1 pipelineAction, T context) at NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) -at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message) -at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action()", context.StackTrace); +at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message)", context.StackTrace); #endif } @@ -97,6 +96,7 @@ public void End(Exception ex = null) { } } + class Handler : IHandleMessages { [MethodImpl(MethodImplOptions.NoInlining)] @@ -104,7 +104,6 @@ public void Handle(Message message) { } } - } [Serializable] diff --git a/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_End_throws.cs b/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_End_throws.cs index 13fd03c01c..237f520a02 100644 --- a/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_End_throws.cs +++ b/src/NServiceBus.AcceptanceTests/Exceptions/When_Uow_End_throws.cs @@ -25,15 +25,14 @@ public void Should_receive_exception_thrown_from_end() Assert.AreEqual(typeof(EndException), context.ExceptionType); #if(!DEBUG) - StackTraceAssert.AreEqual( + StackTraceAssert.StartsWith( @"at NServiceBus.AcceptanceTests.Exceptions.When_Uow_End_throws.Endpoint.UnitOfWorkThatThrowsInEnd.End(Exception ex) at NServiceBus.UnitOfWorkBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.ChildContainerBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.ProcessingStatisticsBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1 pipelineAction, T context) at NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) -at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message) -at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action()", context.StackTrace); +at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message)", context.StackTrace); #endif } @@ -104,7 +103,6 @@ public void Handle(Message message) { } } - } [Serializable] diff --git a/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_and_Uow_End_throws.cs b/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_and_Uow_End_throws.cs index cf36a2f9b2..5c46bfd88b 100644 --- a/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_and_Uow_End_throws.cs +++ b/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_and_Uow_End_throws.cs @@ -22,20 +22,20 @@ public void Should_receive_AggregateException_with_both_exceptions() .AllowExceptions() .Done(c => c.ExceptionReceived) .Run(); + Assert.AreEqual(typeof(HandlerException), context.InnerExceptionOneType); Assert.AreEqual(typeof(EndException), context.InnerExceptionTwoType); #if (!DEBUG) - StackTraceAssert.AreEqual( + StackTraceAssert.StartsWith( @"at NServiceBus.UnitOfWorkBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.ChildContainerBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.ProcessingStatisticsBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1 pipelineAction, T context) at NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) -at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message) -at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action()", context.StackTrace); +at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message)", context.StackTrace); - StackTraceAssert.AreEqual( + StackTraceAssert.StartsWith( @"at NServiceBus.AcceptanceTests.Exceptions.When_handler_and_Uow_End_throws.Endpoint.Handler.Handle(Message message) at NServiceBus.Unicast.MessageHandlerRegistry.Invoke(Object handler, Object message, Dictionary`2 dictionary) at NServiceBus.InvokeHandlersBehavior.Invoke(IncomingContext context, Action next) @@ -49,9 +49,9 @@ at NServiceBus.ApplyIncomingTransportMessageMutatorsBehavior.Invoke(IncomingCont at NServiceBus.SubscriptionReceiverBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.UnitOfWorkBehavior.Invoke(IncomingContext context, Action next)", context.InnerExceptionOneStackTrace); - StackTraceAssert.AreEqual( -@"at NServiceBus.AcceptanceTests.Exceptions.When_handler_and_Uow_End_throws.Endpoint.UnitOfWorkThatThrowsInEnd.End(Exception ex) -at NServiceBus.UnitOfWorkBehavior.AppendEndExceptionsAndRethrow(Exception initialException)", context.InnerExceptionTwoStackTrace); + StackTraceAssert.StartsWith( +string.Format(@"at NServiceBus.AcceptanceTests.Exceptions.When_handler_and_Uow_End_throws.Endpoint.{0}.End(Exception ex) +at NServiceBus.UnitOfWorkBehavior.AppendEndExceptionsAndRethrow(Exception initialException)", context.TypeName), context.InnerExceptionTwoStackTrace); #endif } @@ -64,6 +64,8 @@ public class Context : ScenarioContext public string InnerExceptionTwoStackTrace { get; set; } public Type InnerExceptionOneType { get; set; } public Type InnerExceptionTwoType { get; set; } + public bool FirstOneExecuted { get; set; } + public string TypeName { get; set; } } public class Endpoint : EndpointConfigurationBuilder @@ -75,8 +77,8 @@ public Endpoint() b.RegisterComponents(c => { c.ConfigureComponent(DependencyLifecycle.SingleInstance); - c.ConfigureComponent(DependencyLifecycle.InstancePerUnitOfWork); - c.ConfigureComponent(DependencyLifecycle.InstancePerUnitOfWork); + c.ConfigureComponent(DependencyLifecycle.InstancePerUnitOfWork); + c.ConfigureComponent(DependencyLifecycle.InstancePerUnitOfWork); }); b.DisableFeature(); }) @@ -112,31 +114,64 @@ public void Init(Address address) } } - public class UnitOfWorkThatThrowsInBegin : IManageUnitsOfWork + public class UnitOfWorkThatThrows1 : IManageUnitsOfWork { + public Context Context { get; set; } + + bool executedInSecondPlace; + [MethodImpl(MethodImplOptions.NoInlining)] public void Begin() { + if (Context.FirstOneExecuted) + { + executedInSecondPlace = true; + } + + Context.FirstOneExecuted = true; } [MethodImpl(MethodImplOptions.NoInlining)] public void End(Exception ex = null) { + if (executedInSecondPlace) + { + Context.TypeName = GetType().Name; + + throw new EndException(); + } } } - public class UnitOfWorkThatThrowsInEnd : IManageUnitsOfWork + + public class UnitOfWorkThatThrows2 : IManageUnitsOfWork { + public Context Context { get; set; } + + bool executedInSecondPlace; + [MethodImpl(MethodImplOptions.NoInlining)] public void Begin() { + if (Context.FirstOneExecuted) + { + executedInSecondPlace = true; + } + + Context.FirstOneExecuted = true; } [MethodImpl(MethodImplOptions.NoInlining)] public void End(Exception ex = null) { - throw new EndException(); + if (executedInSecondPlace) + { + Context.TypeName = GetType().Name; + + throw new EndException(); + } } } + class Handler : IHandleMessages { [MethodImpl(MethodImplOptions.NoInlining)] diff --git a/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_throws.cs b/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_throws.cs index 2db76a4d38..5994e5a19a 100644 --- a/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_throws.cs +++ b/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_throws.cs @@ -23,7 +23,7 @@ public void Should_receive_exception_from_handler() .Run(); Assert.AreEqual(typeof(HandlerException), context.ExceptionType); #if (!DEBUG) - StackTraceAssert.AreEqual( + StackTraceAssert.StartsWith( @"at NServiceBus.AcceptanceTests.Exceptions.When_handler_throws.Endpoint.Handler.Handle(Message message) at NServiceBus.Unicast.MessageHandlerRegistry.Invoke(Object handler, Object message, Dictionary`2 dictionary) at NServiceBus.InvokeHandlersBehavior.Invoke(IncomingContext context, Action next) @@ -40,8 +40,7 @@ at NServiceBus.ChildContainerBehavior.Invoke(IncomingContext context, Action nex at NServiceBus.ProcessingStatisticsBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1 pipelineAction, T context) at NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) -at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message) -at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action()", context.StackTrace); +at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message)", context.StackTrace); #endif } diff --git a/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_throws_AggregateException.cs b/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_throws_AggregateException.cs index 9b0581eebe..7c5523b5f4 100644 --- a/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_throws_AggregateException.cs +++ b/src/NServiceBus.AcceptanceTests/Exceptions/When_handler_throws_AggregateException.cs @@ -27,7 +27,7 @@ public void Should_receive_exact_AggregateException_exception_from_handler() Assert.AreEqual("My Inner Exception", context.InnerExceptionMessage); #if (!DEBUG) - StackTraceAssert.AreEqual( + StackTraceAssert.StartsWith( @"at NServiceBus.AcceptanceTests.Exceptions.When_handler_throws_AggregateException.Endpoint.Handler.Handle(Message message) at NServiceBus.Unicast.MessageHandlerRegistry.Invoke(Object handler, Object message, Dictionary`2 dictionary) at NServiceBus.InvokeHandlersBehavior.Invoke(IncomingContext context, Action next) @@ -44,10 +44,9 @@ at NServiceBus.ChildContainerBehavior.Invoke(IncomingContext context, Action nex at NServiceBus.ProcessingStatisticsBehavior.Invoke(IncomingContext context, Action next) at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1 pipelineAction, T context) at NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) -at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message) -at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action()", context.StackTrace); +at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message)", context.StackTrace); - StackTraceAssert.AreEqual( + StackTraceAssert.StartsWith( @"at NServiceBus.AcceptanceTests.Exceptions.When_handler_throws_AggregateException.Endpoint.Handler.MethodThatThrows() at NServiceBus.AcceptanceTests.Exceptions.When_handler_throws_AggregateException.Endpoint.Handler.Handle(Message message)", context.InnerStackTrace); #endif diff --git a/src/NServiceBus.AcceptanceTests/Exceptions/When_serialization_throws.cs b/src/NServiceBus.AcceptanceTests/Exceptions/When_serialization_throws.cs index 771cc3a11b..92cb7f1173 100644 --- a/src/NServiceBus.AcceptanceTests/Exceptions/When_serialization_throws.cs +++ b/src/NServiceBus.AcceptanceTests/Exceptions/When_serialization_throws.cs @@ -3,7 +3,6 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.Serialization; - using System.Xml; using NServiceBus.AcceptanceTesting; using NServiceBus.AcceptanceTests.EndpointTemplates; using NServiceBus.Config; @@ -25,21 +24,8 @@ public void Should_receive_SerializationException() .AllowExceptions() .Done(c => c.ExceptionReceived) .Run(); - Assert.AreEqual(typeof(SerializationException), context.ExceptionType); - Assert.AreEqual(typeof(XmlException), context.InnerExceptionType); -#if (!DEBUG) - StackTraceAssert.AreEqual( -@"at System.Xml.XmlTextReaderImpl.Throw(Exception e) -at System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos) -at System.Xml.XmlTextReaderImpl.ParseElement() -at System.Xml.XmlTextReaderImpl.ParseDocumentContent() -at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) -at System.Xml.XmlDocument.Load(XmlReader reader) -at NServiceBus.Serializers.XML.XmlMessageSerializer.Deserialize(Stream stream, IList`1 messageTypesToDeserialize) -at NServiceBus.DeserializeLogicalMessagesBehavior.Extract(TransportMessage physicalMessage) -at NServiceBus.DeserializeLogicalMessagesBehavior.Invoke(IncomingContext context, Action next)", context.InnerExceptionStackTrace); -#endif + Assert.AreEqual(typeof(SerializationException), context.ExceptionType); } public class Context : ScenarioContext diff --git a/src/ObjectBuilder.Tests/ObjectBuilder.Tests.csproj b/src/NServiceBus.ContainerTests/NServiceBus.ContainerTests.csproj similarity index 64% rename from src/ObjectBuilder.Tests/ObjectBuilder.Tests.csproj rename to src/NServiceBus.ContainerTests/NServiceBus.ContainerTests.csproj index 535ee45486..ebf17a24a3 100644 --- a/src/ObjectBuilder.Tests/ObjectBuilder.Tests.csproj +++ b/src/NServiceBus.ContainerTests/NServiceBus.ContainerTests.csproj @@ -8,12 +8,10 @@ {0A282BF4-0957-4074-8D5E-C2FB8634A3AA} Library Properties - ObjectBuilder.Tests - ObjectBuilder.Tests + NServiceBus.ContainerTests + NServiceBus.ContainerTests v4.5 512 - true - ..\NServiceBus.snk ..\ @@ -39,33 +37,9 @@ false - - ..\packages\Autofac.3.5.2\lib\net40\Autofac.dll - - - ..\packages\Castle.Core.3.3.0\lib\net45\Castle.Core.dll - - - ..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll - - - ..\packages\Common.Logging.1.2.0\lib\1.0\Common.Logging.dll - - - ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll - - - ..\packages\Ninject.Extensions.ContextPreservation.3.2.0.0\lib\net45-full\Ninject.Extensions.ContextPreservation.dll - - - ..\packages\Ninject.Extensions.NamedScope.3.2.0.0\lib\net45-full\Ninject.Extensions.NamedScope.dll - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll - - ..\packages\Spring.Core.1.3.2\lib\net40\Spring.Core.dll - @@ -73,7 +47,7 @@ - + @@ -91,4 +65,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/src/NServiceBus.ContainerTests/TestContainerBuilder.cs b/src/NServiceBus.ContainerTests/TestContainerBuilder.cs new file mode 100644 index 0000000000..cd466e6f35 --- /dev/null +++ b/src/NServiceBus.ContainerTests/TestContainerBuilder.cs @@ -0,0 +1,11 @@ +namespace NServiceBus.ContainerTests +{ + using System; + using NServiceBus.ObjectBuilder.Common; + + public static class TestContainerBuilder + { + public static Func ConstructBuilder = () => { return (IContainer)Activator.CreateInstance(Type.GetType("NServiceBus.ObjectBuilder.Autofac.AutofacObjectBuilder,NServiceBus.Core")); }; + + } +} \ No newline at end of file diff --git a/src/NServiceBus.ContainerTests/When_building_components.cs b/src/NServiceBus.ContainerTests/When_building_components.cs new file mode 100644 index 0000000000..cb6889a36d --- /dev/null +++ b/src/NServiceBus.ContainerTests/When_building_components.cs @@ -0,0 +1,184 @@ +namespace NServiceBus.ContainerTests +{ + using NServiceBus; + using NServiceBus.ObjectBuilder.Common; + using NUnit.Framework; + + [TestFixture] + public class When_building_components + { + [Test] + public void Singleton_components_should_yield_the_same_instance() + { + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.AreEqual(builder.Build(typeof(SingletonComponent)), builder.Build(typeof(SingletonComponent))); + } + } + + [Test] + public void Singlecall_components_should_yield_unique_instances() + { + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.AreNotEqual(builder.Build(typeof(SinglecallComponent)), builder.Build(typeof(SinglecallComponent))); + } + } + + [Test] + public void UoW_components_should_resolve_from_main_container() + { + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.NotNull(builder.Build(typeof(InstancePerUoWComponent))); + } + //Not supported by typeof(WindsorObjectBuilder)); + } + + [Test] + public void Lambda_uow_components_should_resolve_from_main_container() + { + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.NotNull(builder.Build(typeof(LambdaComponentUoW))); + } + //Not supported by typeof(WindsorObjectBuilder)); + } + + [Test] + public void Lambda_singlecall_components_should_yield_unique_instances() + { + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.AreNotEqual(builder.Build(typeof(SingleCallLambdaComponent)), builder.Build(typeof(SingleCallLambdaComponent))); + } + } + + [Test] + public void Lambda_singleton_components_should_yield_the_same_instance() + { + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.AreEqual(builder.Build(typeof(SingletonLambdaComponent)), builder.Build(typeof(SingletonLambdaComponent))); + } + } + + [Test] + public void Requesting_an_unregistered_component_should_throw() + { + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.That(() => builder.Build(typeof(UnregisteredComponent)),Throws.Exception); + } + } + + [Test] + public void Should_be_able_to_build_components_registered_after_first_build() + { + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + builder.Build(typeof(SingletonComponent)); + builder.Configure(typeof(UnregisteredComponent), DependencyLifecycle.SingleInstance); + + var unregisteredComponent = builder.Build(typeof(UnregisteredComponent)) as UnregisteredComponent; + Assert.NotNull(unregisteredComponent); + Assert.NotNull(unregisteredComponent.SingletonComponent); + } + //Not supported by,typeof(SpringObjectBuilder)); + } + + [Test] + public void Should_support_mixed_dependency_styles() + { + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + builder.Configure(typeof(ComponentWithBothConstructorAndSetterInjection), DependencyLifecycle.InstancePerCall); + builder.Configure(typeof(ConstructorDependency), DependencyLifecycle.InstancePerCall); + builder.Configure(typeof(SetterDependency), DependencyLifecycle.InstancePerCall); + + var component = (ComponentWithBothConstructorAndSetterInjection) builder.Build(typeof(ComponentWithBothConstructorAndSetterInjection)); + Assert.NotNull(component.ConstructorDependency); + Assert.NotNull(component.SetterDependency); + } + + //Not supported by, typeof(SpringObjectBuilder)); + } + + + void InitializeBuilder(IContainer container) + { + container.Configure(typeof(SingletonComponent), DependencyLifecycle.SingleInstance); + container.Configure(typeof(SinglecallComponent), DependencyLifecycle.InstancePerCall); + container.Configure(typeof(InstancePerUoWComponent), DependencyLifecycle.InstancePerUnitOfWork); + container.Configure(() => new SingletonLambdaComponent(), DependencyLifecycle.SingleInstance); + container.Configure(() => new SingleCallLambdaComponent(), DependencyLifecycle.InstancePerCall); + container.Configure(() => new LambdaComponentUoW(), DependencyLifecycle.InstancePerUnitOfWork); + } + + public class SingletonComponent + { + } + + public class SinglecallComponent + { + } + + public class UnregisteredComponent + { + public SingletonComponent SingletonComponent { get; set; } + } + + public class SingletonLambdaComponent + { + } + + public class LambdaComponentUoW + { + } + + public class SingleCallLambdaComponent + { + } + } + + public class StaticFactory + { + public ComponentCreatedByFactory Create() + { + return new ComponentCreatedByFactory(); + } + } + + public class ComponentCreatedByFactory + { + } + + public class ComponentWithBothConstructorAndSetterInjection + { + public ComponentWithBothConstructorAndSetterInjection(ConstructorDependency constructorDependency) + { + ConstructorDependency = constructorDependency; + } + + public ConstructorDependency ConstructorDependency { get; private set; } + + public SetterDependency SetterDependency { get; set; } + } + + public class ConstructorDependency + { + } + + public class SetterDependency + { + } +} \ No newline at end of file diff --git a/src/ObjectBuilder.Tests/When_disposing_the_builder.cs b/src/NServiceBus.ContainerTests/When_disposing_the_builder.cs similarity index 57% rename from src/ObjectBuilder.Tests/When_disposing_the_builder.cs rename to src/NServiceBus.ContainerTests/When_disposing_the_builder.cs index b7498f6e4d..3c58a49286 100644 --- a/src/ObjectBuilder.Tests/When_disposing_the_builder.cs +++ b/src/NServiceBus.ContainerTests/When_disposing_the_builder.cs @@ -1,4 +1,4 @@ -namespace ObjectBuilder.Tests +namespace NServiceBus.ContainerTests { using System; using System.Diagnostics; @@ -6,42 +6,39 @@ namespace ObjectBuilder.Tests using NUnit.Framework; [TestFixture] - public class When_disposing_the_builder : BuilderFixture + public class When_disposing_the_builder { [Test] public void Should_dispose_all_IDisposable_components() { - ForAllBuilders(builder => - { - DisposableComponent.DisposeCalled = false; - AnotherSingletonComponent.DisposeCalled = false; + var builder = TestContainerBuilder.ConstructBuilder(); + DisposableComponent.DisposeCalled = false; + AnotherSingletonComponent.DisposeCalled = false; - builder.Configure(typeof(DisposableComponent), DependencyLifecycle.SingleInstance); - builder.RegisterSingleton(typeof(AnotherSingletonComponent), new AnotherSingletonComponent()); + builder.Configure(typeof(DisposableComponent), DependencyLifecycle.SingleInstance); + builder.RegisterSingleton(typeof(AnotherSingletonComponent), new AnotherSingletonComponent()); - builder.Build(typeof(DisposableComponent)); - builder.Build(typeof(AnotherSingletonComponent)); - builder.Dispose(); + builder.Build(typeof(DisposableComponent)); + builder.Build(typeof(AnotherSingletonComponent)); + builder.Dispose(); - Assert.True(DisposableComponent.DisposeCalled, "Dispose should be called on DisposableComponent"); - Assert.True(AnotherSingletonComponent.DisposeCalled, "Dispose should be called on AnotherSingletonComponent"); - }); + Assert.True(DisposableComponent.DisposeCalled, "Dispose should be called on DisposableComponent"); + Assert.True(AnotherSingletonComponent.DisposeCalled, "Dispose should be called on AnotherSingletonComponent"); } + [Test] public void When_circular_ref_exists_between_container_and_builder_should_not_infinite_loop() { - ForAllBuilders(builder => - { - Debug.WriteLine("Trying " + builder.GetType().Name); - builder.RegisterSingleton(builder.GetType(), builder); - builder.Dispose(); - }); + var builder = TestContainerBuilder.ConstructBuilder(); + Debug.WriteLine("Trying " + builder.GetType().Name); + builder.RegisterSingleton(builder.GetType(), builder); + builder.Dispose(); } [Test] public void Should_dispose_all_IDisposable_components_in_child_container() { - ForAllBuilders(main => + using (var main = TestContainerBuilder.ConstructBuilder()) { DisposableComponent.DisposeCalled = false; AnotherSingletonComponent.DisposeCalled = false; @@ -53,10 +50,11 @@ public void Should_dispose_all_IDisposable_components_in_child_container() { builder.Build(typeof(DisposableComponent)); } - Assert.False(AnotherSingletonComponent.DisposeCalled, "Dispose should not be called on AnotherSingletonComponent because it belongs to main container"); Assert.True(DisposableComponent.DisposeCalled, "Dispose should be called on DisposableComponent"); - });//Not supported by, typeof(SpringObjectBuilder)); + } + + //Not supported by, typeof(SpringObjectBuilder)); } public class DisposableComponent : IDisposable diff --git a/src/ObjectBuilder.Tests/When_querying_for_registered_components.cs b/src/NServiceBus.ContainerTests/When_querying_for_registered_components.cs similarity index 55% rename from src/ObjectBuilder.Tests/When_querying_for_registered_components.cs rename to src/NServiceBus.ContainerTests/When_querying_for_registered_components.cs index 481acd2f4d..e93099028d 100644 --- a/src/ObjectBuilder.Tests/When_querying_for_registered_components.cs +++ b/src/NServiceBus.ContainerTests/When_querying_for_registered_components.cs @@ -1,41 +1,46 @@ -namespace ObjectBuilder.Tests +namespace NServiceBus.ContainerTests { - using System; using NServiceBus; using NServiceBus.ObjectBuilder.Common; using NUnit.Framework; [TestFixture] - public class When_querying_for_registered_components : BuilderFixture + public class When_querying_for_registered_components { [Test] public void Existing_components_should_return_true() { - ForAllBuilders(builder => - Assert.True(builder.HasComponent(typeof(ExistingComponent)))); + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.True(builder.HasComponent(typeof(ExistingComponent))); + } } [Test] public void Non_existing_components_should_return_false() { - ForAllBuilders(builder => - Assert.False(builder.HasComponent(typeof(NonExistingComponent)))); + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.False(builder.HasComponent(typeof(NonExistingComponent))); + } } [Test] public void Builders_should_not_determine_existence_by_building_components() { - ForAllBuilders(builder => - Assert.True(builder.HasComponent(typeof(ExistingComponentWithUnsatisfiedDependency)))); + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + InitializeBuilder(builder); + Assert.True(builder.HasComponent(typeof(ExistingComponentWithUnsatisfiedDependency))); + } } - protected override Action InitializeBuilder() + void InitializeBuilder(IContainer c) { - return c => - { - c.Configure(typeof(ExistingComponent), DependencyLifecycle.InstancePerCall); - c.Configure(typeof(ExistingComponentWithUnsatisfiedDependency), DependencyLifecycle.InstancePerCall); - }; + c.Configure(typeof(ExistingComponent), DependencyLifecycle.InstancePerCall); + c.Configure(typeof(ExistingComponentWithUnsatisfiedDependency), DependencyLifecycle.InstancePerCall); } public class NonExistingComponent diff --git a/src/ObjectBuilder.Tests/When_registering_components.cs b/src/NServiceBus.ContainerTests/When_registering_components.cs similarity index 72% rename from src/ObjectBuilder.Tests/When_registering_components.cs rename to src/NServiceBus.ContainerTests/When_registering_components.cs index 3efeea9cbd..918e28de85 100644 --- a/src/ObjectBuilder.Tests/When_registering_components.cs +++ b/src/NServiceBus.ContainerTests/When_registering_components.cs @@ -1,4 +1,4 @@ -namespace ObjectBuilder.Tests +namespace NServiceBus.ContainerTests { using System; using System.Collections; @@ -8,77 +8,76 @@ namespace ObjectBuilder.Tests using NUnit.Framework; [TestFixture] - public class When_registering_components : BuilderFixture + public class When_registering_components { [Test] public void Multiple_registrations_of_the_same_component_should_be_allowed() { - - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(DuplicateClass), DependencyLifecycle.InstancePerCall); builder.Configure(typeof(DuplicateClass), DependencyLifecycle.InstancePerCall); Assert.AreEqual(1, builder.BuildAll(typeof(DuplicateClass)).Count()); - }); + } } [Test] public void Should_support_lambdas_that_uses_other_components_registered_later() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { - builder.Configure(() => ((StaticFactory)builder.Build(typeof(StaticFactory))).Create(), DependencyLifecycle.InstancePerCall); + builder.Configure(() => ((StaticFactory) builder.Build(typeof(StaticFactory))).Create(), DependencyLifecycle.InstancePerCall); builder.Configure(() => new StaticFactory(), DependencyLifecycle.SingleInstance); Assert.NotNull(builder.Build(typeof(ComponentCreatedByFactory))); - }); + } } [Test] public void A_registration_should_be_allowed_to_be_updated() { - - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.RegisterSingleton(typeof(ISingletonComponent), new SingletonComponent()); builder.RegisterSingleton(typeof(ISingletonComponent), new AnotherSingletonComponent()); Assert.IsInstanceOf(builder.Build(typeof(ISingletonComponent))); - });//Not supported by, typeof(SpringObjectBuilder)); + } + + //Not supported by, typeof(SpringObjectBuilder)); } [Test] [Explicit] public void A_registration_should_update_default_component_for_interface() { - - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(SomeClass), DependencyLifecycle.InstancePerCall); builder.Configure(typeof(SomeOtherClass), DependencyLifecycle.InstancePerCall); Assert.IsInstanceOf(builder.Build(typeof(ISomeInterface))); - }); + } } [Test] public void Register_singleton_should_be_supported() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { var singleton = new SingletonComponent(); builder.RegisterSingleton(typeof(ISingletonComponent), singleton); builder.RegisterSingleton(typeof(SingletonComponent), singleton); Assert.AreEqual(builder.Build(typeof(SingletonComponent)), singleton); Assert.AreEqual(builder.Build(typeof(ISingletonComponent)), singleton); - }); + } } [Test] public void Registering_the_same_singleton_for_different_interfaces_should_be_supported() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { var singleton = new SingletonThatImplementsToInterfaces(); builder.RegisterSingleton(typeof(ISingleton1), singleton); @@ -86,20 +85,22 @@ public void Registering_the_same_singleton_for_different_interfaces_should_be_su builder.Configure(typeof(ComponentThatDependsOnMultiSingletons), DependencyLifecycle.InstancePerCall); - var dependency = (ComponentThatDependsOnMultiSingletons)builder.Build(typeof (ComponentThatDependsOnMultiSingletons)); + var dependency = (ComponentThatDependsOnMultiSingletons) builder.Build(typeof(ComponentThatDependsOnMultiSingletons)); - Assert.NotNull(dependency.Singleton1); + Assert.NotNull(dependency.Singleton1); Assert.NotNull(dependency.Singleton2); Assert.AreEqual(builder.Build(typeof(ISingleton1)), singleton); Assert.AreEqual(builder.Build(typeof(ISingleton2)), singleton); - });//Not supported by,typeof(SpringObjectBuilder)); + } + + //Not supported by,typeof(SpringObjectBuilder)); } [Test] public void Properties_set_on_duplicate_registrations_should_not_be_discarded() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(DuplicateClass), DependencyLifecycle.SingleInstance); builder.ConfigureProperty(typeof(DuplicateClass), "SomeProperty", true); @@ -107,34 +108,32 @@ public void Properties_set_on_duplicate_registrations_should_not_be_discarded() builder.Configure(typeof(DuplicateClass), DependencyLifecycle.SingleInstance); builder.ConfigureProperty(typeof(DuplicateClass), "AnotherProperty", true); - var component = (DuplicateClass)builder.Build(typeof(DuplicateClass)); - + var component = (DuplicateClass) builder.Build(typeof(DuplicateClass)); Assert.True(component.SomeProperty); Assert.True(component.AnotherProperty); - }); + } } [Test] public void Properties_configured_multiple_times_should_retain_only_the_last_configuration() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(DuplicateClass), DependencyLifecycle.SingleInstance); builder.ConfigureProperty(typeof(DuplicateClass), "SomeProperty", false); builder.ConfigureProperty(typeof(DuplicateClass), "SomeProperty", true); // this should remove/override the previous property setting var component = (DuplicateClass) builder.Build(typeof(DuplicateClass)); - Assert.True(component.SomeProperty); - }); + } } [Test] public void Setter_dependencies_should_be_supported() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(SomeClass), DependencyLifecycle.InstancePerCall); builder.Configure(typeof(ClassWithSetterDependencies), DependencyLifecycle.SingleInstance); @@ -142,66 +141,63 @@ public void Setter_dependencies_should_be_supported() builder.ConfigureProperty(typeof(ClassWithSetterDependencies), "SimpleDependency", 1); builder.ConfigureProperty(typeof(ClassWithSetterDependencies), "StringDependency", "Test"); - var component = (ClassWithSetterDependencies)builder.Build(typeof(ClassWithSetterDependencies)); - + var component = (ClassWithSetterDependencies) builder.Build(typeof(ClassWithSetterDependencies)); Assert.AreEqual(component.EnumDependency, SomeEnum.X); Assert.AreEqual(component.SimpleDependency, 1); Assert.AreEqual(component.StringDependency, "Test"); Assert.NotNull(component.ConcreteDependency, "Concrete classed should be property injected"); Assert.NotNull(component.InterfaceDependency, "Interfaces should be property injected"); Assert.NotNull(component.concreteDependencyWithSetOnly, "Set only properties should be supported"); - }); + } } [Test] public void Setter_dependencies_should_override_container_defaults() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(SomeClass), DependencyLifecycle.InstancePerCall); builder.Configure(typeof(ClassWithSetterDependencies), DependencyLifecycle.SingleInstance); builder.ConfigureProperty(typeof(ClassWithSetterDependencies), "InterfaceDependency", new SomeOtherClass()); - var component = (ClassWithSetterDependencies)builder.Build(typeof(ClassWithSetterDependencies)); - + var component = (ClassWithSetterDependencies) builder.Build(typeof(ClassWithSetterDependencies)); Assert.IsInstanceOf(typeof(SomeOtherClass), component.InterfaceDependency, "Explicitly set dependency should be injected, not container's default type"); - }); + } } [Test] public void Concrete_classes_should_get_the_same_lifecycle_as_their_interfaces() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(SingletonComponent), DependencyLifecycle.SingleInstance); Assert.AreSame(builder.Build(typeof(SingletonComponent)), builder.Build(typeof(ISingletonComponent))); - }); + } } [Test] public void All_implemented_interfaces_should_be_registered() { - ForAllBuilders(builder => - { - builder.Configure(typeof (ComponentWithMultipleInterfaces), - DependencyLifecycle.InstancePerCall); + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + builder.Configure(typeof(ComponentWithMultipleInterfaces), + DependencyLifecycle.InstancePerCall); - Assert.True(builder.HasComponent(typeof (ISomeInterface))); + Assert.True(builder.HasComponent(typeof(ISomeInterface))); - Assert.True(builder.HasComponent(typeof (ISomeOtherInterface))); + Assert.True(builder.HasComponent(typeof(ISomeOtherInterface))); - Assert.True(builder.HasComponent(typeof (IYetAnotherInterface))); + Assert.True(builder.HasComponent(typeof(IYetAnotherInterface))); - Assert.AreEqual(1, builder.BuildAll(typeof (IYetAnotherInterface)).Count()); - } - ); + Assert.AreEqual(1, builder.BuildAll(typeof(IYetAnotherInterface)).Count()); + } } [Test] public void All_implemented_interfaces_should_be_registered_for_func() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(() => new ComponentWithMultipleInterfaces(), DependencyLifecycle.InstancePerCall); @@ -209,14 +205,15 @@ public void All_implemented_interfaces_should_be_registered_for_func() Assert.True(builder.HasComponent(typeof(ISomeOtherInterface))); Assert.True(builder.HasComponent(typeof(IYetAnotherInterface))); Assert.AreEqual(1, builder.BuildAll(typeof(IYetAnotherInterface)).Count()); - }); + } + //Not supported bytypeof(SpringObjectBuilder)); } [Test] public void Multiple_implementations_should_be_supported() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(SomeClass), DependencyLifecycle.InstancePerUnitOfWork); builder.Configure(typeof(SomeOtherClass), DependencyLifecycle.InstancePerUnitOfWork); @@ -229,54 +226,52 @@ public void Multiple_implementations_should_be_supported() Assert.NotNull(childBuilder.Build(typeof(SomeClass))); Assert.AreEqual(2, childBuilder.BuildAll(typeof(ISomeInterface)).Count()); } - }); + } //Not supported by,typeof(WindsorObjectBuilder)); } [Test] public void Given_lookupType_should_be_used_as_service_in_the_registration_when_RegisterSingleton() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + var expected = new InheritedFromSomeClass(); + builder.RegisterSingleton(typeof(SomeClass), expected); + + Assert.NotNull(builder.Build(typeof(SomeClass))); + Assert.AreEqual(expected, builder.Build(typeof(SomeClass))); + + using (var childBuilder = builder.BuildChildContainer()) { - var expected = new InheritedFromSomeClass(); - builder.RegisterSingleton(typeof (SomeClass), expected); - - Assert.NotNull(builder.Build(typeof (SomeClass))); - Assert.AreEqual(expected, builder.Build(typeof (SomeClass))); - - using (var childBuilder = builder.BuildChildContainer()) - { - Assert.NotNull(childBuilder.Build(typeof (SomeClass))); - Assert.AreEqual(expected, childBuilder.Build(typeof (SomeClass))); - } - }); + Assert.NotNull(childBuilder.Build(typeof(SomeClass))); + Assert.AreEqual(expected, childBuilder.Build(typeof(SomeClass))); + } + } } [Test] public void Generic_interfaces_should_be_registered() { - ForAllBuilders(builder => - { - builder.Configure(typeof (ComponentWithGenericInterface), - DependencyLifecycle.InstancePerCall); - - Assert.True(builder.HasComponent(typeof (ISomeGenericInterface))); - } - ); + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + builder.Configure(typeof(ComponentWithGenericInterface), + DependencyLifecycle.InstancePerCall); + + Assert.True(builder.HasComponent(typeof(ISomeGenericInterface))); + } } [Test, Ignore("Not sure that we should enforce this")] public void System_interfaces_should_not_be_auto_registered() { - ForAllBuilders(builder => - { - builder.Configure(typeof (ComponentWithSystemInterface), - DependencyLifecycle.InstancePerCall); - - Assert.False(builder.HasComponent(typeof (IGrouping))); - Assert.False(builder.HasComponent(typeof (IDisposable))); - } - ); + using (var builder = TestContainerBuilder.ConstructBuilder()) + { + builder.Configure(typeof(ComponentWithSystemInterface), + DependencyLifecycle.InstancePerCall); + + Assert.False(builder.HasComponent(typeof(IGrouping))); + Assert.False(builder.HasComponent(typeof(IDisposable))); + } } } @@ -354,7 +349,12 @@ public class ClassWithSetterDependencies public string StringDependency { get; set; } public ISomeInterface InterfaceDependency { get; set; } public SomeClass ConcreteDependency { get; set; } - public SomeClass ConcreteDependencyWithSetOnly { set { concreteDependencyWithSetOnly = value; } } + + public SomeClass ConcreteDependencyWithSetOnly + { + set { concreteDependencyWithSetOnly = value; } + } + public SomeClass ConcreteDependencyWithPrivateSet { get; private set; } public SomeClass concreteDependencyWithSetOnly; @@ -380,4 +380,4 @@ public enum SomeEnum { X } -} +} \ No newline at end of file diff --git a/src/ObjectBuilder.Tests/When_releasing_components.cs b/src/NServiceBus.ContainerTests/When_releasing_components.cs similarity index 81% rename from src/ObjectBuilder.Tests/When_releasing_components.cs rename to src/NServiceBus.ContainerTests/When_releasing_components.cs index 18e1681657..4b96e8f656 100644 --- a/src/ObjectBuilder.Tests/When_releasing_components.cs +++ b/src/NServiceBus.ContainerTests/When_releasing_components.cs @@ -1,16 +1,16 @@ -namespace ObjectBuilder.Tests +namespace NServiceBus.ContainerTests { using System; using NServiceBus; using NUnit.Framework; [TestFixture] - public class When_releasing_components : BuilderFixture + public class When_releasing_components { [Test] public void Transient_component_should_be_destructed_called() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(TransientClass), DependencyLifecycle.InstancePerCall); @@ -20,7 +20,6 @@ public void Transient_component_should_be_destructed_called() var weak = new WeakReference(comp); builder.Release(comp); - // ReSharper disable once RedundantAssignment comp = null; @@ -29,10 +28,11 @@ public void Transient_component_should_be_destructed_called() Assert.IsFalse(weak.IsAlive); Assert.IsTrue(TransientClass.Destructed); - });//Not supported by typeof(AutofacObjectBuilder)); + } + } - public class TransientClass + public class TransientClass { public static bool Destructed; diff --git a/src/ObjectBuilder.Tests/When_using_nested_containers.cs b/src/NServiceBus.ContainerTests/When_using_nested_containers.cs similarity index 75% rename from src/ObjectBuilder.Tests/When_using_nested_containers.cs rename to src/NServiceBus.ContainerTests/When_using_nested_containers.cs index 76aacf4b77..f2f44e8438 100644 --- a/src/ObjectBuilder.Tests/When_using_nested_containers.cs +++ b/src/NServiceBus.ContainerTests/When_using_nested_containers.cs @@ -1,100 +1,94 @@ -namespace ObjectBuilder.Tests +namespace NServiceBus.ContainerTests { using System; using System.Diagnostics; using System.Threading.Tasks; using NServiceBus; - using NServiceBus.ObjectBuilder.Autofac; using NUnit.Framework; [TestFixture] - public class When_using_nested_containers : BuilderFixture + public class When_using_nested_containers { [Test] public void Instance_per_uow__components_should_be_disposed_when_the_child_container_is_disposed() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(InstancePerUoWComponent), DependencyLifecycle.InstancePerUnitOfWork); using (var nestedContainer = builder.BuildChildContainer()) nestedContainer.Build(typeof(InstancePerUoWComponent)); - Assert.True(InstancePerUoWComponent.DisposeCalled); - }); + } //Not supported bytypeof(SpringObjectBuilder)); } [Test] public void Instance_per_uow__components_should_not_be_shared_across_child_containers() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(InstancePerUoWComponent), DependencyLifecycle.InstancePerUnitOfWork); - var task1 = - Task.Factory.StartNew( - () => - { - using (var childContainer = builder.BuildChildContainer()) - { - return childContainer.Build(typeof(InstancePerUoWComponent)); - } - }); - var task2 = - Task.Factory.StartNew( - () => - { - using (var childContainer = builder.BuildChildContainer()) - { - return childContainer.Build(typeof(InstancePerUoWComponent)); - } - }); - + var task1 = Task.Factory.StartNew(() => + { + using (var childContainer = builder.BuildChildContainer()) + { + return childContainer.Build(typeof(InstancePerUoWComponent)); + } + }); + var task2 = Task.Factory.StartNew(() => + { + using (var childContainer = builder.BuildChildContainer()) + { + return childContainer.Build(typeof(InstancePerUoWComponent)); + } + }); Assert.AreNotSame(task1.Result, task2.Result); + } + - }); //Not supported bytypeof(SpringObjectBuilder)); } [Test] public void Instance_per_call_components_should_not_be_shared_across_child_containers() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(InstancePerCallComponent), DependencyLifecycle.InstancePerCall); - object instance1, instance2; + object instance1; using (var nestedContainer = builder.BuildChildContainer()) { instance1 = nestedContainer.Build(typeof(InstancePerCallComponent)); } + object instance2; using (var anotherNestedContainer = builder.BuildChildContainer()) { instance2 = anotherNestedContainer.Build(typeof(InstancePerCallComponent)); } - Assert.AreNotSame(instance1, instance2); - }); + } + } [Test, Explicit("Time consuming")] public void Instance_per_call_components_should_not_cause_memory_leaks() { - //const int iterations = 1000000; const int iterations = 20000; - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(InstancePerCallComponent), DependencyLifecycle.InstancePerUnitOfWork); GC.Collect(); var before = GC.GetTotalMemory(true); var sw = Stopwatch.StartNew(); - + for (var i = 0; i < iterations; i++) { using (var nestedContainer = builder.BuildChildContainer()) @@ -102,7 +96,7 @@ public void Instance_per_call_components_should_not_cause_memory_leaks() nestedContainer.Build(typeof(InstancePerCallComponent)); } } - + sw.Stop(); // Collect all generations of memory. GC.Collect(); @@ -110,30 +104,33 @@ public void Instance_per_call_components_should_not_cause_memory_leaks() var after = GC.GetTotalMemory(true); Console.WriteLine("{0} Time: {1} MemDelta: {2} bytes", builder.GetType().Name, sw.Elapsed, after - before); - var upperLimitBytes = 200 * 1024; - Assert.That(after-before, Is.LessThan(upperLimitBytes), "Apparently {0} consumed more than {1} KB of memory", builder, upperLimitBytes/1024); - });//Not supported by, typeof(NinjectObjectBuilder)); + var upperLimitBytes = 200*1024; + Assert.That(after - before, Is.LessThan(upperLimitBytes), "Apparently {0} consumed more than {1} KB of memory", builder, upperLimitBytes/1024); + } + + //Not supported by, typeof(NinjectObjectBuilder)); } [Test] public void UoW_components_in_the_parent_container_should_be_singletons_in_the_child_container() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(InstancePerUoWComponent), DependencyLifecycle.InstancePerUnitOfWork); using (var nestedContainer = builder.BuildChildContainer()) { - Assert.AreSame(nestedContainer.Build(typeof(InstancePerUoWComponent)), nestedContainer.Build(typeof(InstancePerUoWComponent)),"UoW's should be singleton in child container"); + Assert.AreSame(nestedContainer.Build(typeof(InstancePerUoWComponent)), nestedContainer.Build(typeof(InstancePerUoWComponent)), "UoW's should be singleton in child container"); } - }); + } //Not supported bytypeof(SpringObjectBuilder)); } [Test] + [Explicit] public void UoW_components_should_by_instance_per_call_in_root_container() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { builder.Configure(typeof(InstancePerUoWComponent), DependencyLifecycle.InstancePerUnitOfWork); @@ -143,13 +140,15 @@ public void UoW_components_should_by_instance_per_call_in_root_container() } Assert.AreNotSame(builder.Build(typeof(InstancePerUoWComponent)), builder.Build(typeof(InstancePerUoWComponent)), "UoW's should be instance per call in the root container"); - },typeof(AutofacObjectBuilder)); + } + //Not supported by typeof(AutofacObjectBuilder), typeof(WindsorObjectBuilder)); } + [Test] public void Should_not_dispose_singletons_when_container_goes_out_of_scope() { - ForAllBuilders(builder => + using (var builder = TestContainerBuilder.ConstructBuilder()) { var singletonInMainContainer = new SingletonComponent(); @@ -160,9 +159,8 @@ public void Should_not_dispose_singletons_when_container_goes_out_of_scope() { nestedContainer.Build(typeof(ComponentThatDependsOfSingleton)); } - Assert.False(SingletonComponent.DisposeCalled); - }); + } //Not supported by typeof(SpringObjectBuilder)); } @@ -211,4 +209,4 @@ public class AnotherSingletonComponent : ISingletonComponent public interface ISingletonComponent { } -} +} \ No newline at end of file diff --git a/src/NServiceBus.ContainerTests/packages.config b/src/NServiceBus.ContainerTests/packages.config new file mode 100644 index 0000000000..ebb6744b72 --- /dev/null +++ b/src/NServiceBus.ContainerTests/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/NServiceBus.Core/Audit/DefaultMessageAuditer.cs b/src/NServiceBus.Core/Audit/DefaultMessageAuditer.cs index 4350b7c329..472747f26d 100644 --- a/src/NServiceBus.Core/Audit/DefaultMessageAuditer.cs +++ b/src/NServiceBus.Core/Audit/DefaultMessageAuditer.cs @@ -1,9 +1,28 @@ namespace NServiceBus.Transports { + using System; + using NServiceBus.ObjectBuilder; using Support; using Unicast; - class DefaultMessageAuditer : IAuditMessages + class AuditerWrapper : IAuditMessages + { + readonly IBuilder builder; + + public Type AuditerImplType { get; set; } + + public AuditerWrapper(IBuilder builder) + { + this.builder = builder; + } + + public void Audit(SendOptions sendOptions, TransportMessage message) + { + ((dynamic)builder.Build(AuditerImplType)).Audit(sendOptions, message); + } + } + + class DefaultMessageAuditer { public ISendMessages MessageSender { get; set; } @@ -45,6 +64,9 @@ public void Customize(BusConfiguration configuration) { configuration.RegisterComponents(c => c.ConfigureComponent(DependencyLifecycle.InstancePerCall) .ConfigureProperty(t => t.EndpointName, configuration.Settings.EndpointName())); + + configuration.RegisterComponents(c => c.ConfigureComponent(DependencyLifecycle.InstancePerCall) + .ConfigureProperty(t => t.AuditerImplType, typeof(DefaultMessageAuditer))); } } } diff --git a/src/NServiceBus.Core/InternalsVisibleTo.cs b/src/NServiceBus.Core/InternalsVisibleTo.cs index 7e523e3357..6b43d8973a 100644 --- a/src/NServiceBus.Core/InternalsVisibleTo.cs +++ b/src/NServiceBus.Core/InternalsVisibleTo.cs @@ -2,6 +2,5 @@ [assembly: InternalsVisibleTo("NServiceBus.Hosting.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dde965e6172e019ac82c2639ffe494dd2e7dd16347c34762a05732b492e110f2e4e2e1b5ef2d85c848ccfb671ee20a47c8d1376276708dc30a90ff1121b647ba3b7259a6bc383b2034938ef0e275b58b920375ac605076178123693c6c4f1331661a62eba28c249386855637780e3ff5f23a6d854700eaa6803ef48907513b92")] [assembly: InternalsVisibleTo("NServiceBus.Core.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")] -[assembly: InternalsVisibleTo("ObjectBuilder.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dde965e6172e019ac82c2639ffe494dd2e7dd16347c34762a05732b492e110f2e4e2e1b5ef2d85c848ccfb671ee20a47c8d1376276708dc30a90ff1121b647ba3b7259a6bc383b2034938ef0e275b58b920375ac605076178123693c6c4f1331661a62eba28c249386855637780e3ff5f23a6d854700eaa6803ef48907513b92")] [assembly: InternalsVisibleTo("NServiceBus.PerformanceTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")] [assembly: InternalsVisibleTo("ReturnToSourceQueue, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dde965e6172e019ac82c2639ffe494dd2e7dd16347c34762a05732b492e110f2e4e2e1b5ef2d85c848ccfb671ee20a47c8d1376276708dc30a90ff1121b647ba3b7259a6bc383b2034938ef0e275b58b920375ac605076178123693c6c4f1331661a62eba28c249386855637780e3ff5f23a6d854700eaa6803ef48907513b92")] diff --git a/src/NServiceBus.Core/Outbox/Outbox.cs b/src/NServiceBus.Core/Outbox/Outbox.cs index d6c1fd7079..95efcbfc05 100644 --- a/src/NServiceBus.Core/Outbox/Outbox.cs +++ b/src/NServiceBus.Core/Outbox/Outbox.cs @@ -79,15 +79,12 @@ protected internal override void Setup(FeatureConfigurationContext context) context.Pipeline.Register(); context.Pipeline.Replace(WellKnownStep.DispatchMessageToTransport, typeof(OutboxSendBehavior), "Sending behavior with a delay sending until all business transactions are committed to the outbox storage"); - context.Container.ConfigureComponent(DependencyLifecycle.InstancePerCall) .ConfigureProperty(t => t.TransactionSettings, new TransactionSettings(context.Settings)); //make the audit use the outbox as well - if (context.Container.HasComponent()) - { - context.Container.ConfigureComponent(DependencyLifecycle.InstancePerCall); - } + context.Container.ConfigureComponent(DependencyLifecycle.InstancePerCall); + context.Container.ConfigureProperty(t => t.AuditerImplType, typeof(OutboxAwareAuditer)); } } diff --git a/src/NServiceBus.Core/Outbox/OutboxAwareAuditer.cs b/src/NServiceBus.Core/Outbox/OutboxAwareAuditer.cs index 4ce5794f5f..239c07d08a 100644 --- a/src/NServiceBus.Core/Outbox/OutboxAwareAuditer.cs +++ b/src/NServiceBus.Core/Outbox/OutboxAwareAuditer.cs @@ -4,7 +4,7 @@ namespace NServiceBus.Outbox using Transports; using Unicast; - class OutboxAwareAuditer:IAuditMessages + class OutboxAwareAuditer { public DefaultMessageAuditer DefaultMessageAuditer { get; set; } @@ -24,7 +24,7 @@ public void Audit( SendOptions sendOptions, TransportMessage message) } else { - DefaultMessageAuditer.Audit(sendOptions,message); + DefaultMessageAuditer.Audit(sendOptions, message); } } } diff --git a/src/NServiceBus.sln b/src/NServiceBus.sln index 47d78eb82e..70137101ff 100644 --- a/src/NServiceBus.sln +++ b/src/NServiceBus.sln @@ -1,15 +1,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +VisualStudioVersion = 12.0.30723.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObjectBuilder.Tests", "ObjectBuilder.Tests\ObjectBuilder.Tests.csproj", "{0A282BF4-0957-4074-8D5E-C2FB8634A3AA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NServiceBus.ContainerTests", "NServiceBus.ContainerTests\NServiceBus.ContainerTests.csproj", "{0A282BF4-0957-4074-8D5E-C2FB8634A3AA}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NServiceBus.Serializers.XML.XsdGenerator", "NServiceBus.Serializers.XML.XsdGenerator\NServiceBus.Serializers.XML.XsdGenerator.csproj", "{85118B5C-6CAA-44B4-87EA-419DC6F4F2FB}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{258A3F0E-FAFA-4C13-9D5A-9E46661B22D2}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ObjectBuilders", "ObjectBuilders", "{A650DE92-3B6D-4228-A1A2-FB06E74C1BD2}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{2904B75F-8F07-4C07-BABC-BC42533B3E75}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{EF5E77D7-74B1-422D-B34E-AED35E19249E}" @@ -231,22 +229,22 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {0A282BF4-0957-4074-8D5E-C2FB8634A3AA} = {A650DE92-3B6D-4228-A1A2-FB06E74C1BD2} + {0A282BF4-0957-4074-8D5E-C2FB8634A3AA} = {2904B75F-8F07-4C07-BABC-BC42533B3E75} {85118B5C-6CAA-44B4-87EA-419DC6F4F2FB} = {EF5E77D7-74B1-422D-B34E-AED35E19249E} - {C4693C58-BB66-4630-984E-313E1BCC2474} = {EF5E77D7-74B1-422D-B34E-AED35E19249E} {DD48B2D0-E996-412D-9157-821ED8B17A9D} = {258A3F0E-FAFA-4C13-9D5A-9E46661B22D2} - {2C8F181B-9BAF-4858-968B-1C16F5DDCFA7} = {258A3F0E-FAFA-4C13-9D5A-9E46661B22D2} - {389628F6-2FB4-4AFF-BACC-16726C44FFA4} = {258A3F0E-FAFA-4C13-9D5A-9E46661B22D2} - {5E51EFBF-329F-4D3A-B86E-CC111697746F} = {258A3F0E-FAFA-4C13-9D5A-9E46661B22D2} - {6A9E04E7-6229-4A3E-B94A-DA168E962B5A} = {2904B75F-8F07-4C07-BABC-BC42533B3E75} - {2F2FBB64-FE67-4204-8E27-E1DB39ED843D} = {2904B75F-8F07-4C07-BABC-BC42533B3E75} {93B2CD66-7860-47A3-A039-B7D778E9A8F4} = {5F77E8FE-0DCB-4E91-8F91-D3C9E767F5EF} {85E813C0-4A94-4946-8B1F-DE1E39AA7D11} = {5F77E8FE-0DCB-4E91-8F91-D3C9E767F5EF} - {79487CAA-C060-49C8-B689-6250C61A46D5} = {5F77E8FE-0DCB-4E91-8F91-D3C9E767F5EF} - {60826589-EB19-46F7-9567-69F46C3668B9} = {5F77E8FE-0DCB-4E91-8F91-D3C9E767F5EF} {8B815173-9AFA-4D95-BAB4-686C298F17DA} = {0284B5E1-7537-462C-983C-B9074C9FAA48} + {2C8F181B-9BAF-4858-968B-1C16F5DDCFA7} = {258A3F0E-FAFA-4C13-9D5A-9E46661B22D2} {7619C202-AE52-45DC-98AF-901DD670F117} = {0284B5E1-7537-462C-983C-B9074C9FAA48} {758357F6-CD31-4337-80C4-BA377FC257AF} = {0284B5E1-7537-462C-983C-B9074C9FAA48} + {6A9E04E7-6229-4A3E-B94A-DA168E962B5A} = {2904B75F-8F07-4C07-BABC-BC42533B3E75} + {C4693C58-BB66-4630-984E-313E1BCC2474} = {EF5E77D7-74B1-422D-B34E-AED35E19249E} + {389628F6-2FB4-4AFF-BACC-16726C44FFA4} = {258A3F0E-FAFA-4C13-9D5A-9E46661B22D2} + {2F2FBB64-FE67-4204-8E27-E1DB39ED843D} = {2904B75F-8F07-4C07-BABC-BC42533B3E75} + {79487CAA-C060-49C8-B689-6250C61A46D5} = {5F77E8FE-0DCB-4E91-8F91-D3C9E767F5EF} + {5E51EFBF-329F-4D3A-B86E-CC111697746F} = {258A3F0E-FAFA-4C13-9D5A-9E46661B22D2} + {60826589-EB19-46F7-9567-69F46C3668B9} = {5F77E8FE-0DCB-4E91-8F91-D3C9E767F5EF} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35;packages\Unity.2.1.505.0\lib\NET35 diff --git a/src/ObjectBuilder.Tests/BuilderFixture.cs b/src/ObjectBuilder.Tests/BuilderFixture.cs deleted file mode 100644 index 92ce3accb0..0000000000 --- a/src/ObjectBuilder.Tests/BuilderFixture.cs +++ /dev/null @@ -1,65 +0,0 @@ -namespace ObjectBuilder.Tests -{ - using System; - using System.Collections.Generic; - using System.Linq; - using NServiceBus.ObjectBuilder.Autofac; - using NUnit.Framework; - using IContainer = NServiceBus.ObjectBuilder.Common.IContainer; - - public class BuilderFixture - { - protected virtual Action InitializeBuilder() - { - //no-op - return c => { }; - } - - IList objectBuilders; - - protected void ForAllBuilders(Action assertion, params Type[] containersToIgnore) - { - foreach (var builder in objectBuilders.Where(b => !containersToIgnore.Contains(b.GetType()))) - { - try - { - assertion(builder); - } - catch (Exception) - { - Console.Out.WriteLine("Assertion failed for builder: {0}", builder.GetType().Name); - throw; - } - } - } - - [SetUp] - public void SetUp() - { - objectBuilders = new List - { - //add all supported builders here - new AutofacObjectBuilder() - }; - - var initialize = InitializeBuilder(); - - foreach (var builder in objectBuilders) - { - initialize(builder); - } - } - - [TearDown] - public void DisposeContainers() - { - if (objectBuilders != null) - { - foreach (var builder in objectBuilders) - { - builder.Dispose(); - } - } - } - } -} \ No newline at end of file diff --git a/src/ObjectBuilder.Tests/When_building_components.cs b/src/ObjectBuilder.Tests/When_building_components.cs deleted file mode 100644 index 5d495ddec5..0000000000 --- a/src/ObjectBuilder.Tests/When_building_components.cs +++ /dev/null @@ -1,153 +0,0 @@ -namespace ObjectBuilder.Tests -{ - using System; - using NServiceBus; - using NServiceBus.ObjectBuilder.Common; - using NUnit.Framework; - - [TestFixture] - public class When_building_components : BuilderFixture - { - [Test] - public void Singleton_components_should_yield_the_same_instance() - { - ForAllBuilders(builder => - Assert.AreEqual(builder.Build(typeof(SingletonComponent)), builder.Build(typeof(SingletonComponent)))); - } - - [Test] - public void Singlecall_components_should_yield_unique_instances() - { - ForAllBuilders(builder => - Assert.AreNotEqual(builder.Build(typeof(SinglecallComponent)), builder.Build(typeof(SinglecallComponent)))); - } - - [Test] - public void UoW_components_should_resolve_from_main_container() - { - ForAllBuilders(builder =>Assert.NotNull(builder.Build(typeof(InstancePerUoWComponent)))); - //Not supported by typeof(WindsorObjectBuilder)); - } - - [Test] - public void Lambda_uow_components_should_resolve_from_main_container() - { - ForAllBuilders(builder => Assert.NotNull(builder.Build(typeof(LambdaComponentUoW)))); - //Not supported by typeof(WindsorObjectBuilder)); - } - - [Test] - public void Lambda_singlecall_components_should_yield_unique_instances() - { - ForAllBuilders(builder => - Assert.AreNotEqual(builder.Build(typeof(SingleCallLambdaComponent)), builder.Build(typeof(SingleCallLambdaComponent)))); - } - - [Test] - public void Lambda_singleton_components_should_yield_the_same_instance() - { - ForAllBuilders(builder => - Assert.AreEqual(builder.Build(typeof(SingletonLambdaComponent)), builder.Build(typeof(SingletonLambdaComponent)))); - } - - [Test] - public void Requesting_an_unregistered_component_should_throw() - { - - ForAllBuilders(builder => - Assert.That(() => builder.Build(typeof(UnregisteredComponent)), - Throws.Exception)); - } - - [Test] - public void Should_be_able_to_build_components_registered_after_first_build() - { - ForAllBuilders(builder => - { - builder.Build(typeof (SingletonComponent)); - builder.Configure(typeof (UnregisteredComponent), DependencyLifecycle.SingleInstance); - - var unregisteredComponent = builder.Build(typeof(UnregisteredComponent)) as UnregisteredComponent; - Assert.NotNull(unregisteredComponent); - Assert.NotNull(unregisteredComponent.SingletonComponent); - }); - //Not supported by,typeof(SpringObjectBuilder)); - } - - [Test] - public void Should_support_mixed_dependency_styles() - { - ForAllBuilders(builder => - { - builder.Configure(typeof(ComponentWithBothConstructorAndSetterInjection), DependencyLifecycle.InstancePerCall); - builder.Configure(typeof(ConstructorDependency), DependencyLifecycle.InstancePerCall); - builder.Configure(typeof(SetterDependency), DependencyLifecycle.InstancePerCall); - - var component = (ComponentWithBothConstructorAndSetterInjection)builder.Build(typeof(ComponentWithBothConstructorAndSetterInjection)); - - Assert.NotNull(component.ConstructorDependency); - Assert.NotNull(component.SetterDependency); - });//Not supported by, typeof(SpringObjectBuilder)); - } - - - protected override Action InitializeBuilder() - { - return config => - { - config.Configure(typeof(SingletonComponent), DependencyLifecycle.SingleInstance); - config.Configure(typeof(SinglecallComponent), DependencyLifecycle.InstancePerCall); - config.Configure(typeof(InstancePerUoWComponent), DependencyLifecycle.InstancePerUnitOfWork); - config.Configure(() => new SingletonLambdaComponent(), DependencyLifecycle.SingleInstance); - config.Configure(() => new SingleCallLambdaComponent(), DependencyLifecycle.InstancePerCall); - config.Configure(() => new LambdaComponentUoW(), DependencyLifecycle.InstancePerUnitOfWork); - }; - } - - public class SingletonComponent - { - } - public class SinglecallComponent - { - } - public class UnregisteredComponent - { - public SingletonComponent SingletonComponent { get; set; } - } - public class SingletonLambdaComponent { } - public class LambdaComponentUoW { } - public class SingleCallLambdaComponent { } - } - - public class StaticFactory - { - public ComponentCreatedByFactory Create() - { - return new ComponentCreatedByFactory(); - } - } - - public class ComponentCreatedByFactory - { - } - - public class ComponentWithBothConstructorAndSetterInjection - { - public ComponentWithBothConstructorAndSetterInjection(ConstructorDependency constructorDependency) - { - ConstructorDependency = constructorDependency; - } - - public ConstructorDependency ConstructorDependency { get; private set; } - - public SetterDependency SetterDependency { get; set; } - } - - public class ConstructorDependency - { - } - - public class SetterDependency - { - } -} diff --git a/src/ObjectBuilder.Tests/packages.config b/src/ObjectBuilder.Tests/packages.config deleted file mode 100644 index cbcdf050ac..0000000000 --- a/src/ObjectBuilder.Tests/packages.config +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file