PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/src/NUnit/framework/Constraints/EmptyConstraint.cs

#
C# | 53 lines | 29 code | 5 blank | 19 comment | 3 complexity | 26091de15c5c48b7375209f4b172f3fa MD5 | raw file
 1// ****************************************************************
 2// Copyright 2007, Charlie Poole
 3// This is free software licensed under the NUnit license. You may
 4// obtain a copy of the license at http://nunit.org
 5// ****************************************************************
 6
 7using System;
 8using System.Collections;
 9
10namespace NUnit.Framework.Constraints
11{
12	/// <summary>
13	/// EmptyConstraint tests a whether a string or collection is empty,
14	/// postponing the decision about which test is applied until the
15	/// type of the actual argument is known.
16	/// </summary>
17	public class EmptyConstraint : Constraint
18	{
19		private Constraint RealConstraint
20		{
21			get 
22			{
23                if (actual is string)
24                    return new EmptyStringConstraint();
25                else if (actual is System.IO.DirectoryInfo)
26                    return new EmptyDirectoryContraint();
27                else
28					return new EmptyCollectionConstraint();
29			}
30		}
31		
32		/// <summary>
33        /// Test whether the constraint is satisfied by a given value
34        /// </summary>
35        /// <param name="actual">The value to be tested</param>
36        /// <returns>True for success, false for failure</returns>
37		public override bool Matches(object actual)
38		{
39			this.actual = actual;
40
41			return this.RealConstraint.Matches( actual );
42		}
43
44        /// <summary>
45        /// Write the constraint description to a MessageWriter
46        /// </summary>
47        /// <param name="writer">The writer on which the description is displayed</param>
48		public override void WriteDescriptionTo(MessageWriter writer)
49		{
50			this.RealConstraint.WriteDescriptionTo( writer );
51		}
52	}
53}