Exemple #1
0
        public void GlueConfiguredByCodeAndMakeCall_MPX()
        {
            //This is an example of how to use Glue without pre-configured app container
            var app = new TestApplication(){ Active = true };
            var glue = new NFX.Glue.Implementation.GlueService();
            glue.Start();
            try
            {
                using(var binding = new MpxBinding(glue, "mpx"))
                {
                  binding.Start();
                  var cl = new JokeContractClient(glue, TestServerMpxNode);
                  cl.Headers.Add( new AuthenticationHeader( TestCredentials ) );

                  var result = cl.Echo("Gello A!");

                  Assert.IsTrue(result.StartsWith("Server echoed Gello A!"));
                }
            }
            finally
            {
                glue.WaitForCompleteStop();
            }
        }
Exemple #2
0
        public void ScopeExitTest()
        {
            int  n = 1;
            bool b = true;
            string s0 = "ok";

            {
                using (Scope.OnExit(() => n = 1))
                    n = 2;

                Assert.AreEqual(1, n);
            }

            {
                using (Scope.OnExit<int>(n, (x) => n = x))
                    n = 2;

                Assert.AreEqual(1, n);
            }

            {
                using (Scope.OnExit<int,bool>(n, b, (x,y) => {n=x; b=y;}))
                {
                    n = 5;
                    b = false;
                }

                Assert.AreEqual(1, n);
                Assert.AreEqual(true, b);
            }

            {
                using (Scope.OnExit<int,bool,string>(n, b, s0, (x,y,s) => {n=x; b=y; s0=s;}))
                {
                    n = 5;
                    b = false;
                    s0 = "bad";
                }

                Assert.AreEqual(1, n);
                Assert.AreEqual(true, b);
                Assert.AreEqual("ok", s0);
            }

            {
                var text = "Cool scopper!";
                using (var log = new TestMemoryLog())
                using (var app = new TestApplication { Log = log })
                {
                    log.Start();

                    using (new Scope(logText: text, logMsgType: MessageType.Warning, measureTime: true))
                    {
                        for (int i = 0; i < 1000000; i++) ;
                    }

                    Assert.AreEqual(1,      log.Messages.Count);
                    Assert.AreEqual(text,   log.Messages[0].Text);
                    Assert.AreEqual("NFX.NUnit.ScopeTestFixture.ScopeExitTest[ScopeTest.cs",
                                    log.Messages[0].From.TakeWhile(c => c != ':'));
                    Assert.AreEqual("time", log.Messages[0].Parameters.TakeWhile(c => c != '='));
                    Assert.AreEqual(MessageType.Warning, log.Messages[0].Type);
                }
            }
        }