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_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); } }