public void TryProcessError_ShouldReturnException_WithNoNetworkErrorType_IfResponseStatusIsError() { var mockResp = new Mock<IGitHubResponse>(MockBehavior.Strict); mockResp.Setup(r => r.StatusCode).Returns(HttpStatusCode.RequestTimeout); mockResp.Setup(r => r.ErrorException).Returns<Exception>(null); mockResp.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Error); var processor = new ResponseProcessor(); GitHubException ex = null; processor.TryProcessResponseErrors(mockResp.Object, out ex); Assert.AreEqual(ErrorType.NoNetwork, ex.ErrorType); }
public void TryProcessError_ShouldReturnException_WithUnauthorizedErrorType_IfResponseStatusIsUnauthorized() { var mockResp = new Mock<IGitHubResponse>(MockBehavior.Strict); mockResp.Setup(r => r.StatusCode).Returns(HttpStatusCode.Unauthorized); mockResp.Setup(r => r.ErrorException).Returns<Exception>(null); mockResp.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed); var processor = new ResponseProcessor(); GitHubException ex = null; processor.TryProcessResponseErrors(mockResp.Object, out ex); Assert.AreEqual(ErrorType.Unauthorized, ex.ErrorType); }
public void TryProcessError_ShouldReturnFalse_IfResponseStatusCodeIsCreated() { var mockResp = new Mock<IGitHubResponse>(MockBehavior.Strict); mockResp.Setup(r => r.StatusCode) .Returns(HttpStatusCode.Created); var processor = new ResponseProcessor(); GitHubException ex = null; Assert.IsFalse(processor.TryProcessResponseErrors(mockResp.Object, out ex)); }
public void TryProcessError_ShouldReturnTrue_IfResponseStatusCodeIsNotOKOrCreated() { var mockResp = new Mock<IGitHubResponse>(MockBehavior.Strict); mockResp.Setup(r => r.StatusCode).Returns(HttpStatusCode.Forbidden); mockResp.Setup(r => r.ErrorException).Returns<Exception>(null); mockResp.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed); var processor = new ResponseProcessor(); GitHubException ex = null; Assert.IsTrue(processor.TryProcessResponseErrors(mockResp.Object, out ex)); }