Skip to content

Commit

Permalink
add tests for TimeToBeReceived
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Feb 4, 2014
1 parent 9b4a76d commit 089cbd4
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Endpoint>(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<DefaultServer>();
}
public class MyMessageHandler : IHandleMessages<MyMessage>
{
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")]

This comment has been minimized.

Copy link
@andreasohlund

andreasohlund Feb 19, 2014

Member

This doesn't seem to work for Rabbit http://builds.particular.net/viewLog.html?buildId=36672&tab=buildResultsDiv&buildTypeId=NServiceBusRabbitMQ_2RunAcceptanceTests

and I know @yvesgoeleven mentioned that it doesn't work for Azure either. Isn't 1 sec to short? (think rabbit discards right away)

public class MyMessage : IMessage
{
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Endpoint>(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<DefaultServer>();
}
public class MyMessageHandler : IHandleMessages<MyMessage>
{
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
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="BasicMessaging\When_using_a_message_with_TimeToBeReceived_has_not_expired.cs" />
<Compile Include="BasicMessaging\When_using_a_message_with_TimeToBeReceived_has_expired.cs" />
<Compile Include="BasicMessaging\When_Deferring_a_message.cs" />
<Compile Include="BusStartStop\When_bus_start_raises_an_inmemory_message.cs" />
<Compile Include="HostInformation\When_a_message_is_received.cs" />
Expand Down

0 comments on commit 089cbd4

Please sign in to comment.