public async Task Should_deliver_the_reply_without_the_need_to_configure_the_hub()
    {
        var result = await Scenario.Define <Context>()
                     .WithComponent(new SwitchComponent(() =>
        {
            var cfg = new SwitchConfiguration();
            cfg.AddPort <TestTransport>("Port1", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());
            cfg.AddPort <TestTransport>("Port2", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());
            cfg.AddPort <TestTransport>("Port3", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());

            cfg.PortTable[Conventions.EndpointNamingConvention(typeof(Sender1))] = "Port1";
            cfg.PortTable[Conventions.EndpointNamingConvention(typeof(Sender2))] = "Port2";
            //Sender3's port is configured manually in Sender2

            return(cfg);
        }))
                     .WithEndpoint <Sender1>(c => c.When(s => s.Send(new MyRequest())))
                     .WithEndpoint <Sender2>(c => c.When(s => s.Send(new MyRequest())))
                     .WithEndpoint <Sender3>(c => c.When(s => s.Send(new MyRequest())))
                     .Done(c => c.Response1Received && c.Response2Received && c.Response3Received)
                     .Run(TimeSpan.FromSeconds(20));

        Assert.IsTrue(result.Request1Received);
        Assert.IsTrue(result.Response1Received);
        Assert.IsTrue(result.Request2Received);
        Assert.IsTrue(result.Response2Received);
        Assert.IsTrue(result.Request3Received);
        Assert.IsTrue(result.Response3Received);
    }
