[Adapdev-commits] Adapdev/src/Adapdev.Tests Adapdev.Tests.csproj,1.7,1.8 CompositeValidatorTest.cs,1
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 07:02:14
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.Tests Added Files: Adapdev.Tests.csproj CompositeValidatorTest.cs IValidatorTest.cs ObjectComparerTest.cs Log Message: --- NEW FILE: CompositeValidatorTest.cs --- using System; using System.Collections; using NUnit.Framework; using Adapdev; namespace Adapdev.Tests { /// <summary> /// Summary description for IValidatable. /// </summary> /// [TestFixture] public class CompositeValidatorTest { public static string BadHeightMessage = "Height must be greater than zero."; public static string BadWidthMessage = "Width must be greater than zero."; public static string NoSquareMessage = "Must be a rectangle, not a square. Please use the Square object for squares."; [Test] public void Invalid() { Rectangle rectangle = new Rectangle(); rectangle.Height = 2; rectangle.Width = 2; ValidationResult vr = rectangle.Validate(); Console.WriteLine(vr.Message); Assert.IsFalse(vr.IsValid, "Object should not be valid."); Assert.IsTrue(vr.Message.Length > 0); Assert.IsTrue(vr.Message.IndexOf(CompositeValidatorTest.NoSquareMessage) >= 0); Assert.AreEqual(CompositeValidatorTest.NoSquareMessage + Environment.NewLine + Environment.NewLine, vr.Message); } [Test] public void Valid() { Rectangle rectangle = new Rectangle(); rectangle.Height = 3; rectangle.Width = 2; ValidationResult vr = rectangle.Validate(); Assert.IsTrue(vr.IsValid); Assert.IsTrue(vr.Message.Length == 0, "Object should not have a validation message."); } } public class Rectangle : CompositeValidator { public Rectangle() { this.AddRule(new RectangleNoSquareRule(this)); this.AddRule(new RectangleHeightRule(this)); this.AddRule(new RectangleWidthRule(this)); } public int Height = 0; public int Width = 0; } public class RectangleNoSquareRule : IValidationRule { private Rectangle _rectangle; public RectangleNoSquareRule(Rectangle r) { this._rectangle = r; } #region IValidationRule Members public ValidationResult Validate() { ValidationResult vr = new ValidationResult(); if(this._rectangle.Height == this._rectangle.Width) { vr.IsValid = false; vr.AddMessage(CompositeValidatorTest.NoSquareMessage); } return vr; } #endregion } public class RectangleHeightRule : IValidationRule { #region IValidationRule Members private Rectangle _rectangle; public RectangleHeightRule(Rectangle r) { this._rectangle = r; } public ValidationResult Validate() { ValidationResult vr = new ValidationResult(); if(this._rectangle.Height <= 0) { vr.IsValid = false; vr.AddMessage(CompositeValidatorTest.BadHeightMessage); } return vr; } #endregion } public class RectangleWidthRule : IValidationRule { #region IValidationRule Members private Rectangle _rectangle; public RectangleWidthRule(Rectangle r) { this._rectangle = r; } public ValidationResult Validate() { ValidationResult vr = new ValidationResult(); if(this._rectangle.Width <= 0) { vr.IsValid = false; vr.AddMessage(CompositeValidatorTest.BadWidthMessage); } return vr; } #endregion } } --- NEW FILE: ObjectComparerTest.cs --- using System; using System.Text; using System.Threading; using Adapdev.Mock; using Adapdev.Serialization; using NUnit.Framework; namespace Adapdev.Tests { /// <summary> /// Summary description for ObjectComparerTest. /// </summary> /// [TestFixture] public class ObjectComparerTest { [Test] public void AreEqual() { DateTime now = DateTime.Now; SuppliersEntity e1 = new SuppliersEntity(); e1.Address = "Test"; e1.SupplierID = 12; e1.Created = now; SuppliersEntity e2 = new SuppliersEntity(); e2.Address = "Test"; e2.SupplierID = 12; e2.Created = now; Assert.IsTrue(ObjectComparer.AreEqual(e1, e2), "Objects should be equal."); e2.Created = DateTime.Now.AddHours(1); Assert.IsFalse(ObjectComparer.AreEqual(e1, e2), "Objects should not be equal."); } [Test] public void FailAreEqualWithFields() { DateTime now = DateTime.Now; SuppliersEntity e1 = new SuppliersEntity(); e1.Address = "Test"; e1.SupplierID = 12; e1.Created = now; Thread.Sleep(1000); SuppliersEntity e2 = new SuppliersEntity(); e2.Address = "Test"; e2.SupplierID = 12; e2.Created = now; //Console.WriteLine(e1); //Console.WriteLine(e2); Assert.IsFalse(ObjectComparer.AreEqual(e1, e2, true), "Objects should not be equal because InternalCreated is different."); } [Test] public void FailAreEqualWithFieldsSerialization() { DateTime now = DateTime.Now; SuppliersEntity e1 = new SuppliersEntity(); e1.Address = "Test"; e1.SupplierID = 12; e1.Created = now; SuppliersEntity e2 = new SuppliersEntity(); e2.Address = "Test"; e2.SupplierID = 12; e2.Created = now; string a = Serializer.SerializeToXml(e1); string b = Serializer.SerializeToXml(e2); Console.WriteLine(a); Console.WriteLine(b); Assert.IsTrue(a == b, "Objects should be equal."); e2.Created = DateTime.Now.AddHours(1); // byte[] c = Serializer.SerializeToBinary(e2); // // Assert.IsFalse(a == c, "Objects should not be equal."); } } } --- NEW FILE: IValidatorTest.cs --- using System; using NUnit.Framework; using Adapdev; namespace Adapdev.Tests { /// <summary> /// Summary description for IValidatable. /// </summary> /// [TestFixture] public class IValidatorTest { public static string BadHeightMessage = "Height must be greater than zero."; public static string BadWidthMessage = "Width must be greater than zero."; [Test] public void Invalid() { Square square = new Square(); square.Height = -1; square.Width = 0; ValidationResult vr = square.Validate(); Console.WriteLine(vr.Message); Assert.IsFalse(vr.IsValid, "Object should not be valid."); Assert.IsTrue(vr.Message.Length > 0); Assert.IsTrue(vr.Message.IndexOf(IValidatorTest.BadHeightMessage) >= 0); Assert.IsTrue(vr.Message.IndexOf(IValidatorTest.BadWidthMessage) >= 0); } [Test] public void Valid() { Square square = new Square(); square.Height = 2; square.Width = 2; ValidationResult vr = square.Validate(); Assert.IsTrue(vr.IsValid); Assert.IsTrue(vr.Message.Length == 0, "Object should not have a validation message."); } } public class Square : IValidator { #region IValidator Members public int Height = 0; public int Width = 0; public ValidationResult Validate() { ValidationResult vr = new ValidationResult(); if(this.Height <= 0) { vr.IsValid = false; vr.AddMessage(IValidatorTest.BadHeightMessage); } if(this.Width <= 0) { vr.IsValid = false; vr.AddMessage(IValidatorTest.BadWidthMessage); } return vr; } #endregion } } --- NEW FILE: Adapdev.Tests.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{6012639A-3857-46CC-80BC-32CBF1F104D7}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "Adapdev.Tests" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "Adapdev.Tests" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "nunit.framework" AssemblyName = "nunit.framework" HintPath = "..\..\lib\nunit.framework.dll" /> <Reference Name = "Adapdev" Project = "{CC30A321-2569-4B1F-8E1A-781B5509B56D}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "log4net" AssemblyName = "log4net" HintPath = "..\..\lib\log4net.dll" /> </References> </Build> <Files> <Include> <File RelPath = "AdapdevAssemblyInfo.cs" Link = "..\AdapdevAssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CompositeValidatorTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "IValidatorTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ObjectComparerTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Cryptography\CryptoTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Diagnostics\CPUMeterTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Diagnostics\PerfTimerFactoryTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Reflection\ClassAccessorCacheTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Reflection\ClassAccessorTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Reflection\FieldAccessorTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Reflection\FieldAccessorTestObject.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Reflection\PropertyAccessorTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Reflection\PropertyAccessorTestObject.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Text\Indexing\FullTextSearchTests.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Text\Indexing\RegExFilterTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Text\Indexing\SearchResultTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Text\Indexing\SpecialCharactersFilterTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Text\Indexing\StringTokenizerTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Text\Indexing\TokenAssertions.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Text\Indexing\TokenLengthFilterTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Text\Indexing\WordFilterTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "XPath\XPathObjectNavigatorTest.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> |