[翻译]NUnit---String && Collection && File && Directory Assert (七)

StringAssert (NUnit 2.2.3)

StringAssert类提供一系列检查字符串的方法。

 

View Code
StringAssert.Contains( string expected, string actual );
StringAssert.Contains( string expected, string actual, 
                string message );
StringAssert.Contains( string expected, string actual,
                string message, params object[] args );

StringAssert.StartsWith( string expected, string actual );
StringAssert.StartsWith( string expected, string actual, 
                string message );
StringAssert.StartsWith( string expected, string actual,
                string message, params object[] args );

StringAssert.EndsWith( string expected, string actual );
StringAssert.EndsWith( string expected, string actual, 
                string message );
StringAssert.EndsWith( string expected, string actual,
                string message, params object[] args );

StringAssert.AreEqualIgnoringCase( string expected, string actual );
StringAssert.AreEqualIgnoringCase( string expected, string actual, 
                string message );
StringAssert.AreEqualIgnoringCase( string expected, string actual,
                string message params object[] args );
                
StringAssert.IsMatch( string regexPattern, string actual );
StringAssert.IsMatch( string regexPattern, string actual, 
                string message );
StringAssert.IsMatch( string regexPattern, string actual,
                string message, params object[] args );

 

CollectionAssert (NUnit 2.4 / 2.5)

CollectionAssert类提供一系列检查两个集合及内容的方法。AreEqual检查两个集合对应元素都相等时则集合相等。AreEquivalent不按照舒顺序检查两个集合内容是否相等。这两种情况都是使用NUnit默认相等比较。

 

从NUnit2.4.6开始,这些方法都用于实现了IEnumerable接口的对象。2.4.6以前的版本仅支持集合对象。

 

View Code
CollectionAssert.AllItemsAreInstancesOfType( IEnumerable collection,
          Type expectedType );
CollectionAssert.AllItemsAreInstancesOfType( IEnumerable collection,
          Type expectedType, string message );
CollectionAssert.AllItemsAreInstancesOfType( IEnumerable collection,
          Type expectedType, string message, params object[] args );

CollectionAssert.AllItemsAreNotNull( IEnumerable collection );
CollectionAssert.AllItemsAreNotNull( IEnumerable collection,
          string message );
CollectionAssert.AllItemsAreNotNull( IEnumerable collection,
          string message, params object[] args );

CollectionAssert.AllItemsAreUnique( IEnumerable collection );
CollectionAssert.AllItemsAreUnique( IEnumerable collection,
          string message );
CollectionAssert.AllItemsAreUnique( IEnumerable collection,
          string message, params object[] args );

CollectionAssert.AreEqual( IEnumerable expected, IEnumerable actual );
CollectionAssert.AreEqual( IEnumerable expected, IEnumerable actual,
          string message );
CollectionAssert.AreEqual( IEnumerable expected, IEnumerable actual
          string message, params object[] args );

CollectionAssert.AreEquivalent( IEnumerable expected, IEnumerable actual);
CollectionAssert.AreEquivalent( IEnumerable expected, IEnumerable actual,
          string message );
CollectionAssert.AreEquivalent( IEnumerable expected, IEnumerable actual
          string message, params object[] args );

CollectionAssert.AreNotEqual( IEnumerable expected, IEnumerable actual );
CollectionAssert.AreNotEqual( IEnumerable expected, IEnumerable actual,
          string message );
CollectionAssert.AreNotEqual( IEnumerableon expected, IEnumerable actual
          string message, params object[] args );

CollectionAssert.AreNotEquivalent( IEnumerable expected,
          IEnumerable actual );
CollectionAssert.AreNotEquivalent( IEnumerable expected,
          IEnumerable actual, string message );
CollectionAssert.AreNotEquivalent( IEnumerable expected,
          IEnumerable actual, string message, params object[] args );

