Esempio n. 1
0
        public void Request_Basic()
        {
            SipBasicCore    core = null;
            SipCoreSettings settings;
            SipRequest      request;
            SipResult       result;
            string          serviceUri;

            try
            {
                settings          = new SipCoreSettings();
                settings.UserName = "******";
                settings.Password = "******";

                serviceUri = "sip:" + settings.TransportSettings[0].ExternalBinding.ToString();

                core = new SipBasicCore(settings);
                core.RequestReceived += new SipRequestDelegate(OnRequest);
                core.Start();

                request = new SipRequest(SipMethod.Info, serviceUri, null);
                request.AddHeader("Test", "OK");
                result = core.Request(request);

                Assert.AreEqual(SipStatus.OK, result.Status);
            }
            finally
            {
                if (core != null)
                {
                    core.Stop();
                }
            }
        }
Esempio n. 2
0
        public void SipBasicCore_Request_SetResponse()
        {
            // Verify that we can submit a non-dialog request from
            // one core to another, respond to it by setting the
            // Response property of the RequestReceived handler arguments
            // and then actually receive the response.

            StartCores();

            try
            {
                SipResponse core1Response = null;

                core1.ResponseReceived += delegate(object sender, SipResponseEventArgs args)
                {
                    core1Response = args.Response;
                };

                SipRequest core2Request = null;

                core2.RequestReceived += delegate(object sender, SipRequestEventArgs args)
                {
                    core2Request           = args.Request;
                    args.Response          = core2Request.CreateResponse(SipStatus.OK, "Hello World!");
                    args.Response.Contents = new byte[] { 5, 6, 7, 8 };
                };

                // Submit a request and verify the response.

                SipRequest  request;
                SipResult   result;
                SipResponse response;

                request          = new SipRequest(SipMethod.Info, (string)core2Uri, null);
                request.Contents = new byte[] { 1, 2, 3, 4 };

                result   = core1.Request(request);
                response = result.Response;
                Assert.AreEqual(SipStatus.OK, result.Status);
                Assert.AreEqual(SipStatus.OK, response.Status);
                Assert.AreEqual("Hello World!", response.ReasonPhrase);
                CollectionAssert.AreEqual(new byte[] { 5, 6, 7, 8 }, response.Contents);

                // Verify that the core1 ResponseReceived event handler was called

                Assert.IsNotNull(core1Response);
                Assert.AreEqual(SipStatus.OK, core1Response.Status);
                Assert.AreEqual("Hello World!", core1Response.ReasonPhrase);
                CollectionAssert.AreEqual(new byte[] { 5, 6, 7, 8 }, core1Response.Contents);

                // Verify that the core2 RequestReceived event handler was called

                Assert.IsNotNull(core2Request);
                Assert.AreEqual(SipMethod.Info, core2Request.Method);
                CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4 }, core2Request.Contents);
            }
            finally
            {
                StopCores();
            }
        }