Exemple #1
0
        public void GenerateMessageHandlesUnknownUrn()
        {
            var expected = "Unable to find target item - check that the URN is correct";
            var actual   = RemoteServerException.GenerateMessage(RemoteResultCode.UnknownUrn);

            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public override bool AsyncFetchContents(RemoteUrl remoteUrl, out RemoteServerException remoteException)
        {
            var chorusUrl  = (ChorusUrl)remoteUrl;
            Uri requestUri = GetContentsUri(ChorusAccount, chorusUrl);

            return(AsyncFetch(requestUri, FetchContents, out remoteException));
        }
Exemple #3
0
        public void GenerateMessageHandlesSuccess()
        {
            var expected = "An error has occurred at the remote server, code: " + RemoteResultCode.Success;
            var actual   = RemoteServerException.GenerateMessage(RemoteResultCode.Success);

            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        public void GenerateMessageHandlesUnknownAction()
        {
            var expected = "Unable to find specified action - check that the action is correct";
            var actual   = RemoteServerException.GenerateMessage(RemoteResultCode.UnknownAction);

            Assert.AreEqual(expected, actual);
        }
Exemple #5
0
        public void GenerateMessageHandlesInvalidInput()
        {
            var expected = "An invalid request message was passed to the remote server";
            var actual   = RemoteServerException.GenerateMessage(RemoteResultCode.InvalidInput);

            Assert.AreEqual(expected, actual);
        }
Exemple #6
0
        public override bool AsyncFetchContents(RemoteUrl remoteUrl, out RemoteServerException remoteException)
        {
            bool result = AsyncFetch(GetRootContentsUrl(), GetFolders, out remoteException);

            if (null == remoteException)
            {
                result = result && AsyncFetch(GetFileContentsUrl((UnifiUrl)remoteUrl), GetFiles, out remoteException);
            }
            return(result);
        }
 public void ConstructorSetsProperties()
 {
     var logId = Guid.NewGuid();
     var resultCode = RemoteResultCode.InvalidInput;
     var exception = new RemoteServerException(resultCode, logId);
     var expected = RemoteServerException.GenerateMessage(resultCode);
     Assert.AreEqual(resultCode, exception.ResultCode);
     Assert.AreEqual(logId, exception.LogId);
     Assert.AreEqual(expected, exception.Message);
     Assert.IsNull(exception.InnerException);
 }
Exemple #8
0
        public static RemoteServerException WrapWebException(WebException webException)
        {
            string httpErrorMessage = Resources.ChorusSession_WrapWebException_An_error_occurred_communicating_with_the_server___The_server_return_HTTP_error_response_code__0__;

            try
            {
                if (null == webException.Response)
                {
                    return(new RemoteServerException(string.Format(httpErrorMessage, webException.Status), webException)); // Not L10N
                }
                using (var responseStream = webException.Response.GetResponseStream())
                {
                    if (null == responseStream)
                    {
                        return
                            (new RemoteServerException(
                                 string.Format(httpErrorMessage, webException.Status), webException));
                    }
                    MemoryStream memoryStream = new MemoryStream();
                    int          count;
                    byte[]       buffer = new byte[65536];
                    while ((count = responseStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        memoryStream.Write(buffer, 0, count);
                    }
                    String fullMessage   = Encoding.UTF8.GetString(memoryStream.ToArray());
                    var    xmlSerializer = new XmlSerializer(typeof(ChorusErrorResponse));
                    ChorusErrorResponse chorusErrorResponse;
                    try
                    {
                        chorusErrorResponse =
                            (ChorusErrorResponse)xmlSerializer.Deserialize(new StringReader(fullMessage));
                    }
                    catch (Exception)
                    {
                        // If there is an error in the XML of the response, then put the full text of the response in an inner exception,
                        // and return them an error.
                        var innerException = new RemoteServerException(fullMessage, webException);
                        return(new RemoteServerException(string.Format(Resources.ChorusSession_WrapWebException_An_error_occurred_communicating_with_the_server___The_server_returned_the_HTTP_error_response_code__0__but_the_error_message_could_not_be_parsed_, webException.Status), innerException));
                    }

                    if (!string.IsNullOrEmpty(chorusErrorResponse.StackTrace))
                    {
                        Trace.TraceWarning(chorusErrorResponse.StackTrace);
                    }
                    return(new RemoteServerException(chorusErrorResponse.Message, webException));
                }
            }
            catch (Exception exception)
            {
                return(new RemoteServerException(exception.Message, new AggregateException(webException, exception)));
            }
        }
Exemple #9
0
        public void ConstructorSetsProperties()
        {
            var logId      = Guid.NewGuid();
            var resultCode = RemoteResultCode.InvalidInput;
            var exception  = new RemoteServerException(resultCode, logId);
            var expected   = RemoteServerException.GenerateMessage(resultCode);

            Assert.AreEqual(resultCode, exception.ResultCode);
            Assert.AreEqual(logId, exception.LogId);
            Assert.AreEqual(expected, exception.Message);
            Assert.IsNull(exception.InnerException);
        }
 public void InnerExceptionIsSet()
 {
     var logId = Guid.NewGuid();
     var resultCode = RemoteResultCode.InvalidInput;
     var message = "duh-duh";
     var inner = new Exception("Oops");
     var exception = new RemoteServerException(resultCode, logId, message, inner);
     Assert.AreEqual(resultCode, exception.ResultCode);
     Assert.AreEqual(logId, exception.LogId);
     Assert.AreEqual(message, exception.Message);
     Assert.AreSame(inner, exception.InnerException);
 }
Exemple #11
0
        public void InnerExceptionIsSet()
        {
            var logId      = Guid.NewGuid();
            var resultCode = RemoteResultCode.InvalidInput;
            var message    = "duh-duh";
            var inner      = new Exception("Oops");
            var exception  = new RemoteServerException(resultCode, logId, message, inner);

            Assert.AreEqual(resultCode, exception.ResultCode);
            Assert.AreEqual(logId, exception.LogId);
            Assert.AreEqual(message, exception.Message);
            Assert.AreSame(inner, exception.InnerException);
        }