public void SharePointRestErrorToStringDeserialization() { bool sharePointRestServiceExceptionThrown = false; SharePointRestError error = null; Dictionary <string, string> headers = new Dictionary <string, string> { { PnPConstants.SPRequestGuidHeader, "E91534F0-D3B4-4062-B872-41301FC1EC86" }, { PnPConstants.XSPServerStateHeader, "0" }, { PnPConstants.XSharePointHealthScoreHeader, "2" }, { PnPConstants.SPClientServiceRequestDurationHeader, "13" } }; try { SharePointRestServiceException restException = new SharePointRestServiceException(ErrorType.SharePointRestServiceError, 400, sampleRestSimpleError, headers); restException.Error.AdditionalData.Add("Extra1", "extra error data"); restException.Error.AdditionalData.Add("Extra2", true); throw restException; } catch (ServiceException ex) { if (ex is SharePointRestServiceException) { error = ex.Error as SharePointRestError; sharePointRestServiceExceptionThrown = true; } } Assert.IsTrue(error.ClientRequestId == "E91534F0-D3B4-4062-B872-41301FC1EC86"); var restErrorString = error.ToString(); Assert.IsTrue(restErrorString.Contains("HttpResponseCode:")); Assert.IsTrue(restErrorString.Contains("Code:")); Assert.IsTrue(restErrorString.Contains("Message:")); Assert.IsTrue(restErrorString.Contains("ClientRequestId:")); Assert.IsTrue(restErrorString.Contains("Extra1: extra error data")); Assert.IsTrue(restErrorString.Contains("Extra2: True")); Assert.IsTrue(restErrorString.Contains("SPClientServiceRequestDuration: 13")); Assert.IsTrue(restErrorString.Contains("X-SharePointHealthScore: 2")); Assert.IsTrue(restErrorString.Contains("X-SP-SERVERSTATE: 0")); Assert.IsTrue(sharePointRestServiceExceptionThrown); Assert.IsTrue(string.IsNullOrEmpty(error.Code)); Assert.IsTrue(!string.IsNullOrEmpty(error.Message)); Assert.IsTrue(error.Type == ErrorType.SharePointRestServiceError); }
public void SharePointRestErrorToStringDeserialization() { bool sharePointRestServiceExceptionThrown = false; SharePointRestError error = null; try { SharePointRestServiceException restException = new SharePointRestServiceException(ErrorType.SharePointRestServiceError, 400, sampleRestSimpleError); restException.Error.AdditionalData = new Dictionary <string, object> { { "Extra1", "extra error data" }, { "Extra2", true } }; throw restException; } catch (ServiceException ex) { if (ex is SharePointRestServiceException) { error = ex.Error as SharePointRestError; sharePointRestServiceExceptionThrown = true; } } var restErrorString = error.ToString(); Assert.IsTrue(restErrorString.Contains("HttpResponseCode:")); Assert.IsTrue(restErrorString.Contains("Code:")); Assert.IsTrue(restErrorString.Contains("Message:")); Assert.IsTrue(restErrorString.Contains("ClientRequestId:")); Assert.IsTrue(restErrorString.Contains("Extra1: extra error data")); Assert.IsTrue(restErrorString.Contains("Extra2: True")); Assert.IsTrue(sharePointRestServiceExceptionThrown); Assert.IsTrue(string.IsNullOrEmpty(error.Code)); Assert.IsTrue(!string.IsNullOrEmpty(error.Message)); Assert.IsTrue(error.Type == ErrorType.SharePointRestServiceError); }