Skip to content

Commit cf7c7b6

Browse files
timbussmannjpalac
authored andcommitted
add test for invalid sendonly usage
1 parent 9447970 commit cf7c7b6

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace ServiceBus.Tests
2+
{
3+
using System;
4+
using NServiceBus.AcceptanceTesting;
5+
using NServiceBus;
6+
using NUnit.Framework;
7+
using System.Threading.Tasks;
8+
9+
public class When_receiving_with_sendonly
10+
{
11+
[TestCase(TransportTransactionMode.ReceiveOnly)]
12+
[TestCase(TransportTransactionMode.SendsAtomicWithReceive)]
13+
public void Should_invoke_the_handler_to_process_it(TransportTransactionMode transactionMode)
14+
{
15+
var exception = Assert.ThrowsAsync<InvalidOperationException>(() => Scenario.Define<ScenarioContext>()
16+
.WithComponent(new FunctionWithSendOnlyConfiguration(transactionMode))
17+
.Done(c => c.EndpointsStarted)
18+
.Run());
19+
20+
StringAssert.Contains("This endpoint cannot process messages because it is configured in send-only mode.", exception.Message);
21+
}
22+
23+
24+
class FunctionWithSendOnlyConfiguration : FunctionEndpointComponent
25+
{
26+
public FunctionWithSendOnlyConfiguration(TransportTransactionMode transactionMode) : base(transactionMode)
27+
{
28+
CustomizeConfiguration = configuration => configuration.AdvancedConfiguration.SendOnly();
29+
30+
Messages.Add(new TestMessage());
31+
}
32+
33+
public class TestMessageHandler : IHandleMessages<TestMessage>
34+
{
35+
public Task Handle(TestMessage message, IMessageHandlerContext context) => Task.CompletedTask;
36+
}
37+
}
38+
39+
class TestMessage : IMessage
40+
{
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)