Esempio n. 1
0
        /// <summary>
        /// Creates a <see cref="SipRoutingClient" /> with the token credential
        /// and instruments it to make use of the Azure Core Test Framework functionalities.
        /// </summary>
        /// <returns>The instrumented <see cref="SipRoutingClient" />.</returns>
        protected SipRoutingClient CreateClientWithTokenCredential(bool isInstrumented = true)
        {
            var client = new SipRoutingClient(
                new Uri(ConnectionString.Parse(TestEnvironment.LiveTestStaticConnectionString, allowEmptyValues: true).GetRequired("endpoint")),
                (Mode == RecordedTestMode.Playback) ? new MockCredential() : new DefaultAzureCredential(),
                InstrumentClientOptions(new SipRoutingClientOptions()));

            return(isInstrumented ? InstrumentClient(client) : client);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a <see cref="SipRoutingClient" /> with the connectionstring via environment
        /// variables and instruments it to make use of the Azure Core Test Framework functionalities.
        /// </summary>
        /// <returns>The instrumented <see cref="SipRoutingClient" />.</returns>
        protected SipRoutingClient CreateClient(bool isInstrumented = true)
        {
            var client = new SipRoutingClient(
                TestEnvironment.LiveTestStaticConnectionString,
                InstrumentClientOptions(new SipRoutingClientOptions()));

            // We always create the instrumented client to suppress the instrumentation check
            var instrumentedClient = InstrumentClient(client);

            return(isInstrumented ? instrumentedClient : client);
        }
Esempio n. 3
0
        public void ManageSipConfiguration()
        {
            if (SkipSipRoutingLiveTests)
            {
                Assert.Ignore("Skip SIP routing live tests flag is on.");
            }

            var connectionString = TestEnvironment.LiveTestStaticConnectionString;

            #region Snippet:CreateSipRoutingClient
            // Get a connection string to Azure Communication resource.
            //@@var connectionString = "<connection_string>";
            var client = new SipRoutingClient(connectionString);
            #endregion Snippet:CreateSipRoutingClient

            #region Snippet:CreateSipRoutingClientWithTokenCredential
            // Get an endpoint to our Azure Communication resource.
            //@@var endpoint = new Uri("<endpoint_url>");
            //@@TokenCredential tokenCredential = new DefaultAzureCredential();
            //@@client = new SipRoutingClient(endpoint, tokenCredential);
            #endregion Snippet:CreateSipRoutingClientWithTokenCredential

            client = CreateClient();
            var newTrunks = new List <SipTrunk> {
                TestData.NewTrunk
            };
            var newRoutes = new List <SipTrunkRoute> {
                TestData.RuleNavigateToNewTrunk
            };

            #region Snippet:Replace
            // The service will not allow trunks that are used in any of the routes to be deleted, therefore first set the routes as empty list, and then update the routes.
            //@@var newTrunks = "<new_trunks_list>";
            //@@var newRoutes = "<new_routes_list>";
            client.SetRoutes(new List <SipTrunkRoute>());
            client.SetTrunks(newTrunks);
            client.SetRoutes(newRoutes);
            #endregion Snippet:Replace

            #region Snippet:RetrieveList
            var trunksResponse = client.GetTrunks();
            var routesResponse = client.GetRoutes();
            #endregion Snippet:RetrieveList

            Assert.AreEqual(1, trunksResponse.Value.Count);
            Assert.IsTrue(TrunkAreEqual(TestData.NewTrunk, trunksResponse.Value[0]));
            Assert.AreEqual(1, routesResponse.Value.Count);
            Assert.IsTrue(RouteAreEqual(TestData.RuleNavigateToNewTrunk, routesResponse.Value[0]));

            var fqdnToRetrieve = TestData.NewTrunk.Fqdn;

            #region Snippet:RetrieveTrunk
            // Get trunk object, based on it's FQDN.
            //@@var fqdnToRetrieve = "<fqdn>";
            var trunkResponse = client.GetTrunk(fqdnToRetrieve);
            #endregion Snippet:RetrieveTrunk

            var trunkToSet = new SipTrunk(TestData.NewTrunk.Fqdn, 9999);

            #region Snippet:SetTrunk
            // Set function will either modify existing item or add new item to the collection.
            // The trunk is matched based on it's FQDN.
            //@@var trunkToSet = "<trunk_to_set>";
            client.SetTrunk(trunkToSet);
            #endregion Snippet:SetTrunk

            client.SetTrunk(TestData.TrunkList[0]);
            var fqdnToDelete = TestData.Fqdns[0];

            #region Snippet:DeleteTrunk
            // Deletes trunk with supplied FQDN.
            //@@var fqdnToDelete = "<fqdn>";
            client.DeleteTrunk(fqdnToDelete);
            #endregion Snippet:DeleteTrunk

            var trunksFinalResponse = client.GetTrunks();
            var routesFinalResponse = client.GetRoutes();

            Assert.AreEqual(1, trunksFinalResponse.Value.Count);
            Assert.IsTrue(TrunkAreEqual(trunkToSet, trunksFinalResponse.Value[0]));
            Assert.AreEqual(1, routesFinalResponse.Value.Count);
        }