public void Parse_TypeInv_Error()
		{
			CustomAssert.ThrowsException<CodedArgumentOutOfRangeException>(() =>
			{
				ConstraintParser parser = new ConstraintParser();
				parser.Parse(Constants.SimpleConstraintString, ParameterDataType.None);
			});
		}
		public void Parse_EmptyConstraint_Error()
		{
			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				ConstraintParser parser = new ConstraintParser();
				parser.Parse("[   ]", ParameterDataType.Int32);
			});
		}
		public void Parse_StringNull_Success()
		{
			ConstraintParser parser = new ConstraintParser();
			IReadOnlyList<Constraint> constraints = parser.Parse(null, ParameterDataType.Int32);
			Assert.AreEqual(0, constraints.Count);
		}
		private ConstraintParser CreateParserWithDummy()
		{
			ConstraintParser parser = new ConstraintParser();
			parser.UnknownConstraint += (sender, e) =>
			{
				if (e.ConstraintName == "Dummy")
				{
					e.Constraint = new DummyConstraint();
				}
			};

			return parser;
		}
		public void Parse_InvalidDataTypes_Error()
		{
			ConstraintParser parser = new ConstraintParser();
			IReadOnlyList<Constraint> constraints;

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[AllowedScheme(http)]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[CharSet(Ascii)]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[DecimalPlaces(2)]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[Endpoint]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[Values(Int32,MyValue=1)]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[FileName]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[Host]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[Length(5)]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[Lowercase]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[MaxLength(5)]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[MaxValue(42)]", ParameterDataType.String);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[MinLength(5)]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[MinValue(42)]", ParameterDataType.String);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[Password]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[Regex(.*)]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[Step(3)]", ParameterDataType.String);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse(string.Format("[Type('{0}')]", typeof(XmlSerializableObject).AssemblyQualifiedName), ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				constraints = parser.Parse("[Uppercase]", ParameterDataType.Int32);
			});
		}
		public void Parse_AllConstraints_Success()
		{
			ConstraintParser parser = new ConstraintParser();
			IReadOnlyList<Constraint> constraints;

			constraints = parser.Parse("[AllowedScheme(http)]", ParameterDataType.Uri);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(AllowedSchemeConstraint));

			constraints = parser.Parse("[CharSet(Ascii)]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(CharacterSetConstraint));

			constraints = parser.Parse("[Database(MyTable,MyValue)]", ParameterDataType.Int32);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(DatabaseConstraint));

			constraints = parser.Parse("[DecimalPlaces(2)]", ParameterDataType.Decimal);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(DecimalPlacesConstraint));

			constraints = parser.Parse("[Encrypted]", ParameterDataType.Uri);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(EncryptedConstraint));

			constraints = parser.Parse("[Endpoint]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(EndpointConstraint));

			constraints = parser.Parse("[Values(Int32,MyValue=1)]", ParameterDataType.Enum);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(EnumValuesConstraint));

			constraints = parser.Parse("[FileName]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(FileNameConstraint));

			constraints = parser.Parse("[Host]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(HostNameConstraint));

			constraints = parser.Parse("[Length(5)]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(LengthConstraint));

			constraints = parser.Parse("[Lowercase]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(LowercaseConstraint));

			constraints = parser.Parse("[MaxLength(5)]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(MaximumLengthConstraint));

			constraints = parser.Parse("[MaxValue(42)]", ParameterDataType.Int32);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(MaximumValueConstraint));

			constraints = parser.Parse("[MinLength(5)]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(MinimumLengthConstraint));

			constraints = parser.Parse("[MinValue(42)]", ParameterDataType.Int32);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(MinimumValueConstraint));

			constraints = parser.Parse("[Null]", ParameterDataType.Uri);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(NullConstraint));

			constraints = parser.Parse("[Password]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(PasswordConstraint));

			constraints = parser.Parse("[Path]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(PathConstraint));

			constraints = parser.Parse("[Regex(.*)]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(RegexConstraint));

			constraints = parser.Parse("[Step(3)]", ParameterDataType.Int32);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(StepConstraint));

			constraints = parser.Parse(string.Format("[Type('{0}')]", typeof(XmlSerializableObject).AssemblyQualifiedName), ParameterDataType.Xml);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(TypeConstraint));

			constraints = parser.Parse(string.Format("[Type('{0}')]", typeof(DayOfWeek).AssemblyQualifiedName), ParameterDataType.Enum);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(EnumTypeConstraint));

			constraints = parser.Parse("[Uppercase]", ParameterDataType.String);
			Assert.AreEqual(1, constraints.Count);
			Assert.IsInstanceOfType(constraints[0], typeof(UppercaseConstraint));
		}
		public void Parse_UnknownConstraint_Error()
		{
			ConstraintParser parser = new ConstraintParser();
			parser.UnknownConstraint += (sender, e) =>
			{
			};

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				parser.Parse("[YouThinkYouKnowMe]", ParameterDataType.Int32);
			});

			CustomAssert.ThrowsException<ConstraintParserException>(() =>
			{
				parser.Parse("[Path]", ParameterDataType.Int32);
			});
		}