Example #2
0
        /// <summary>
        /// Creates the default configuration.
        /// </summary>
        public void CreateDefaultConfiguration()
        {
            Configuration = new SwitchConfiguration
            {
                EnableSwitchBetweenDesignerAndCodeBehind      = true,
                EnableSwitchBetweenInterfaceAndImplementation = true,
                ExtensionSwitches = new List <ExtensionSwitch>()
            };

            //  C/C++ extensions.
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("c", "h"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("cpp", "h"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("cxx", "h"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("h", "c"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("h", "cpp"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("h", "cxx"));

            //  Add the XAML extensions.
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("xaml", "xaml.cs"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("xaml.cs", "xaml"));

            //  Add the ASPX extensions.
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("master", "master.cs"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("master.cs", "master.designer.cs"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("master.designer.cs", "master"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("asax", "asax.cs"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("asax.cs", "asax"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("aspx", "aspx.cs"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("aspx.cs", "aspx.designer.cs"));
            Configuration.ExtensionSwitches.Add(new ExtensionSwitch("aspx.designer.cs", "aspx"));
        }
Example #3
0
        public ISwitchBuilder Add(string name, Action <ISwitchConfiguration> action = null)
        {
            if (_values.ContainsKey(name))
            {
                _context.CakeContext.LogAndThrow($"Value name {name} already exists for switch {_switchName}");
            }

            ISwitchConfiguration switchConfiguration = new SwitchConfiguration(_context);

            action?.Invoke(switchConfiguration);
            _values.Add(name, switchConfiguration);

            return(this);
        }
    public void ThreeWaySwitch()
    {
        #region bridge-to-router-switch

        var switchConfig = new SwitchConfiguration();
        switchConfig.AddPort <RabbitMQTransport>("A", tx => tx.ConnectionString("host=a"));
        switchConfig.AddPort <RabbitMQTransport>("B", tx => tx.ConnectionString("host=b"));
        switchConfig.AddPort <RabbitMQTransport>("C", tx => tx.ConnectionString("host=c"));

        switchConfig.PortTable["MyEndpoint"]    = "A";
        switchConfig.PortTable["OtherEndpoint"] = "C";

        var @switch = Switch.Create(switchConfig);

        #endregion
    }
Example #5
0
    public async Task It_should_deliver_the_message_to_both_subscribers()
    {
        var result = await Scenario.Define <Context>()
                     .WithComponent(new SwitchComponent(() =>
        {
            var cfg = new SwitchConfiguration();
            cfg.AddPort <TestTransport>("Port1", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());
            cfg.AddPort <TestTransport>("Port2", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());
            cfg.AddPort <TestTransport>("Port3", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());

            cfg.PortTable[Conventions.EndpointNamingConvention(typeof(Publisher))] = "Port1";
            return(cfg);
        }))
                     .WithEndpoint <Publisher>(c => c.When(x => x.BaseEventSubscribed && x.DerivedEventSubscribed, s => s.Publish(new MyDerivedEvent())))
                     .WithEndpoint <BaseEventSubscriber>()
                     .WithEndpoint <DerivedEventSubscriber>()
                     .Done(c => c.BaseEventDelivered && c.DerivedEventDeilvered)
                     .Run(TimeSpan.FromSeconds(20));

        Assert.IsTrue(result.BaseEventDelivered);
        Assert.IsTrue(result.DerivedEventDeilvered);
    }
Example #6
0
    public async Task It_should_deliver_the_message_to_both_subscribers()
    {
        var result = await Scenario.Define <Context>()
                     .WithComponent(new SwitchComponent(() =>
        {
            var cfg = new SwitchConfiguration();

            //Publisher - Broker B. Limit concurrency to ensure when tracer arrives the subscribe request has already been processed.
            cfg.AddPort <TestTransport>("Port1", t => t.ConfigureNativePubSubBrokerB()).LimitMessageProcessingConcurrencyTo(1);

            //BaseEventSubscriber - Broker A
            cfg.AddPort <TestTransport>("Port2", t => t.ConfigureNoNativePubSubBrokerA()).UseSubscriptionPersistence(new InMemorySubscriptionStorage());

            //DerivedEventSubscriber - Broker C`
            cfg.AddPort <TestTransport>("Port3", t => t.ConfigureNativePubSubBrokerC());

            cfg.PortTable[Conventions.EndpointNamingConvention(typeof(Publisher))] = "Port1";
            return(cfg);
        }))
                     .WithEndpoint <Publisher>(c => c.When(x => x.BaseEventSubscribed && x.DerivedEventSubscribed, s => s.Publish(new MyDerivedEvent3())))
                     .WithEndpoint <BaseEventSubscriber>(c => c.When(async s =>
        {
            await s.Subscribe <MyBaseEvent3>().ConfigureAwait(false);
            await s.Send(new TracerMessage()).ConfigureAwait(false);
        }))
                     .WithEndpoint <DerivedEventSubscriber>(c => c.When(async s =>
        {
            await s.Subscribe <MyDerivedEvent3>().ConfigureAwait(false);
            await s.Send(new TracerMessage()).ConfigureAwait(false);
        }))
                     .Done(c => c.BaseEventDelivered && c.DerivedEventDeilvered)
                     .Run();

        Assert.IsTrue(result.BaseEventDelivered);
        Assert.IsTrue(result.DerivedEventDeilvered);
    }
Example #7
0
    static async Task Main()
    {
        Console.Title = "Switch";

        var redSubscriptionStorage = new SqlSubscriptionStorage(() => new SqlConnection(SwitchConnectionString), "Red", new SqlDialect.MsSqlServer(), null);
        await redSubscriptionStorage.Install().ConfigureAwait(false);

        var greenSubscriptionStorage = new SqlSubscriptionStorage(() => new SqlConnection(SwitchConnectionString), "Green", new SqlDialect.MsSqlServer(), null);
        await greenSubscriptionStorage.Install().ConfigureAwait(false);

        #region SwitchConfig

        var switchConfig = new SwitchConfiguration();

        var blueSubscriptionStorage = new SqlSubscriptionStorage(
            () => new SqlConnection(SwitchConnectionString),
            "Blue",
            new SqlDialect.MsSqlServer(),
            null);
        await blueSubscriptionStorage.Install().ConfigureAwait(false);

        switchConfig.AddPort <SqlServerTransport>("Blue", t =>
        {
            t.ConnectionString(ConnectionStrings.Blue);
        }).UseSubscriptionPersistence(blueSubscriptionStorage);


        switchConfig.AddPort <SqlServerTransport>("Red", t =>
        {
            t.ConnectionString(ConnectionStrings.Red);
        }).UseSubscriptionPersistence(redSubscriptionStorage);

        switchConfig.AddPort <SqlServerTransport>("Green", t =>
        {
            t.ConnectionString(ConnectionStrings.Green);
        }).UseSubscriptionPersistence(greenSubscriptionStorage);

        switchConfig.AutoCreateQueues();

        #endregion

        #region SwitchForwarding

        switchConfig.PortTable["Client"]   = "Blue";
        switchConfig.PortTable["Sales"]    = "Red";
        switchConfig.PortTable["Shipping"] = "Red";
        switchConfig.PortTable["Billing"]  = "Green";

        #endregion

        SqlHelper.EnsureDatabaseExists(SwitchConnectionString);
        SqlHelper.EnsureDatabaseExists(ConnectionStrings.Blue);
        SqlHelper.EnsureDatabaseExists(ConnectionStrings.Red);
        SqlHelper.EnsureDatabaseExists(ConnectionStrings.Green);

        var @switch = Switch.Create(switchConfig);

        await @switch.Start().ConfigureAwait(false);

        Console.WriteLine("Press <enter> to exit");
        Console.ReadLine();

        await @switch.Stop().ConfigureAwait(false);
    }
 public SwitchComponent(Func <SwitchConfiguration> config)
 {
     this.config = config();
 }