StringAsserters.cs :  » Business-Application » 32feet.NET » NUnit » Framework » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Business Application » 32feet.NET 
32feet.NET » NUnit » Framework » StringAsserters.cs
using System;

namespace NUnit.Framework{
  #region StringAsserter
  /// <summary>
  /// Abstract class used as a base for asserters that compare
  /// expected and an actual string values in some way or another.
  /// </summary>
  public abstract class StringAsserter : AbstractAsserter
  {
    /// <summary>
    /// The expected value, used as the basis for comparison.
    /// </summary>
    protected string expected;

    /// <summary>
    /// The actual value to be compared.
    /// </summary>
    protected string actual;

    /// <summary>
    /// Constructs a StringAsserter for two strings
    /// </summary>
    /// <param name="expected">The expected value</param>
    /// <param name="actual">The actual value</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public StringAsserter( string expected, string actual, string message, params object[] args )
      : base( message, args ) 
    {
      this.expected = expected;
      this.actual = actual;
    }

    /// <summary>
    /// Message related to a failure. If no failure has
    /// occured, the result is unspecified.
    /// </summary>
    public override string Message
    {
      get
      {
        FailureMessage.AddExpectedLine( Expectation );
        FailureMessage.DisplayActualValue( actual );
        return FailureMessage.ToString();
      }
    }

    /// <summary>
    /// String value that represents what the asserter expected
    /// to find. Defaults to the expected value itself.
    /// </summary>
    protected virtual string Expectation
    {
      get { return string.Format( "<\"{0}\">", expected ); }
    }
  }
  #endregion

  #region ContainsAsserter
  /// <summary>
  /// Summary description for ContainsAsserter.
  /// </summary>
  public class ContainsAsserter : StringAsserter
  {
    /// <summary>
    /// Constructs a ContainsAsserter for two strings
    /// </summary>
    /// <param name="expected">The expected substring</param>
    /// <param name="actual">The actual string to be examined</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public ContainsAsserter( string expected, string actual, string message, params object[] args )
      : base( expected, actual, message, args ) { }

    /// <summary>
    /// Test the assertion.
    /// </summary>
    /// <returns>True if the test succeeds</returns>
    public override bool Test()
    {
      return actual.IndexOf( expected ) >= 0;
    }

    /// <summary>
    /// String value that represents what the asserter expected
    /// </summary>
    protected override string Expectation
    {
      get { return string.Format( "String containing \"{0}\"", expected ); }
    }
  }
  #endregion

  #region StartsWithAsserter
  /// <summary>
  /// Summary description for StartsWithAsserter.
  /// </summary>
  public class StartsWithAsserter : StringAsserter
  {
    /// <summary>
    /// Constructs a StartsWithAsserter for two strings
    /// </summary>
    /// <param name="expected">The expected substring</param>
    /// <param name="actual">The actual string to be examined</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public StartsWithAsserter( string expected, string actual, string message, params object[] args )
      : base( expected, actual, message, args ) { }

    /// <summary>
    /// Test the assertion.
    /// </summary>
    /// <returns>True if the test succeeds</returns>
    public override bool Test()
    {
      return actual.StartsWith( expected );
    }

    /// <summary>
    /// String value that represents what the asserter expected
    /// </summary>
    protected override string Expectation
    {
      get { return string.Format( "String starting with \"{0}\"", expected ); }
    }
  }
  #endregion

  #region EndsWithAsserter
  /// <summary>
  /// Summary description for EndsWithAsserter.
  /// </summary>
  public class EndsWithAsserter : StringAsserter
  {
    /// <summary>
    /// Constructs a EndsWithAsserter for two strings
    /// </summary>
    /// <param name="expected">The expected substring</param>
    /// <param name="actual">The actual string to be examined</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public EndsWithAsserter( string expected, string actual, string message, params object[] args )
      : base( expected, actual, message, args ) { }

    /// <summary>
    /// Test the assertion.
    /// </summary>
    /// <returns>True if the test succeeds</returns>
    public override bool Test()
    {
      return actual.EndsWith( expected );
    }

    /// <summary>
    /// String value that represents what the asserter expected
    /// </summary>
    protected override string Expectation
    {
      get { return string.Format( "String ending with \"{0}\"", expected ); }
    }
  }
  #endregion

  #region EqualIgnoringCaseAsserter
  /// <summary>
  /// Asserter that implements AreEqualIgnoringCase
  /// </summary>
  public class EqualIgnoringCaseAsserter : StringAsserter
  {
    /// <summary>
    /// Constructs an EqualIgnoringCaseAsserter for two strings
    /// </summary>
    /// <param name="expected">The expected string</param>
    /// <param name="actual">The actual string</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public EqualIgnoringCaseAsserter( string expected, string actual, string message, params object[] args )
      : base( expected, actual, message, args ) { }

    /// <summary>
    /// Test the assertion.
    /// </summary>
    /// <returns>True if the test succeeds</returns>
    public override bool Test()
    {
      return string.Compare( expected, actual, true ) == 0;
    }

    /// <summary>
    /// String value that represents what the asserter expected
    /// </summary>
    public override string Message
    {
      get
      {
        FailureMessage.DisplayDifferences( expected, actual, true );
        return FailureMessage.ToString();
      }
    }
  }
  #endregion
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.