1+ using System . Threading . Tasks ;
2+ using NServiceBus ;
3+ using NServiceBus . AcceptanceTesting ;
4+ using NUnit . Framework ;
5+ using Conventions = NServiceBus . AcceptanceTesting . Customization . Conventions ;
6+
7+ public class ThreeTransports : BridgeAcceptanceTest
8+ {
9+ [ Test ( Description = "Replicates issue reported in https://github.com/Particular/NServiceBus.MessagingBridge/issues/369" ) ]
10+ public async Task Should_translate_address_correctly_for_target_transport ( )
11+ {
12+ var endpointOnTestingTransportName = Conventions . EndpointNamingConvention ( typeof ( EndpointOnTestingTransport ) ) ;
13+ var endpointOnTransportUnderTestName = Conventions . EndpointNamingConvention ( typeof ( EndpointOnTransportUnderTest ) ) ;
14+
15+ var options = new SendOptions ( ) ;
16+ options . SetDestination ( Conventions . EndpointNamingConvention ( typeof ( ReceivingEndpoint ) ) ) ;
17+
18+ var ctx = await Scenario . Define < Context > ( )
19+ . WithEndpoint < ReceivingEndpoint > ( )
20+ . WithEndpoint < EndpointOnTestingTransport > ( builder => builder
21+ . When ( c => c . EndpointsStarted , ( session , _ ) => session . Send ( new SomeMessage { From = endpointOnTestingTransportName } , options ) ) )
22+ . WithEndpoint < EndpointOnTransportUnderTest > ( builder => builder
23+ . When ( c => c . EndpointsStarted , ( session , _ ) => session . Send ( new SomeMessage { From = endpointOnTransportUnderTestName } , options ) ) )
24+ . WithBridge ( bridgeConfiguration =>
25+ {
26+ bridgeConfiguration . TranslateReplyToAddressForFailedMessages ( ) ;
27+
28+ var receivingTransport = new TestableBridgeTransport ( ReceivingTestServer . GetReceivingTransportDefinition ( ) )
29+ {
30+ Name = "ReceivingTransport"
31+ } ;
32+ receivingTransport . AddTestEndpoint < ReceivingEndpoint > ( ) ;
33+ bridgeConfiguration . AddTransport ( receivingTransport ) ;
34+
35+ var acceptanceTestingTransport = new TestableBridgeTransport ( SendingTestServer . GetSendingTransportDefinition ( ) )
36+ {
37+ Name = "SendingAcceptanceTestingTransportName"
38+ } ;
39+ acceptanceTestingTransport . AddTestEndpoint < EndpointOnTestingTransport > ( ) ;
40+ bridgeConfiguration . AddTransport ( acceptanceTestingTransport ) ;
41+
42+ var transportUnderTest = new TestableBridgeTransport ( TransportBeingTested )
43+ {
44+ Name = "TransportUnderTest"
45+ } ;
46+ transportUnderTest . AddTestEndpoint < EndpointOnTransportUnderTest > ( ) ;
47+ bridgeConfiguration . AddTransport ( transportUnderTest ) ;
48+ } )
49+ . Done ( c => c . ReceivedMessageCount == 2 )
50+ . Run ( ) ;
51+
52+ }
53+
54+ public class ReceivingEndpoint : EndpointConfigurationBuilder
55+ {
56+ public ReceivingEndpoint ( ) => EndpointSetup < ReceivingTestServer > ( ) ;
57+
58+ class SomeMessageHandler ( Context context ) : IHandleMessages < SomeMessage >
59+ {
60+ public Task Handle ( SomeMessage message , IMessageHandlerContext context )
61+ {
62+ Assert . Multiple ( ( ) =>
63+ {
64+ Assert . That ( context . MessageHeaders . TryGetValue ( "NServiceBus.ReplyToAddress" , out var headerValue ) , Is . True ) ;
65+ Assert . That ( headerValue , Is . EqualTo ( message . From ) ) ;
66+ } ) ;
67+
68+ testContext . ReceivedMessageCount ++ ;
69+
70+ return Task . CompletedTask ;
71+ }
72+
73+ readonly Context testContext = context ;
74+ }
75+ }
76+
77+ public class EndpointOnTestingTransport : EndpointConfigurationBuilder
78+ {
79+ public EndpointOnTestingTransport ( ) => EndpointSetup < SendingTestServer > ( ) ;
80+ }
81+
82+ public class EndpointOnTransportUnderTest : EndpointConfigurationBuilder
83+ {
84+ public EndpointOnTransportUnderTest ( ) => EndpointSetup < DefaultServer > ( ) ;
85+ }
86+
87+ public class Context : ScenarioContext
88+ {
89+ public int ReceivedMessageCount { get ; set ; }
90+ }
91+
92+ public class SomeMessage : IMessage
93+ {
94+ public string From { get ; set ; }
95+ }
96+ }
0 commit comments