diff --git a/src/NServiceBus.AcceptanceTests/BasicMessaging/When_using_a_message_with_TimeToBeReceived_has_expired.cs b/src/NServiceBus.AcceptanceTests/BasicMessaging/When_using_a_message_with_TimeToBeReceived_has_expired.cs new file mode 100644 index 00000000000..a2ffe5b215d --- /dev/null +++ b/src/NServiceBus.AcceptanceTests/BasicMessaging/When_using_a_message_with_TimeToBeReceived_has_expired.cs @@ -0,0 +1,62 @@ +namespace NServiceBus.AcceptanceTests.BasicMessaging +{ + using System; + using System.Threading; + using EndpointTemplates; + using AcceptanceTesting; + using NUnit.Framework; + + public class When_using_a_message_with_TimeToBeReceived_has_expired : NServiceBusAcceptanceTest + { + [Test] + public void Message_should_not_be_received() + { + var context = new Context(); + + var timeToWaitFor = DateTime.Now.AddSeconds(10); + Scenario.Define(context) + .WithEndpoint(b => b.Given((bus, c) => bus.SendLocal(new MyMessage()))) + .Done(c => DateTime.Now > timeToWaitFor ) + .Run(); + Assert.IsFalse(context.WasCalled); + } + + public class Context : ScenarioContext + { + public bool WasCalled { get; set; } + } + + public class Endpoint : EndpointConfigurationBuilder + { + public Endpoint() + { + EndpointSetup(); + } + public class MyMessageHandler : IHandleMessages + { + static bool hasSkipped; + public Context Context { get; set; } + + public IBus Bus { get; set; } + + public void Handle(MyMessage message) + { + if (!hasSkipped) + { + hasSkipped = true; + Thread.Sleep(TimeSpan.FromSeconds(2)); + Bus.HandleCurrentMessageLater(); + return; + } + Context.WasCalled = true; + } + } + } + + [Serializable] + [TimeToBeReceived("00:00:01")] + public class MyMessage : IMessage + { + } + } +} diff --git a/src/NServiceBus.AcceptanceTests/BasicMessaging/When_using_a_message_with_TimeToBeReceived_has_not_expired.cs b/src/NServiceBus.AcceptanceTests/BasicMessaging/When_using_a_message_with_TimeToBeReceived_has_not_expired.cs new file mode 100644 index 00000000000..a516e51daa8 --- /dev/null +++ b/src/NServiceBus.AcceptanceTests/BasicMessaging/When_using_a_message_with_TimeToBeReceived_has_not_expired.cs @@ -0,0 +1,53 @@ +namespace NServiceBus.AcceptanceTests.BasicMessaging +{ + using System; + using EndpointTemplates; + using AcceptanceTesting; + using NUnit.Framework; + + public class When_using_a_message_with_TimeToBeReceived_has_not_expired : NServiceBusAcceptanceTest + { + [Test] + public void Message_should_be_received() + { + var context = new Context(); + + Scenario.Define(context) + .WithEndpoint(b => b.Given((bus, c) => bus.SendLocal(new MyMessage()))) + .Done(c => c.WasCalled) + .Run(); + + Assert.IsTrue(context.WasCalled); + } + + public class Context : ScenarioContext + { + public bool WasCalled { get; set; } + } + + public class Endpoint : EndpointConfigurationBuilder + { + public Endpoint() + { + EndpointSetup(); + } + public class MyMessageHandler : IHandleMessages + { + public Context Context { get; set; } + + public IBus Bus { get; set; } + + public void Handle(MyMessage message) + { + Context.WasCalled = true; + } + } + } + + [Serializable] + [TimeToBeReceived("00:00:10")] + public class MyMessage : IMessage + { + } + } +} diff --git a/src/NServiceBus.AcceptanceTests/NServiceBus.AcceptanceTests.csproj b/src/NServiceBus.AcceptanceTests/NServiceBus.AcceptanceTests.csproj index f3a338f5561..dc3276c7b1c 100644 --- a/src/NServiceBus.AcceptanceTests/NServiceBus.AcceptanceTests.csproj +++ b/src/NServiceBus.AcceptanceTests/NServiceBus.AcceptanceTests.csproj @@ -100,6 +100,8 @@ + +