📄 failuremessagefixture.cs
字号:
#region Copyright (c) 2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
/************************************************************************************
'
' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
' Copyright 2000-2002 Philip A. Craig
'
' This software is provided 'as-is', without any express or implied warranty. In no
' event will the authors be held liable for any damages arising from the use of this
' software.
'
' Permission is granted to anyone to use this software for any purpose, including
' commercial applications, and to alter it and redistribute it freely, subject to the
' following restrictions:
'
' 1. The origin of this software must not be misrepresented; you must not claim that
' you wrote the original software. If you use this software in a product, an
' acknowledgment (see the following) in the product documentation is required.
'
' Portions Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
' or Copyright 2000-2002 Philip A. Craig
'
' 2. Altered source versions must be plainly marked as such, and must not be
' misrepresented as being the original software.
'
' 3. This notice may not be removed or altered from any source distribution.
'
'***********************************************************************************/
#endregion
namespace NUnit.Tests.Assertions
{
using System;
using NUnit.Framework;
using System.Collections;
/// <summary>
/// Wrapper class to give us 'inner-class' access to the methods of this
/// class, without exposing them publicly. We need to be able to test
/// these methods, but because this is a framework, don't want others
/// calling the methods.
/// </summary>
public class MyAssertionFailureMessage : NUnit.Framework.AssertionFailureMessage
{
/// <summary>
/// Protected constructor, used since this class is only used via
/// static methods
/// </summary>
protected MyAssertionFailureMessage() : base() {}
/// <summary>
/// Summary description for AssertionFailureMessageTests.
/// </summary>
///
[TestFixture]
public class FailureMessageFixture
{
/// <summary>
///
/// </summary>
///
[Test]
public void TestInputsAreStrings()
{
Assert.AreEqual( false, InputsAreStrings( null, null ) );
Assert.AreEqual( false, InputsAreStrings( new Object(), null ) );
Assert.AreEqual( false, InputsAreStrings( null, new Object() ) );
Assert.AreEqual( false, InputsAreStrings( new Object(), "" ) );
Assert.AreEqual( false, InputsAreStrings( "", new Object() ) );
Assert.AreEqual( true, InputsAreStrings( "", "" ) );
Assert.AreEqual( true, InputsAreStrings( "test1", "test1" ) );
Assert.AreEqual( true, InputsAreStrings( "some", "value" ) );
}
/// <summary>
///
/// </summary>
///
[Test]
public void TestCreateStringBuilder()
{
Assert.AreEqual( "", CreateStringBuilder( null ).ToString() );
Assert.AreEqual( "", CreateStringBuilder( "" ).ToString() );
Assert.AreEqual( "a", CreateStringBuilder( "a" ).ToString() );
Assert.AreEqual( "message", CreateStringBuilder( "message" ).ToString() );
Assert.AreEqual( "message 5 from me",
CreateStringBuilder( "message {0} from {1}", 5, "me" ).ToString() );
}
/// <summary>
/// Tests the string-clipping method to see if it clips at the
/// expected positions.
/// </summary>
[Test]
public void TestClipAroundPosition()
{
// Some spot-checks
Assert.AreEqual( "", ClipAroundPosition( null, 0 ) );
Assert.AreEqual( "", ClipAroundPosition( "", 0 ) );
Assert.AreEqual( "a", ClipAroundPosition( "a", 0 ) );
Assert.AreEqual( "ab", ClipAroundPosition( "ab", 0 ) );
Assert.AreEqual( "ab", ClipAroundPosition( "ab", 1 ) );
Assert.AreEqual( "abc", ClipAroundPosition( "abc", 0 ) );
Assert.AreEqual( "abc", ClipAroundPosition( "abc", 1 ) );
Assert.AreEqual( "abc", ClipAroundPosition( "abc", 2 ) );
Assert.AreEqual( "012345678", ClipAroundPosition( "012345678", 0 ) );
Assert.AreEqual( "012345678", ClipAroundPosition( "012345678", 1 ) );
Assert.AreEqual( "012345678", ClipAroundPosition( "012345678", 2 ) );
Assert.AreEqual( "012345678", ClipAroundPosition( "012345678", 7 ) );
Assert.AreEqual( "012345678", ClipAroundPosition( "012345678", 8 ) );
Assert.AreEqual( "0123456789", ClipAroundPosition( "0123456789", 0 ) );
Assert.AreEqual( "0123456789", ClipAroundPosition( "0123456789", 1 ) );
Assert.AreEqual( "0123456789", ClipAroundPosition( "0123456789", 2 ) );
Assert.AreEqual( "0123456789", ClipAroundPosition( "0123456789", 7 ) );
Assert.AreEqual( "0123456789", ClipAroundPosition( "0123456789", 8 ) );
Assert.AreEqual( "0123456789", ClipAroundPosition( "0123456789", 9 ) );
Assert.AreEqual( "01234567890", ClipAroundPosition( "01234567890", 0 ) );
Assert.AreEqual( "01234567890", ClipAroundPosition( "01234567890", 1 ) );
Assert.AreEqual( "01234567890", ClipAroundPosition( "01234567890", 2 ) );
Assert.AreEqual( "01234567890", ClipAroundPosition( "01234567890", 7 ) );
Assert.AreEqual( "01234567890", ClipAroundPosition( "01234567890", 8 ) );
Assert.AreEqual( "01234567890", ClipAroundPosition( "01234567890", 9 ) );
Assert.AreEqual( "01234567890", ClipAroundPosition( "01234567890", 10 ) );
}
/// <summary>
/// Tests the string-clipping method to see if it clips at the
/// expected positions.
/// </summary>
[Test]
public void TestClipAroundPosition2()
{
const string sTest = "a0a1a2a3a4a5a6a7a8a9b0b1b2b3b4b5b6b7b8b9c0c1c2c3c4c5c6c7c8c9d0d1d2d3d4d5d6d7d8d9";
int iTestPosition;
// Want no pre-clipping and post-clipping when position is before
// first 10 digits
for( int i=0; i<=PreClipLength; i++ )
{
iTestPosition = i;
Assert.AreEqual( sTest.Substring( 0, i+PostClipLength ) + "...",
ClipAroundPosition( sTest, iTestPosition ) );
}
// Want pre- and post-clipping when position is after
// first 10 digits and before last 40 digits
for( int i=PreClipLength+1; i<(sTest.Length - PostClipLength); i++ )
{
iTestPosition = i;
Assert.AreEqual( "..." + sTest.Substring( iTestPosition-PreClipLength, PreClipLength+PostClipLength ) + "...",
ClipAroundPosition( sTest, iTestPosition ) );
}
// Want pre-clipping and no post-clipping when position is within
// last 40 digits
for( int i=(sTest.Length - PostClipLength); i<sTest.Length; i++ )
{
iTestPosition = i;
Assert.AreEqual( "..." + sTest.Substring( iTestPosition-PreClipLength ),
ClipAroundPosition( sTest, iTestPosition ) );
}
}
/// <summary>
/// Makes sure that whitespace conversion for CR, LF, or TAB
/// characters into 2 characters, one slash '\' and
/// one 'r' or 'n' or 't' for display
/// </summary>
[Test]
public void TestConvertWhitespace()
{
Assert.AreEqual( "\\n", ConvertWhitespace("\n") );
Assert.AreEqual( "\\n\\n", ConvertWhitespace("\n\n") );
Assert.AreEqual( "\\n\\n\\n", ConvertWhitespace("\n\n\n") );
Assert.AreEqual( "\\r", ConvertWhitespace("\r") );
Assert.AreEqual( "\\r\\r", ConvertWhitespace("\r\r") );
Assert.AreEqual( "\\r\\r\\r", ConvertWhitespace("\r\r\r") );
Assert.AreEqual( "\\r\\n", ConvertWhitespace("\r\n") );
Assert.AreEqual( "\\n\\r", ConvertWhitespace("\n\r") );
Assert.AreEqual( "This is a\\rtest message", ConvertWhitespace("This is a\rtest message") );
Assert.AreEqual( "", ConvertWhitespace("") );
Assert.AreEqual( null, ConvertWhitespace(null) );
Assert.AreEqual( "\\t", ConvertWhitespace( "\t" ) );
Assert.AreEqual( "\\t\\n", ConvertWhitespace( "\t\n" ) );
}
/// <summary>
/// Checks several common failure conditions to ensure the output
/// strings match the expected output.
/// </summary>
[Test]
public void TestFormatMessageForFailNotEquals()
{
Assert.AreEqual( "\r\n\texpected:<(null)>\r\n\t but was:<(null)>",
FormatMessageForFailNotEquals( null, null, null ) );
Assert.AreEqual( "\r\n\texpected:<(null)>\r\n\t but was:<(null)>",
FormatMessageForFailNotEquals(null, null, "") );
Assert.AreEqual( "message \r\n\texpected:<(null)>\r\n\t but was:<(null)>",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -