public void ClientRuntimeContextService_Should_ThrowGenericException_On_UnsupportHttpStatuses()
        {
            // expecting web exception on unknown http statuses

            var currentReconnectCount = 0;
            var service = new DefaultClientRuntimeContextService();

            var rndService            = new DefaultRandomService();
            var supportedHttpStatuses = new[]
            {
                700, 800, 900
            };

            // to run test faster
            service.ExecuteQueryDelayInMilliseconds = 1;

            service.CustomExecuteQueryHandler += (cnt) =>
            {
                currentReconnectCount++;

                var webResponce = Activator.CreateInstance <HttpWebResponse>();

                var sttausCode = rndService.RandomFromArray(supportedHttpStatuses);
                SetStatusCode(webResponce, sttausCode);

                var ex = new WebException("Can't connect to O365", null,
                                          (WebExceptionStatus)402, webResponce);

                throw ex;
            };

            service.ExecuteQuery(default(ClientRuntimeContext));
        }
        public void ClientRuntimeContextService_Should_Rethrow_GenericException()
        {
            // expecting generic exception re-thrown
            var service = new DefaultClientRuntimeContextService();

            service.CustomExecuteQueryHandler += (cnt) =>
            {
                throw new Exception("Can't do anything!");
            };

            service.ExecuteQuery(default(ClientRuntimeContext));
        }
Ejemplo n.º 3
0
        public void ClientRuntimeContextService_Default_Throtting_Setting_As_Recommended()
        {
            // Align CSOM throttling setting with MS recommendations, open up API #849
            // https://github.com/SubPointSolutions/spmeta2/issues/849

            // https://msdn.microsoft.com/en-us/library/office/dn889829.aspx?f=255&MSPPError=-2147217396#BKMK_Bestpracticestohandlethrottling
            // https://www.yammer.com/spmeta2feedback/#/threads/show?threadId=725945901&messageId=725945901

            // expecting generic exception re-thrown
            var service = new DefaultClientRuntimeContextService();

            Assert.AreEqual(5, service.ExecuteQueryRetryAttempts);
            Assert.AreEqual(30000, service.ExecuteQueryDelayInMilliseconds);
            Assert.AreEqual(2, service.ExecuteQueryRetryDelayMultiplier);
        }
        public void ClientRuntimeContextService_Should_SupportHttpStatuses()
        {
            // expecting SPMeta2Exception on known http statuses

            var currentReconnectCount = 0;
            var service = new DefaultClientRuntimeContextService();

            var rndService            = new DefaultRandomService();
            var supportedHttpStatuses = new[]
            {
                429, 503
            };

            // to run test faster
            service.ExecuteQueryDelayInMilliseconds = 1;

            service.CustomExecuteQueryHandler += (cnt) =>
            {
                currentReconnectCount++;

                var webResponce = Activator.CreateInstance <HttpWebResponse>();

                var sttausCode = rndService.RandomFromArray(supportedHttpStatuses);
                SetStatusCode(webResponce, sttausCode);

                var ex = new WebException("Can't connect to O365", null,
                                          (WebExceptionStatus)402, webResponce);

                throw ex;
            };
            try
            {
                service.ExecuteQuery(default(ClientRuntimeContext));
            }
            catch (Exception e)
            {
                Assert.AreEqual(currentReconnectCount, service.ExecuteQueryRetryAttempts);
                Assert.IsTrue(e is SPMeta2Exception);
            }
        }
        public void ClientRuntimeContextService_Should_MakeNAttempts_And_ThrowException()
        {
            // expecting SPMeta2Exception AND currentReconnectCount == ExecuteQueryRetryAttempts
            // tried our best, but failed

            var currentReconnectCount = 0;

            var service = new DefaultClientRuntimeContextService();

            // to run test faster
            service.ExecuteQueryDelayInMilliseconds = 1;

            service.CustomExecuteQueryHandler += (cnt) =>
            {
                currentReconnectCount++;

                var webResponce = Activator.CreateInstance <HttpWebResponse>();

                var statusCodeProp = webResponce.GetType()
                                     .GetField("m_StatusCode", BindingFlags.NonPublic | BindingFlags.Instance);

                statusCodeProp.SetValue(webResponce, 429);

                var ex = new WebException("Can't connect to O365", null,
                                          (WebExceptionStatus)402, webResponce);

                throw ex;
            };
            try
            {
                service.ExecuteQuery(default(ClientRuntimeContext));
            }
            catch (Exception e)
            {
                Assert.AreEqual(currentReconnectCount, service.ExecuteQueryRetryAttempts);
                Assert.IsTrue(e is SPMeta2Exception);
            }
        }
Ejemplo n.º 6
0
 static ClientRuntimeContextExtensions()
 {
     DefaultClientRuntimeContextService = new DefaultClientRuntimeContextService();
     DefaultTraceServiceBase            = new TraceSourceService();
 }