Ejemplo n.º 1
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);
            }
        }
        internal void SetOrAddValue(DocumentClientType type, double charge)
        {
            double curr;

            if (this.chargeStore.TryGetValue(type, out curr))
            {
                this.chargeStore[type] = curr + charge;
            }
            else
            {
                this.chargeStore[type] = charge;
            }
        }
Ejemplo n.º 3
0
 private static void RunTestForClient(
     Func <DocumentClient, DocumentClientType, Task> testFunc,
     string testName,
     DocumentClientType clientType,
     DocumentClient client)
 {
     try
     {
         Logger.LogLine("Run test - {0} for clientType {1}", testName, clientType);
         testFunc(client, clientType).Wait();
     }
     catch (Exception e)
     {
         Logger.LogLine("Run test {0} for clientType {1} failed with exception - {2}", testName, clientType, e.ToString());
         Assert.Fail(
             string.Format(
                 CultureInfo.InvariantCulture,
                 "Test {0} failed for clientType - {1} with unexpected exception : {2}",
                 testFunc,
                 clientType,
                 e.ToString()));
     }
 }
 /// <summary>
 /// Sets the value for charge for a clientType.
 /// Overrides the earlier set value if it is set.
 /// </summary>
 /// <param name="type">DocumentClientType</param>
 /// <param name="charge">charge for the operation</param>
 internal void SetValue(DocumentClientType type, double charge)
 {
     this.chargeStore[type] = charge;
 }