Permalink
Browse files

add unit test NHibernateValidatorProviderTests

  • Loading branch information...
1 parent 0896df9 commit e73658a623d536ef929a2dcd4ddd1a44dc92f475 @manishma manishma committed with alecwhittington May 16, 2010
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Web.Mvc;
+using NHibernate.Validator.Constraints;
+using NUnit.Framework;
+using SharpArch.Core.NHibernateValidator.ValidatorProvider;
+
+namespace Tests.SharpArch.Core.NHibernateValidator.ValidatorProvider
+{
+ [TestFixture]
+ public class NHibernateValidatorProviderTests
+ {
+ private NHibernateValidatorProvider _validatorProvider;
+ private ViewDataDictionary<TestModel> _viewData;
+ private ControllerContext _controllerContext;
+
+ class TestModel
+ {
+ [NotNull]
+ public string NotNullProperty { get; set; }
+
+ [NotEmpty]
+ public string NotEmptyStringProperty { get; set; }
+ }
+
+ [SetUp]
+ public void SetUp()
+ {
+ _validatorProvider = new NHibernateValidatorProvider();
+ _viewData = new ViewDataDictionary<TestModel>();
+ _controllerContext = new ControllerContext();
+ }
+
+ [Test]
+ public void NotNullProperty()
+ {
+ var modelMetadata =
+ ModelMetadata.FromLambdaExpression<TestModel, string>(x => x.NotNullProperty, _viewData);
+
+ var modelValidators = _validatorProvider.GetValidators(modelMetadata, _controllerContext);
+
+ Assert.That(modelValidators, Is.Not.Empty);
+
+ var validationRules = modelValidators.SelectMany(x => x.GetClientValidationRules()).ToList();
+
+ Assert.That(validationRules.Count, Is.EqualTo(1));
+
+ var validationRule = validationRules[0];
+
+ Assert.That(validationRule.ValidationType, Is.EqualTo("required"));
+
+ //Assert.That(validationRule.ErrorMessage, Is.EqualTo(""));
+ }
+ }
+}
@@ -108,6 +108,7 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SharpArch.Core.NHibernateValidator\CommonValidatorAdapter\ValidatorTests.cs" />
+ <Compile Include="SharpArch.Core.NHibernateValidator\ValidatorProvider\NHibernateValidatorProviderTests.cs" />
<Compile Include="SharpArch.Core\DesignByContractTests.cs" />
<Compile Include="SharpArch.Core\DomainModel\BaseObjectEqualityComparerTests.cs" />
<Compile Include="SharpArch.Core\DomainModel\EntityTests.cs" />
@@ -146,6 +147,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

0 comments on commit e73658a

Please sign in to comment.