public void ToRemoteError_WhenExceptionIsOtherType_SetsProjectContextLogMessage() { var exception = new DivideByZeroException(); RemoteError remoteError = RemoteErrorUtility.ToRemoteError(exception); Assert.Equal(exception.ToString(), remoteError.ProjectContextLogMessage); }
public void ShowError_WhenArgumentIsRemoteInvocationExceptionForOtherException_ShowsError() { var remoteException = new ArgumentException(message: "a", new DivideByZeroException(message: "b")); var remoteError = RemoteErrorUtility.ToRemoteError(remoteException); var exception = new RemoteInvocationException( message: "c", errorCode: 0, errorData: null, deserializedErrorData: remoteError); var defaultLogger = new Mock <INuGetUILogger>(); var projectLogger = new Mock <INuGetUILogger>(); defaultLogger.Setup( x => x.ReportError( It.Is <ILogMessage>(logMessage => ReferenceEquals(logMessage, remoteError.LogMessage)))); projectLogger.Setup( x => x.Log( It.Is <MessageLevel>(level => level == MessageLevel.Error), It.Is <string>(message => message == remoteException.ToString()))); using (NuGetUI ui = CreateNuGetUI(defaultLogger.Object, projectLogger.Object)) { ui.ShowError(exception); defaultLogger.VerifyAll(); projectLogger.VerifyAll(); } }
public void ToRemoteError_WhenExceptionIsNull_Throws() { ArgumentNullException exception = Assert.Throws <ArgumentNullException>( () => RemoteErrorUtility.ToRemoteError(exception: null)); Assert.Equal("exception", exception.ParamName); }
public void ToRemoteError_WhenExceptionIsNull_Throws() { ArgumentNullException exception = Assert.Throws <ArgumentNullException>( #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. () => RemoteErrorUtility.ToRemoteError(exception: null)); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. Assert.Equal("exception", exception.ParamName); }
private async ValueTask <T> CatchAndRethrowExceptionAsync <T>(Func <Task <T> > taskFunc) { try { return(await taskFunc()); } catch (Exception ex) { var exception = new LocalRpcException(ex.Message, ex) { ErrorCode = (int)RemoteErrorCode.RemoteError, ErrorData = RemoteErrorUtility.ToRemoteError(ex) }; throw exception; } }