System.ComponentModel.Tests.Win32ExceptionTestType.InstantiateExceptionWithLongErrorString C# (CSharp) Method

InstantiateExceptionWithLongErrorString() private method

private InstantiateExceptionWithLongErrorString ( ) : void
return void
        public static void InstantiateExceptionWithLongErrorString()
        {
            // This test checks that Win32Exception supports error strings greater than 256 characters.
            // Since we will have to rely on a message associated with an error code,
            // we try to reduce the flakiness by doing the following.
            // 1. Call FormatMessage to check whether the exception resource length >256 chars.
            // 2. If true, we validate that Win32Exception class can retrieve the complete resource string.
            // 3. If not we skip testing.
            int errorCode = 0x268;
            if (IsExceptionMessageLong(errorCode)) // Localized error string for 0x268 is not guaranteed to be >256 chars. 
            {
                Win32Exception ex = new Win32Exception(errorCode);
                Assert.NotEqual("Unknown error (0x268)", ex.Message);
                Assert.True(ex.Message.Length > FirstPassBufferSize);

                ex = new Win32Exception(0x23);
                Assert.Equal(expected: "Unknown error (0x23)", actual: ex.Message);
            }
        }