示例#1
0
        /// <summary>
        /// Helper function to run a test scenario for client of type DocumentClientType.
        /// </summary>
        /// <param name="testFunc"></param>
        /// <param name="testName"></param>
        /// <param name="requestChargeHelper"></param>
        /// <param name="authTokenType">authTokenType for the client created for running the test</param>
        internal static void TestForEachClient(
            Func <DocumentClient, DocumentClientType, Task> testFunc,
            string testName,
            RequestChargeHelper requestChargeHelper = null,
            AuthorizationTokenType authTokenType    = AuthorizationTokenType.PrimaryMasterKey,
            ConsistencyLevel?consistencyLevel       = null)
        {
            IDictionary <DocumentClientType, DocumentClient> clients =
                new Dictionary <DocumentClientType, DocumentClient>
            {
                { DocumentClientType.Gateway, TestCommon.CreateClient(true, tokenType: authTokenType, defaultConsistencyLevel: consistencyLevel) },
                { DocumentClientType.DirectTcp, TestCommon.CreateClient(false, Protocol.Tcp, tokenType: authTokenType, defaultConsistencyLevel: consistencyLevel) },
                { DocumentClientType.DirectHttps, TestCommon.CreateClient(false, Protocol.Https, tokenType: authTokenType, defaultConsistencyLevel: consistencyLevel) }
            };

            foreach (var clientEntry in clients)
            {
                try
                {
                    RunTestForClient(testFunc, testName, clientEntry.Key, clientEntry.Value);
                }
                finally
                {
                    clientEntry.Value.Dispose();
                }
            }

            if (requestChargeHelper != null)
            {
                requestChargeHelper.CompareRequestCharge(testName);
            }
        }
示例#2
0
        /// <summary>
        /// Helper function to run a test scenario for a random client of type DocumentClientType.
        /// </summary>
        /// <param name="testFunc"></param>
        /// <param name="testName"></param>
        /// <param name="requestChargeHelper"></param>
        /// <param name="authTokenType">authTokenType for the client created for running the test</param>
        internal static void TestForAnyClient(
            Func <DocumentClient, DocumentClientType, Task> testFunc,
            string testName,
            RequestChargeHelper requestChargeHelper = null,
            AuthorizationTokenType authTokenType    = AuthorizationTokenType.PrimaryMasterKey,
            ConsistencyLevel?consistencyLevel       = null)
        {
            IDictionary <DocumentClientType, DocumentClient> clients =
                new Dictionary <DocumentClientType, DocumentClient>
            {
                { DocumentClientType.Gateway, TestCommon.CreateClient(true, tokenType: authTokenType, defaultConsistencyLevel: consistencyLevel) },
                { DocumentClientType.DirectTcp, TestCommon.CreateClient(false, Protocol.Tcp, tokenType: authTokenType, defaultConsistencyLevel: consistencyLevel) },
                { DocumentClientType.DirectHttps, TestCommon.CreateClient(false, Protocol.Https, tokenType: authTokenType, defaultConsistencyLevel: consistencyLevel) }
            };

            int                seed         = (int)DateTime.Now.Ticks;
            Random             rand         = new Random(seed);
            DocumentClientType selectedType = clients.Keys.ElementAt(rand.Next(clients.Count));
            DocumentClient     client       = clients[selectedType];

            try
            {
                RunTestForClient(testFunc, testName, selectedType, client);
            }
            finally
            {
                client.Dispose();
            }

            if (requestChargeHelper != null)
            {
                requestChargeHelper.CompareRequestCharge(testName);
            }
        }