public PublisherWithAuthorizer()
            {
                var defaultServer = new DefaultServer
                {
                    TransportConfiguration = new ConfigureEndpointAcceptanceTestingTransport(false, false),
                };

                EndpointSetup(defaultServer, (endpointConfiguration, descriptor) =>
                {
                    endpointConfiguration.UsePersistence <FakePersistence>();
                    endpointConfiguration.EnableFeature <StorageAccessorFeature>();
                    endpointConfiguration.OnEndpointSubscribed <Context>((args, ctx) =>
                    {
                        if (args.MessageType.Contains(typeof(AllowedEvent).FullName))
                        {
                            ctx.ReceivedAllowedEventSubscriptionMessage = true;
                        }
                        if (args.MessageType.Contains(typeof(ForbiddenEvent).FullName))
                        {
                            ctx.ReceivedForbiddenEventSubscriptionMessage = true;
                        }
                    });

                    var routingSettings =
                        new RoutingSettings <AcceptanceTestingTransport>(endpointConfiguration.GetSettings());
                    routingSettings.SubscriptionAuthorizer(ctx =>
                    {
                        // only allow subscriptions for AllowedEvent:
                        return(ctx.MessageHeaders[Headers.SubscriptionMessageType]
                               .Contains(typeof(AllowedEvent).FullName));
                    });
                });
            }
Exemplo n.º 2
0
 public Publisher()
 {
     EndpointSetup <DefaultServer>(b =>
     {
         var routingSettings = new RoutingSettings <MsmqTransport>(b.GetSettings());
         routingSettings.SubscriptionAuthorizer(Authorizer);
         b.OnEndpointSubscribed <TestContext>((s, context) =>
         {
             context.Subscribed = true;
             if (s.SubscriberReturnAddress.Contains("Subscriber"))
             {
                 context.UnsubscribeAttempted = true;
             }
         });
         b.DisableFeature <AutoSubscribe>();
     });
 }