public void ShouldHandleInternalErrorsAndNotifyCallbacks() { IClientOperation errorSubscribeOperation = Substitute.For <IClientOperation>(); errorSubscribeOperation.ToJson().Returns(x => throw new Exception("forced error")); ParseQuery <ParseObject> query = new ParseQuery <ParseObject>(); _subscriptionFactory.CreateSubscriptionFunction = () => new TestSubscription(1, query) { CreateSubscribeClientOperationFunction = _ => errorSubscribeOperation }; LiveQueryException exception = null; ErrorCallback <ParseObject> errorCallback = Substitute.For <ErrorCallback <ParseObject> >(); errorCallback.Invoke(query, Arg.Do <LiveQueryException>(e => exception = e)); _parseLiveQueryClient.Subscribe(query).HandleError(errorCallback); _webSocketClientCallback.OnMessage(MockConnectedMessage()); // Trigger a re-subscribe // This will never get a chance to call op=subscribe, because an exception was thrown _webSocketClient.DidNotReceive().Send(Arg.Any <string>()); errorCallback.Received().Invoke(query, exception); Assert.AreEqual("Error when subscribing", exception.Message); Assert.NotNull(exception.GetBaseException()); }
public void ShouldHandleServerErrorsAndNotifyCallbacks() { LiveQueryException exception = null; ParseQuery <ParseObject> query = new ParseQuery <ParseObject>("test"); ErrorCallback <ParseObject> errorCallback = Substitute.For <ErrorCallback <ParseObject> >(); errorCallback.Invoke(query, Arg.Do <LiveQueryException>(e => exception = e)); Subscription <ParseObject> subscription = Subscribe(query).HandleError(errorCallback); _webSocketClientCallback.OnMessage(MockErrorMessage(subscription.RequestId)); errorCallback.Received().Invoke(query, exception); Assert.IsInstanceOf <ServerReportedException>(exception); ServerReportedException serverException = (ServerReportedException)exception; Assert.AreEqual("testError", serverException.Error); Assert.AreEqual(1, serverException.Code); Assert.AreEqual(true, serverException.IsReconnect); }