CollectionAssert.Contains( IEnumerable expected, object actual );
CollectionAssert.Contains( IEnumerable expected, object actual,
          string message );
CollectionAssert.Contains( IEnumerable expected, object actual
          string message, params object[] args );

CollectionAssert.DoesNotContain( IEnumerable expected, object actual );
CollectionAssert.DoesNotContain( IEnumerable expected, object actual,
          string message );
CollectionAssert.DoesNotContain( IEnumerable expected, object actual
          string message, params object[] args );

CollectionAssert.IsSubsetOf( IEnumerable subset, IEnumerable superset );
CollectionAssert.IsSubsetOf( IEnumerable subset, IEnumerable superset,
          string message );
CollectionAssert.IsSubsetOf( IEnumerable subset, IEnumerable superset,
          string message, params object[] args );

CollectionAssert.IsNotSubsetOf( IEnumerable subset, IEnumerable superset);
CollectionAssert.IsNotSubsetOf( IEnumerable subset, IEnumerable superset,
          string message );
CollectionAssert.IsNotSubsetOf( IEnumerable subset, IEnumerable superset,
          string message, params object[] args );

CollectionAssert.IsEmpty( IEnumerable collection );
CollectionAssert.IsEmpty( IEnumerable collection, string message );
CollectionAssert.IsEmpty( IEnumerable collection, string message,
          params object[] args );

CollectionAssert.IsNotEmpty( IEnumerable collection );
CollectionAssert.IsNotEmpty( IEnumerable collection, string message );
CollectionAssert.IsNotEmpty( IEnumerable collection, string message,
          params object[] args );

 

从NUnit2.5开始,可以使用以下方法:

View Code
CollectionAssert.IsOrdered( IEnumerable collection ); CollectionAssert.IsOrdered( IEnumerable collection, string message ); CollectionAssert.IsOrdered( IEnumerable collection, string message, params object [] args ); CollectionAssert.IsOrdered( IEnumerable collection, IComparer comparer ); CollectionAssert.IsOrdered( IEnumerable collection, IComparer comparer, string message ); CollectionAssert.IsOrdered( IEnumerable collection, IComparer comparer, string message, params object[] args );

 

FileAssert (NUnit 2.4)


FileAssert类提供了比较两个文件的方法,包括StreamFileInfo、指定文件路径string的参数格式。

 

View Code
FileAssert.AreEqual( Stream expected, Stream actual );
FileAssert.AreEqual( Stream expected, Stream actual, 
                string message );
FileAssert.AreEqual( Stream expected, Stream actual,
                string message, params object[] args );

FileAssert.AreEqual( FileInfo expected, FileInfo actual );
FileAssert.AreEqual( FileInfo expected, FileInfo actual, 
                string message );
FileAssert.AreEqual( FileInfo expected, FileInfo actual,
                string message, params object[] args );

FileAssert.AreEqual( string expected, string actual );
FileAssert.AreEqual( string expected, string actual, 
                string message );
FileAssert.AreEqual( string expected, string actual,
                string message, params object[] args );

FileAssert.AreNotEqual( Stream expected, Stream actual );
FileAssert.AreNotEqual( Stream expected, Stream actual, 
                string message );
FileAssert.AreNotEqual( Stream expected, Stream actual,
                string message, params object[] args );

FileAssert.AreNotEqual( FileInfo expected, FileInfo actual );
FileAssert.AreNotEqual( FileInfo expected, FileInfo actual, 
                string message );
FileAssert.AreNotEqual( FileInfo expected, FileInfo actual,
                string message, params object[] args );

FileAssert.AreNotEqual( string expected, string actual );
FileAssert.AreNotEqual( string expected, string actual, 
                string message );
FileAssert.AreNotEqual( string expected, string actual,
                string message, params object[] args );

 

DirectoryAssert (NUnit 2.5)

DirectoryAssert类提供了一系列方法来比较文件系统目录,DirectoryInfo或者指定目录路径的string格式的参数。

