public void TestValidErrorJsonResponse() { var observer = new MockServerResponseReaderObserver(); ServerResponseReader serverResponseReader = ServerResponseReader.Instance; const string jsonResponse = @"{ ""error"": { ""code"": ""the code"", ""message"": ""the message"" } }"; serverResponseReader.Read(jsonResponse, observer); Assert.IsTrue( observer.HasCalledOnErrorResponse(), "The OnErrorResponse should have been called on the observer."); Assert.AreEqual( "the code", observer.Code, "The code value was not properly sent to the observer." ); Assert.AreEqual( "the message", observer.Message, "The message value was not properly sent to the observer." ); Assert.IsFalse( observer.HasCalledOnSuccessResponse(), "The OnSuccessResponse should NOT have been called on the observer."); Assert.IsFalse( observer.HasCalledOnInvalidJsonResponse(), "The OnInvalidJsonResponse should NOT have been called on the observer."); }
public void TestValidNonErrorJsonResponse() { var observer = new MockServerResponseReaderObserver(); ServerResponseReader serverResponseReader = ServerResponseReader.Instance; const string jsonResponse = @"{ ""foo"": ""bar"" }"; serverResponseReader.Read(jsonResponse, observer); Assert.IsTrue( observer.HasCalledOnSuccessResponse(), "The OnSuccessResponse should have been called on the observer."); Assert.AreEqual( jsonResponse, observer.RawResult, "The observer did not receive the correct raw json result."); IDictionary <string, object> result = observer.Result; Assert.AreEqual( "bar", result["foo"], "The observer did not receive the correct json result. It was missing the correct foo property"); Assert.IsFalse( observer.HasCalledOnErrorResponse(), "The OnErrorResponse should NOT have been called on the observer."); Assert.IsFalse( observer.HasCalledOnInvalidJsonResponse(), "The OnInvalidJsonResponse should NOT have been called on the observer."); }
/// <summary> /// Reads, parses, and deltes the upload response from downloadLocation and then /// returns an action that will call the appropriate method on the IBackgroundUploadResponseHandlerObserver. /// </summary> /// <returns> /// An action that will call the approriate method on the IBackgroundUploadResponseHandlerObserver. /// This return value will be given as an argument to OnSuccess on the main/ui thread. /// </returns> public Action OnDoWork() { string response = this.ReadAndDeleteFromDownloadLocation(); ServerResponseReader responseReader = ServerResponseReader.Instance; responseReader.Read(response, this); return(this.result); }
internal static LiveOperationResult FromResponse(string response) { var creator = new Creator(); ServerResponseReader reader = ServerResponseReader.Instance; reader.Read(response, creator); return(creator.Result); }
public void TestInvalidJsonResponse() { var observer = new MockServerResponseReaderObserver(); ServerResponseReader serverResponseReader = ServerResponseReader.Instance; const string jsonResponse = "INVALID JSON L:KA)(*#!:KAJ}{!#A"; serverResponseReader.Read(jsonResponse, observer); Assert.IsTrue( observer.HasCalledOnInvalidJsonResponse(), "The OnInvalidJsonResponse should NOT have been called on the observer."); Assert.IsNotNull(observer.Exception, "Expected to see a FormatException because of invalid json."); Assert.IsFalse( observer.HasCalledOnSuccessResponse(), "The OnSuccessResponse should NOT have been called on the observer."); Assert.IsFalse( observer.HasCalledOnErrorResponse(), "The OnErrorResponse should NOT have been called on the observer."); }
/// <summary> /// initializes and starts the reading of the responses from the vr server /// </summary> /// <param name="stream">the networkstream</param> private void initReader() { serverResponseReader = new ServerResponseReader(stream); serverResponseReader.callback = HandleResponse; serverResponseReader.StartRead(); }