ConditionAsserters.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 » ConditionAsserters.cs
using System;
using System.Collections;

namespace NUnit.Framework{
  #region ConditionAsserter
  /// <summary>
  /// ConditionAsserter class represents an asssertion
  /// that tests a particular condition, which is passed
  /// to it in the constructor. The failure message is
  /// not specialized in this class, but derived classes
  /// are free to do so.
  /// </summary>
  public class ConditionAsserter : AbstractAsserter
  {
    /// <summary>
    /// The condition we are testing
    /// </summary>
    protected bool condition;

    /// <summary>
    /// Phrase indicating what we expected to find
    /// Ignored unless set by derived class
    /// </summary>
    protected string expectation;

    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="condition">The condition to be tested</param>
    /// <param name="message">The message issued upon failure</param>
    /// <param name="args">Arguments to be used in formatting the message</param>
    public ConditionAsserter( bool condition, string message, params object[] args )
      : base( message, args )
    {
      this.condition = condition;
    }

    /// <summary>
    /// Test the condition being asserted directly
    /// </summary>
    public override bool Test()
    {
      return condition;
    }
  }
  #endregion

  #region TrueAsserter
  /// <summary>
  /// Class to assert that a condition is true
  /// </summary>
  public class TrueAsserter : ConditionAsserter
  {
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="condition">The condition to assert</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public TrueAsserter( bool condition, string message, params object[] args )
      : base( condition, message, args ) { }
  }
  #endregion

  #region FalseAsserter
  /// <summary>
  /// Class to assert that a condition is false
  /// </summary>
  public class FalseAsserter : ConditionAsserter
  {
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="condition">The condition to assert</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public FalseAsserter( bool condition, string message, params object[] args )
      : base( !condition, message, args ) { }

  }
  #endregion

  #region NullAsserter
  /// <summary>
  /// Class to assert that an object is null
  /// </summary>
  public class NullAsserter : ConditionAsserter
  {
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="anObject">The object to test</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public NullAsserter( object anObject, string message, params object[] args )
      : base( anObject == null, message, args ) { }
  }
  #endregion

  #region NotNullAsserter
  /// <summary>
  /// Class to assert that an object is not null
  /// </summary>
  public class NotNullAsserter : ConditionAsserter
  {
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="anObject">The object to test</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public NotNullAsserter( object anObject, string message, params object[] args )
      : base( anObject != null, message, args ) { }
  }
  #endregion

  #region NaNAsserter
  /// <summary>
  /// Class to assert that a double is an NaN
  /// </summary>
  public class NaNAsserter : ConditionAsserter
  {
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="aDouble">The value to test</param>
    /// <param name="message">The message to issue on failure</param>
    /// <param name="args">Arguments to apply in formatting the message</param>
    public NaNAsserter( double aDouble, string message, params object[] args )
      : base( double.IsNaN( aDouble ), message, args ) { }
  }
  #endregion

  #region EmptyAsserter
  /// <summary>
  /// Class to Assert that a string or collection is empty
  /// </summary>
  public class EmptyAsserter : ConditionAsserter
  {
    /// <summary>
    /// Construct an EmptyAsserter for a string
    /// </summary>
    /// <param name="aString">The string to be tested</param>
    /// <param name="message">The message to display if the string is not empty</param>
    /// <param name="args">Arguements to use in formatting the message</param>
    public EmptyAsserter( string aString, string message, params object[] args )
      : base( aString == string.Empty, message, args ) { }

    /// <summary>
    /// Construct an EmptyAsserter for a collection
    /// </summary>
    /// <param name="collection">The collection to be tested</param>
    /// <param name="message">The message to display if the collection is not empty</param>
    /// <param name="args">Arguements to use in formatting the message</param>
    public EmptyAsserter( ICollection collection, string message, params object[] args )
      : base( collection.Count == 0, message, args ) { }
  }
  #endregion

  #region NotEmptyAsserter
  /// <summary>
  /// Class to Assert that a string or collection is not empty
  /// </summary>
  public class NotEmptyAsserter : ConditionAsserter
  {
    /// <summary>
    /// Construct a NotEmptyAsserter for a string
    /// </summary>
    /// <param name="aString">The string to be tested</param>
    /// <param name="message">The message to display if the string is empty</param>
    /// <param name="args">Arguements to use in formatting the message</param>
    public NotEmptyAsserter( string aString, string message, params object[] args )
      : base( aString != string.Empty, message, args ) { }

    /// <summary>
    /// Construct a NotEmptyAsserter for a collection
    /// </summary>
    /// <param name="collection">The collection to be tested</param>
    /// <param name="message">The message to display if the collection is empty</param>
    /// <param name="args">Arguements to use in formatting the message</param>
    public NotEmptyAsserter( ICollection collection, string message, params object[] args )
      : base( collection.Count != 0, message, args ) { }
  }
  #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.