DirectoryAssert.AreEqual() and DirectoryAssert.AreNotEqual() 比较两个目录是否相等。如果目录有相同的FullName, Attributes, CreationTime and LastAccessTime则认为是相等。

Note:如果不满足以上条件即使两个不同目录包含相同的文件也不相等

 

View Code
DirectoryAssert.AreEqual( DirectoryInfo expected, DirectoryInfo actual );
DirectoryAssert.AreEqual( DirectoryInfo expected, DirectoryInfo actual, 
                string message );
DirectoryAssert.AreEqual( DirectoryInfo expected, DirectoryInfo actual,
                string message, params object[] args );

DirectoryAssert.AreEqual( string expected, string actual );
DirectoryAssert.AreEqual( string expected, string actual, 
                string message );
DirectoryAssert.AreEqual( string expected, string actual,
                string message, params object[] args );

DirectoryAssert.AreNotEqual( DirectoryInfo expected, DirectoryInfo actual );
DirectoryAssert.AreNotEqual( DirectoryInfo expected, DirectoryInfo actual, 
                string message );
DirectoryAssert.AreNotEqual( DirectoryInfo expected, DirectoryInfo actual,
                string message, params object[] args );

DirectoryAssert.AreNotEqual( string expected, string actual );
DirectoryAssert.AreNotEqual( string expected, string actual, 
                string message );
DirectoryAssert.AreNotEqual( string expected, string actual,
                string message, params object[] args );

DirectoryAssert.IsEmpty() and DirectoryAssert.IsNotEmpty() 检测指定的目录是否为empty

View Code
DirectoryAssert.IsEmpty( DirectoryInfo directory );
DirectoryAssert.IsEmpty( DirectoryInfo directory, string message );
DirectoryAssert.IsEmpty( DirectoryInfo directory,
                string message, params object[] args );

DirectoryAssert.IsEmpty( string directory );
DirectoryAssert.IsEmpty( string directory, string message );
DirectoryAssert.IsEmpty( string directory,
                string message, params object[] args );

DirectoryAssert.IsNotEmpty( DirectoryInfo directory );
DirectoryAssert.IsNotEmpty( DirectoryInfo directory, string message );
DirectoryAssert.IsNotEmpty( DirectoryInfo directory,
                string message, params object[] args );

DirectoryAssert.IsNotEmpty( string directory );
DirectoryAssert.IsNotEmpty( string directory, string message );
DirectoryAssert.IsNotEmpty( string directory,
                string message, params object[] args );

DirectoryAssert.IsWithin() and DirectoryAssert.IsNotWithin()检测第二个目录是否是第一个目录的直接或者间接子目录。

 

View Code
DirectoryAssert.IsWithin( DirectoryInfo expected, DirectoryInfo actual );
DirectoryAssert.IsWithin( DirectoryInfo expected, DirectoryInfo actual,
                string message );
DirectoryAssert.IsWithin( DirectoryInfo expected, DirectoryInfo actual,
                string message, params object[] args );

DirectoryAssert.IsWithin( string expected, string actual );
DirectoryAssert.IsWithin( string expected, string actual,
                string message );
DirectoryAssert.IsWithin( string expected, string actual,
                string message, params object[] args );

DirectoryAssert.IsNotWithin( DirectoryInfo expected, DirectoryInfo actual );
DirectoryAssert.IsNotWithin( DirectoryInfo expected, DirectoryInfo actual,
                string message );
DirectoryAssert.IsNotWithin( DirectoryInfo expected, DirectoryInfo actual,
                string message, params object[] args );

DirectoryAssert.IsNotWithin( string expected, string actual );
DirectoryAssert.IsNotWithin( string expected, string actual,
                string message );
DirectoryAssert.IsNotWithin( string expected, string actual,
                string message, params object[] args );

 

你可能感兴趣的:(Collection)