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