Exemple #1
0
        public void PartialCommandContractWithChannelIdSet()
        {
            int countTotal    = 0;
            int countOutgoing = 0;
            int countResponse = 0;

            var policy = new CommandPolicy()
            {
                ChannelId = "fredo", OutgoingRequestsEnabled = true, ResponseChannelId = "getback"
            };

            var harness = new CommandHarness <CommandHarness1>(policy);

            harness.Start();

            Assert.IsTrue(harness.RegisteredCommandMethods.Count == 2);

            bool ok = false;

            harness
            .Intercept((ctx) => ok = true, CommandHarnessTrafficDirection.Outgoing, ("one", null, null))
            .Intercept((ctx) => Interlocked.Increment(ref countTotal))
            .Intercept((ctx) => Interlocked.Increment(ref countOutgoing), header: ("one", null, null))
            .Intercept((ctx) => Interlocked.Increment(ref countResponse), header: ("getback", null, null))
            .InterceptOutgoing((c) =>
            {
                string rString = null;
                c.RequestPayloadTryGet <string>(out rString);

                c.ResponseSet <string>(200, "over and out", "Hello mum");
            })
            ;

            harness.ScheduleExecute("1");

            harness.Dispatcher.Process(("fredo", "two", "three"), "Helloe");
            harness.Dispatcher.Process(("one", "two"), "Helloe", responseHeader: ("2", "3"));

            Assert.IsTrue(harness.TrafficPayloadOutgoing.Count == 2);
            Assert.IsTrue(ok);
            Assert.IsTrue(countTotal == 7);
            Assert.IsTrue(countOutgoing == 2);
        }