Repository: andrebaltieri/flunt Branch: main Commit: 38f159b1fd48 Files: 64 Total size: 589.4 KB Directory structure: gitextract_dejsxxuh/ ├── .github/ │ └── workflows/ │ └── main.yml ├── .gitignore ├── Flunt/ │ ├── Flunt.csproj │ ├── Localization/ │ │ ├── FluntErrorMessages.cs │ │ ├── FluntFormats.cs │ │ └── FluntRegexPatterns.cs │ ├── Notifications/ │ │ ├── INotifiable.cs │ │ ├── Notifiable.cs │ │ └── Notification.cs │ └── Validations/ │ ├── BoolValidationContract.cs │ ├── Contract.cs │ ├── CreditCardValidation.cs │ ├── DateTimeValidationContract.cs │ ├── DecimalValidationContract.cs │ ├── DocumentValitionContract.cs │ ├── DoubleValidationContract.cs │ ├── EmailValidationContract.cs │ ├── FloatValidationContract.cs │ ├── GuidValidationContract.cs │ ├── IntValidationContract.cs │ ├── ListValidationContract.cs │ ├── LongValidationContract.cs │ ├── ObjectValidationContract.cs │ ├── RegexValidationContract.cs │ ├── StringValidationContract.cs │ ├── TimeSpanValidationContract.cs │ └── UrlValidationContract.cs ├── Flunt.Samples/ │ ├── Entities/ │ │ ├── Contracts/ │ │ │ ├── CreateCustomerContract.cs │ │ │ └── UpdateCustomerBirthDateContract.cs │ │ ├── Customer.cs │ │ ├── Entity.cs │ │ ├── Order.cs │ │ └── OrderLine.cs │ ├── Flunt.Samples.csproj │ ├── Handlers/ │ │ ├── CustomerHandler.cs │ │ └── Requests/ │ │ ├── Contracts/ │ │ │ └── CreateCustomerRequestContract.cs │ │ └── CreateCustomerRequest.cs │ ├── Program.cs │ └── ValueObjects/ │ ├── Contracts/ │ │ └── CreateEmailContract.cs │ └── Email.cs ├── Flunt.Tests/ │ ├── BoolValidationTests.cs │ ├── CreditCardValidationTests.cs │ ├── CustomNotificationsTests.cs │ ├── DateTimeValidationTests.cs │ ├── DecimalValidationTests.cs │ ├── DocumentValidationTests.cs │ ├── DoubleValidationTests.cs │ ├── EmailValidationTests.cs │ ├── Entities/ │ │ └── SampleEntity.cs │ ├── Enums/ │ │ └── SampleEnum.cs │ ├── FloatValidationTests.cs │ ├── Flunt.Tests.csproj │ ├── GuidValidationTests.cs │ ├── IntValidationTests.cs │ ├── ListValidationTests.cs │ ├── LongValidationTests.cs │ ├── ObjectValidationTests.cs │ ├── RegexValidationTests.cs │ ├── StringValidationTests.cs │ ├── TimeSpanValidationTests.cs │ └── UrlValidationTests.cs ├── Flunt.sln ├── LICENSE └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/main.yml ================================================ name: Build and deploy package on: push: branches: - main jobs: build-and-deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@main - name: Set up .NET Core uses: actions/setup-dotnet@v1 with: dotnet-version: '5.0.x' - name: Build with dotnet run: dotnet build --configuration Release - name: Test run: dotnet test - name: Create the Package run: dotnet pack --configuration Release - name: Publish run: dotnet nuget push "Flunt/bin/Release/*.nupkg" -k ${{ secrets.NUGET_TOKEN }} -s https://api.nuget.org/v3/index.json ================================================ FILE: .gitignore ================================================ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. .vscode/* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json .DS_Store .vscode # User-specific files *.suo *.user *.userosscache *.sln.docstates # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs # Build results [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ x64/ x86/ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ # Visual Studio 2015 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* # NUNIT *.VisualState.xml TestResult.xml # Build Results of an ATL Project [Dd]ebugPS/ [Rr]eleasePS/ dlldata.c # DNX project.lock.json project.fragment.lock.json artifacts/ *_i.c *_p.c *_i.h *.ilk *.meta *.obj *.pch *.pdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.tmp_proj *.log *.vspscc *.vssscc .builds *.pidb *.svclog *.scc # Chutzpah Test files _Chutzpah* # Visual C++ cache files ipch/ *.aps *.ncb *.opendb *.opensdf *.sdf *.cachefile *.VC.db *.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx *.sap # TFS 2012 Local Workspace $tf/ # Guidance Automation Toolkit *.gpState # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user # JustCode is a .NET coding add-in .JustCode # TeamCity is a build add-in _TeamCity* # DotCover is a Code Coverage Tool *.dotCover # Visual Studio code coverage results *.coverage *.coveragexml # NCrunch _NCrunch_* .*crunch*.local.xml nCrunchTemp_* # MightyMoose *.mm.* AutoTest.Net/ # Web workbench (sass) .sass-cache/ # Installshield output folder [Ee]xpress/ # DocProject is a documentation generator add-in DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC DocProject/Help/*.hhc DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 DocProject/Help/html # Click-Once directory publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml # TODO: Comment the next line if you want to checkin your web deploy settings # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to # checkin your Azure Web App publish settings, but sensitive information contained # in these scripts will be unencrypted PublishScripts/ # NuGet Packages *.nupkg # The packages folder can be ignored because of Package Restore **/packages/* # except build/, which is used as an MSBuild target. !**/packages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/packages/repositories.config # NuGet v3's project.json files produces more ignoreable files *.nuget.props *.nuget.targets # Microsoft Azure Build Output csx/ *.build.csdef # Microsoft Azure Emulator ecf/ rcf/ # Windows Store app package directories and files AppPackages/ BundleArtifacts/ Package.StoreAssociation.xml _pkginfo.txt # Visual Studio cache files # files ending in .cache can be ignored *.[Cc]ache # but keep track of directories ending in .cache !*.[Cc]ache/ # Others ClientBin/ ~$* *~ *.dbmdl *.dbproj.schemaview *.jfm *.pfx *.publishsettings node_modules/ orleans.codegen.cs # Since there are multiple workflows, uncomment next line to ignore bower_components # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) #bower_components/ # RIA/Silverlight projects Generated_Code/ # Backup & report files from converting an old project file # to a newer Visual Studio version. Backup files are not needed, # because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm # SQL Server files *.mdf *.ldf # Business Intelligence projects *.rdl.data *.bim.layout *.bim_*.settings # Microsoft Fakes FakesAssemblies/ # GhostDoc plugin setting file *.GhostDoc.xml # Node.js Tools for Visual Studio .ntvs_analysis.dat # Visual Studio 6 build log *.plg # Visual Studio 6 workspace options file *.opt # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts **/*.DesktopClient/ModelManifest.xml **/*.Server/GeneratedArtifacts **/*.Server/ModelManifest.xml _Pvt_Extensions # Paket dependency manager .paket/paket.exe paket-files/ # FAKE - F# Make .fake/ # JetBrains Rider .idea/ *.sln.iml # CodeRush .cr/ # Python Tools for Visual Studio (PTVS) __pycache__/ *.pyc # Cake - Uncomment if you are using it # tools/ ================================================ FILE: Flunt/Flunt.csproj ================================================ netstandard2.0 Flunt 2.0.5 https://baltaio.blob.core.windows.net/static/images/icons/flunt-icon.png MIT André Baltieri balta.io Notifications made easy Notifications made easy https://github.com/andrebaltieri/Flunt https://github.com/andrebaltieri/Flunt MIT icon.png Domain;DDD;Notification;Validation;Flunt Breaking changes from v1.5, please, visit our GitHub before migrating. Flunt Flunt is a fluent way to use Notification Pattern with your entities, concentrating every change you made and easy accessing it when you need. ================================================ FILE: Flunt/Localization/FluntErrorMessages.cs ================================================ namespace Flunt.Localization { public static class FluntErrorMessages { public static string AndLocalizationErrorMessageLocalization = "and"; public static string OrLocalizationErrorMessageLocalization = "or"; public static string IsFalseLocalizationErrorMessage = $"should not be true"; public static string IsTrueLocalizationErrorMessage = $"should not be false"; public static string IsEmptyLocalizationErrorMessage = $"should be empty"; public static string IsNotEmptyLocalizationErrorMessage = $"should not be empty"; public static string IsNotNullOrEmptyLocalizationErrorMessage = $"should not be null or empty"; public static string IsNotNullLocalizationErrorMessage = $"should not be null"; public static string IsNullLocalizationErrorMessage = $"should be null"; public static string IsNullOrEmptyLocalizationErrorMessage = $"should be null or empty"; public static string IsNullOrWhiteSpaceLocalizationErrorMessage = "should be null or white space"; public static string IsNotNullOrWhiteSpaceLocalizationErrorMessage = "should not be null or white space"; public static string IsGreaterThanLocalizationErrorMessage = $"should be greater than"; public static string IsGreaterOrEqualsThanLocalizationErrorMessage = $"should be greater or equals than"; public static string IsLowerThanLocalizationErrorMessage = $"should be lower than"; public static string IsLowerOrEqualsThanLocalizationErrorMessage = $"should be lower or equals than"; public static string IsBetweenLocalizationErrorMessage = $"should be between"; public static string IsNotBetweenLocalizationErrorMessage = $"should not be between"; public static string IsMinValueLocalizationErrorMessage = $"should be"; public static string IsNotMinValueLocalizationErrorMessage = $"should not be"; public static string IsMaxValueLocalizationErrorMessage = $"should be"; public static string IsNotMaxValueLocalizationErrorMessage = $"should not be"; public static string AreEqualsLocalizationErrorMessage = $"should be equals"; public static string AreNotEqualsLocalizationErrorMessage = $"should not be equals"; public static string ContainsLocalizationErrorMessage = $"should contain value"; public static string NotContainsLocalizationErrorMessage = $"should not contain value"; public static string IsCreditCardLocalizationErrorMessage = $"should be a credit card number"; public static string MatchesLocalizationErrorMessage = $"does not matches pattern"; public static string NotMatchesLocalizationErrorMessage = $"should not matches pattern"; public static string IsEmailLocalizationErrorMessage = $"should be an email"; public static string IsEmailOrEmptyLocalizationErrorMessage = $"should be an email or empty"; public static string IsNotEmailLocalizationErrorMessage = $"should not be an email"; public static string IsUrlLocalizationErrorMessage = "should be an URL"; public static string IsNotUrlLocalizationErrorMessage = "should not be an URL"; public static string IsPassportLocalizationErrorMessage = "should be a passport number"; public static string IsFalseErrorMessage(string key) => $"{key} {IsFalseLocalizationErrorMessage}"; public static string IsTrueErrorMessage(string key) => $"{key} {IsTrueLocalizationErrorMessage}"; public static string IsEmptyErrorMessage(string key) => $"{key} {IsEmptyLocalizationErrorMessage}"; public static string IsNotEmptyErrorMessage(string key) => $"{key} {IsNotEmptyLocalizationErrorMessage}"; public static string IsNotNullOrEmptyErrorMessage(string key) => $"{key} {IsNotNullOrEmptyLocalizationErrorMessage}"; public static string IsNotNullErrorMessage(string key) => $"{key} {IsNotNullLocalizationErrorMessage}"; public static string IsNullErrorMessage(string key) => $"{key} {IsNullLocalizationErrorMessage}"; public static string IsNullOrEmptyErrorMessage(string key) => $"{key} {IsNullOrEmptyLocalizationErrorMessage}"; public static string IsNullOrWhiteSpaceErrorMessage(string key) => $"{key} {IsNullOrWhiteSpaceLocalizationErrorMessage}"; public static string IsNotNullOrWhiteSpaceErrorMessage(string key) => $"{key} {IsNotNullOrWhiteSpaceLocalizationErrorMessage}"; public static string IsGreaterThanErrorMessage(string key, string comparer) => $"{key} {IsGreaterThanLocalizationErrorMessage} {comparer}"; public static string IsGreaterOrEqualsThanErrorMessage(string key, string comparer) => $"{key} {IsGreaterOrEqualsThanLocalizationErrorMessage} {comparer}"; public static string IsLowerThanErrorMessage(string key, string comparer) => $"{key} {IsLowerThanLocalizationErrorMessage} {comparer}"; public static string IsLowerOrEqualsThanErrorMessage(string key, string comparer) => $"{key} {IsLowerOrEqualsThanLocalizationErrorMessage} {comparer}"; public static string IsBetweenErrorMessage(string key, string start, string end) => $"{key} {IsBetweenLocalizationErrorMessage} {start} {AndLocalizationErrorMessageLocalization} {end}"; public static string IsNotBetweenErrorMessage(string key, string start, string end) => $"{key} {IsNotBetweenLocalizationErrorMessage} {start} {AndLocalizationErrorMessageLocalization} {end}"; public static string IsMinValueErrorMessage(string key, string minValue) => $"{key} {IsMinValueLocalizationErrorMessage} {minValue}"; public static string IsNotMinValueErrorMessage(string key, string minValue) => $"{key} {IsNotMinValueLocalizationErrorMessage} {minValue}"; public static string IsMaxValueErrorMessage(string key, string maxValue) => $"{key} {IsMaxValueLocalizationErrorMessage} {maxValue}"; public static string IsNotMaxValueErrorMessage(string key, string maxValue) => $"{key} {IsNotMaxValueLocalizationErrorMessage} {maxValue}"; public static string AreEqualsErrorMessage(string val, string comparer) => $"{val} {AreEqualsLocalizationErrorMessage} {comparer}"; public static string AreNotEqualsErrorMessage(string val, string comparer) => $"{val} {AreNotEqualsLocalizationErrorMessage} {comparer}"; public static string ContainsErrorMessage(string key, string comparer) => $"{key} {ContainsLocalizationErrorMessage} {comparer}"; public static string NotContainsErrorMessage(string key, string comparer) => $"{key} {NotContainsLocalizationErrorMessage} {comparer}"; public static string IsCreditCardErrorMessage(string key) => $"{key} {IsCreditCardLocalizationErrorMessage}"; public static string MatchesErrorMessage(string key, string pattern) => $"{key} {MatchesLocalizationErrorMessage} {pattern}"; public static string NotMatchesErrorMessage(string key, string pattern) => $"{key} {NotMatchesLocalizationErrorMessage} {pattern}"; public static string IsEmailErrorMessage(string key) => $"{key} {IsEmailLocalizationErrorMessage}"; public static string IsEmailOrEmptyErrorMessage(string key) => $"{key}{IsEmailOrEmptyLocalizationErrorMessage}"; public static string IsNotEmailErrorMessage(string key) => $"{key} {IsNotEmailLocalizationErrorMessage}"; public static string IsUrlErrorMessage(string key) => $"{key} {IsUrlLocalizationErrorMessage}"; public static string IsNotUrlErrorMessage(string key) => $"{key} {IsNotUrlLocalizationErrorMessage}"; public static string IsUrlOrEmptyErrorMessage(string key) => $"{key} {IsUrlLocalizationErrorMessage} {OrLocalizationErrorMessageLocalization} {IsEmptyLocalizationErrorMessage}"; public static string IsNotUrlOrEmptyErrorMessage(string key) => $"{key} {IsNotUrlLocalizationErrorMessage} {OrLocalizationErrorMessageLocalization} {IsEmptyLocalizationErrorMessage}"; public static string IsPassportErrorMessage(string key) => $"{key} {IsPassportLocalizationErrorMessage}"; } } ================================================ FILE: Flunt/Localization/FluntFormats.cs ================================================ namespace Flunt.Localization { public static class FluntFormats { public static string DateFormat = "MM/DD/yyyy"; public static string DateTimeFormat = "MM/DD/yyyy hh:mm"; } } ================================================ FILE: Flunt/Localization/FluntRegexPatterns.cs ================================================ namespace Flunt.Localization { public static class FluntRegexPatterns { public static string EmailRegexPattern = @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"; public static string UrlRegexPattern = @"^(http|https):(\/\/www\.|\/\/www\.|\/\/|\/\/)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$|(http|https):(\/\/localhost:\d*|\/\/127\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))(:[0-9]{1,5})?(\/.*)?$"; public static string OnlyNumbersPattern = @"[^0-9]+"; public static string OnlyLettersAndNumbersPattern = @"[A-Za-z0-9_-]"; public static string PassportRegexPattern = @"^(?!^0+$)[a-zA-Z0-9]{3,20}$"; } } ================================================ FILE: Flunt/Notifications/INotifiable.cs ================================================ using System.Collections.Generic; namespace Flunt.Notifications { public interface INotifiable { void AddNotifications(IEnumerable notifications); } } ================================================ FILE: Flunt/Notifications/Notifiable.cs ================================================ using System; using System.Collections.Generic; using System.Linq; namespace Flunt.Notifications { public abstract class Notifiable where T : Notification { private readonly List _notifications; protected Notifiable() => _notifications = new List(); private T GetNotificationInstance(string key, string message) { return (T)Activator.CreateInstance(typeof(T), new object[] { key, message }); } public IReadOnlyCollection Notifications => _notifications; public void AddNotification(string key, string message) { var notification = GetNotificationInstance(key, message); _notifications.Add(notification); } public void AddNotification(T notification) { _notifications.Add(notification); } public void AddNotification(Type property, string message) { var notification = GetNotificationInstance(property?.Name, message); _notifications.Add(notification); } public void AddNotifications(IReadOnlyCollection notifications) { _notifications.AddRange(notifications); } public void AddNotifications(IList notifications) { _notifications.AddRange(notifications); } public void AddNotifications(ICollection notifications) { _notifications.AddRange(notifications); } public void AddNotifications(Notifiable item) { AddNotifications(item.Notifications); } public void AddNotifications(params Notifiable[] items) { foreach (var item in items) AddNotifications(item); } public void Clear() { _notifications.Clear(); } public bool IsValid => _notifications.Any() == false; } } ================================================ FILE: Flunt/Notifications/Notification.cs ================================================ namespace Flunt.Notifications { public class Notification { public Notification() { } public Notification(string key, string message) { Key = key; Message = message; } public string Key { get; set; } public string Message { get; set; } } } ================================================ FILE: Flunt/Validations/BoolValidationContract.cs ================================================ using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { #region IsFalse /// /// Requires that a bool is false /// /// bool /// Key or Property Name /// public Contract IsFalse(bool val, string property) => IsFalse(val, property, FluntErrorMessages.IsFalseErrorMessage(property)); /// /// Requires that a bool is false /// /// bool /// Key or Property Name /// Custom error message /// public Contract IsFalse(bool val, string property, string message) { if (val == true) AddNotification(property, message); return this; } #endregion #region IsTrue /// /// Requires that a bool is true /// /// bool /// Key or Property Name /// public Contract IsTrue(bool val, string property) => IsTrue(val, property, FluntErrorMessages.IsTrueErrorMessage(property)); /// /// Requires that a bool is true /// /// bool /// Key or Property Name /// Custom error message /// public Contract IsTrue(bool val, string property, string message) { if (val == false) AddNotification(property, message); return this; } #endregion #region IsNull /// /// Requires that a bool is null /// /// bool /// Key or Property Name /// public Contract IsNull(bool? val, string property) => IsNull(val, property, FluntErrorMessages.IsNullErrorMessage(property)); /// /// Requires that a bool is null /// /// bool /// Key or Property Name /// Custom error message /// public Contract IsNull(bool? val, string property, string message) { if (val != null) AddNotification(property, message); return this; } #endregion #region IsNotNull /// /// Requires that a bool is not null /// /// bool /// Key or Property Name /// public Contract IsNotNull(bool? val, string property) => IsNotNull(val, property, FluntErrorMessages.IsNotNullErrorMessage(property)); /// /// Requires that a bool is not null /// /// bool /// Key or Property Name /// Custom error message /// public Contract IsNotNull(bool? val, string property, string message) { if (val == null) AddNotification(property, message); return this; } #endregion } } ================================================ FILE: Flunt/Validations/Contract.cs ================================================ using Flunt.Notifications; using System; namespace Flunt.Validations { public partial class Contract : Notifiable { public Contract Requires() { return this; } public Contract Join(params Notifiable[] items) { if (items == null) return this; foreach (var notifiable in items) { if (notifiable.IsValid == false) AddNotifications(notifiable.Notifications); } return this; } } } ================================================ FILE: Flunt/Validations/CreditCardValidation.cs ================================================ using System.Linq; using System.Text.RegularExpressions; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { /// /// Requires a string is a Credit Card number /// /// /// /// public Contract IsCreditCard(string val, string key) => IsCreditCard(val, key, FluntErrorMessages.IsCreditCardErrorMessage(key)); /// /// Requires a string is a Credit Card number /// /// /// /// /// public Contract IsCreditCard(string val, string key, string message) { val = Regex.Replace(val, FluntRegexPatterns.OnlyNumbersPattern, ""); if (string.IsNullOrWhiteSpace(val)) { AddNotification(key, message); return this; } var even = false; var checksum = 0; foreach (var digit in val.ToCharArray().Reverse()) { if (!char.IsDigit(digit)) { AddNotification(val, message); return this; } var value = (digit - '0') * (even ? 2 : 1); even = !even; while (value > 0) { checksum += value % 10; value /= 10; } } if (checksum % 10 != 0) AddNotification(key, message); return this; } } } ================================================ FILE: Flunt/Validations/DateTimeValidationContract.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { #region IsGreaterThan /// /// Requires a date is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(DateTime val, DateTime comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is greater than /// /// val /// comparer /// Key or Property Name /// Customer error message /// public Contract IsGreaterThan(DateTime val, DateTime comparer, string key, string message) { if (val <= comparer) AddNotification(key, message); return this; } #endregion #region IsGreaterOrEqualsThan /// /// Requires a date is greater or equals than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterOrEqualsThan(DateTime val, DateTime comparer, string key) => IsGreaterOrEqualsThan(val, comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is greater or equals than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterOrEqualsThan(DateTime val, DateTime comparer, string key, string message) { if (val < comparer) AddNotification(key, message); return this; } #endregion #region IsLowerThan /// /// Requires a date is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(DateTime val, DateTime comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is lower than /// /// val /// comparer /// Key or Property Name /// Customer error message /// public Contract IsLowerThan(DateTime val, DateTime comparer, string key, string message) { if (val >= comparer) AddNotification(key, message); return this; } #endregion #region IsLowerOrEqualsThan /// /// Requires a date is lower or equals than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerOrEqualsThan(DateTime val, DateTime comparer, string key) => IsLowerOrEqualsThan(val, comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is lower or equals than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerOrEqualsThan(DateTime val, DateTime comparer, string key, string message) { if (val > comparer) AddNotification(key, message); return this; } #endregion #region IsNull /// /// Requires a date is null /// /// date /// Key or Property Name /// public Contract IsNull(DateTime? val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires a date is null /// /// date /// Key or Property Name /// Custom error message /// public Contract IsNull(DateTime? val, string key, string message) { if (val != null) AddNotification(key, message); return this; } #endregion #region IsNotNull /// /// Requires a date is not null /// /// date /// Key or Property Name /// public Contract IsNotNull(DateTime? val, string key) => IsNotNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires a date is not null /// /// date /// Key or Property Name /// Custom error message /// public Contract IsNotNull(DateTime? val, string key, string message) { if (val == null) AddNotification(key, message); return this; } #endregion #region IsBetween /// /// Requires a date is between /// /// date /// start date /// end date /// Key or Property Name /// public Contract IsBetween(DateTime val, DateTime start, DateTime end, string key) => IsBetween(val, start, end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is between /// /// date /// start date /// end date /// Key or Property Name /// Customer error message /// public Contract IsBetween(DateTime val, DateTime start, DateTime end, string key, string message) { if ((val >= start && val <= end) == false) AddNotification(key, message); return this; } #endregion #region IsNotBetween /// /// Requires a date is not between /// /// date /// start date /// end date /// Key or Property Name /// public Contract IsNotBetween(DateTime val, DateTime start, DateTime end, string key) => IsNotBetween(val, start, end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is not between /// /// date /// start date /// end date /// Key or Property Name /// Customer error message /// public Contract IsNotBetween(DateTime val, DateTime start, DateTime end, string key, string message) { if ((val >= start && val <= end) == true) AddNotification(key, message); return this; } #endregion #region IsMinValue /// /// Requires a date is min value /// /// date /// Key or Property Name /// public Contract IsMinValue(DateTime val, string key) => IsMinValue(val, key, FluntErrorMessages.IsMinValueErrorMessage(key, DateTime.MinValue.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is min value /// /// date /// Key or Property Name /// Custom error message /// public Contract IsMinValue(DateTime val, string key, string message) { if (val != DateTime.MinValue) AddNotification(key, message); return this; } #endregion #region IsNotMinValue /// /// Requires a date is not min value /// /// date /// Key or Property Name /// public Contract IsNotMinValue(DateTime val, string key) => IsNotMinValue(val, key, FluntErrorMessages.IsNotMinValueErrorMessage(key, DateTime.MinValue.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is not min value /// /// date /// Key or Property Name /// Custom error message /// public Contract IsNotMinValue(DateTime val, string key, string message) { if (val == DateTime.MinValue) AddNotification(key, message); return this; } #endregion #region IsMaxValue /// /// Requires a date is max value /// /// date /// Key or Property Name /// public Contract IsMaxValue(DateTime val, string key) => IsMaxValue(val, key, FluntErrorMessages.IsMaxValueErrorMessage(key, DateTime.MaxValue.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is max value /// /// date /// Key or Property Name /// Custom error message /// public Contract IsMaxValue(DateTime val, string key, string message) { if (val != DateTime.MaxValue) AddNotification(key, message); return this; } #endregion #region IsNotMaxValue /// /// Requires a date is not max value /// /// date /// Key or Property Name /// public Contract IsNotMaxValue(DateTime val, string key) => IsNotMaxValue(val, key, FluntErrorMessages.IsNotMaxValueErrorMessage(key, DateTime.MaxValue.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a date is not max value /// /// date /// Key or Property Name /// Custom error message /// public Contract IsNotMaxValue(DateTime val, string key, string message) { if (val == DateTime.MaxValue) AddNotification(key, message); return this; } #endregion #region AreEquals /// /// Require dates are equals /// /// date /// date /// Key or Property Name /// public Contract AreEquals(DateTime val, DateTime comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(FluntFormats.DateTimeFormat), comparer.ToString(FluntFormats.DateTimeFormat))); /// /// Require dates are equals /// /// date /// date /// Key or Property Name /// Customer error message /// public Contract AreEquals(DateTime val, DateTime comparer, string key, string message) { if (val != comparer) AddNotification(key, message); return this; } #endregion #region AreNotEquals /// /// Requires two dates are not equals /// /// date /// date /// Key or Property Name /// public Contract AreNotEquals(DateTime val, DateTime comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(FluntFormats.DateTimeFormat), comparer.ToString(FluntFormats.DateTimeFormat))); /// /// Requires two dates are not equals /// /// date /// date /// Key or Property Name /// Custom error message /// public Contract AreNotEquals(DateTime val, DateTime comparer, string key, string message) { if (val == comparer) AddNotification(key, message); return this; } #endregion #region Contains /// /// Requires a list contains a date /// /// date /// list of dates /// Key or Property Name /// public Contract Contains(DateTime val, IEnumerable list, string key) => Contains(val, list, key, FluntErrorMessages.ContainsErrorMessage(key, val.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a list contains a date /// /// date /// list of dates /// Key or Property Name /// Custom error message /// public Contract Contains(DateTime val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == false) AddNotification(key, message); return this; } #endregion #region NotContains /// /// Requires a list not contains a date /// /// date /// list of dates /// Key or Property Name /// public Contract NotContains(DateTime val, IEnumerable list, string key) => NotContains(val, list, key, FluntErrorMessages.NotContainsErrorMessage(key, val.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a list not contains a date /// /// date /// list of dates /// Key or Property Name /// Custom error message /// public Contract NotContains(DateTime val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == true) AddNotification(key, message); return this; } #endregion } } ================================================ FILE: Flunt/Validations/DecimalValidationContract.cs ================================================ using System.Collections.Generic; using System.Linq; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { #region IsGreaterThan /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(decimal val, decimal comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(decimal val, decimal comparer, string key, string message) { if (val <= comparer) AddNotification(key, message); return this; } /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(decimal val, double comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(decimal val, double comparer, string key, string message) => IsGreaterThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(decimal val, float comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(decimal val, float comparer, string key, string message) => IsGreaterThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(decimal val, int comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(decimal val, int comparer, string key, string message) => IsGreaterThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(decimal val, long comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(decimal val, long comparer, string key, string message) => IsGreaterThan(val, (decimal)comparer, key, message); #endregion #region IsGreaterOrEqualsThan /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(decimal val, decimal comparer, string key) => IsGreaterOrEqualsThan(val, comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(decimal val, decimal comparer, string key, string message) { if (val < comparer) AddNotification(key, message); return this; } /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(decimal val, double comparer, string key) => IsGreaterOrEqualsThan(val, (decimal)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(decimal val, double comparer, string key, string message) => IsGreaterOrEqualsThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(decimal val, float comparer, string key) => IsGreaterOrEqualsThan(val, (decimal)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(decimal val, float comparer, string key, string message) => IsGreaterOrEqualsThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(decimal val, int comparer, string key) => IsGreaterOrEqualsThan(val, (decimal)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(decimal val, int comparer, string key, string message) => IsGreaterOrEqualsThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(decimal val, long comparer, string key) => IsGreaterOrEqualsThan(val, (decimal)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(decimal val, long comparer, string key, string message) => IsGreaterOrEqualsThan(val, (decimal)comparer, key, message); #endregion #region IsLowerThan /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(decimal val, decimal comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(decimal val, decimal comparer, string key, string message) { if (val >= comparer) AddNotification(key, message); return this; } /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(decimal val, double comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(decimal val, double comparer, string key, string message) => IsLowerThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(decimal val, float comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(decimal val, float comparer, string key, string message) => IsLowerThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(decimal val, int comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(decimal val, int comparer, string key, string message) => IsLowerThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(decimal val, long comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(decimal val, long comparer, string key, string message) => IsLowerThan(val, (decimal)comparer, key, message); #endregion #region IsLowerOrEqualsThan /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(decimal val, decimal comparer, string key) => IsLowerOrEqualsThan(val, comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(decimal val, decimal comparer, string key, string message) { if (val > comparer) AddNotification(key, message); return this; } /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(decimal val, double comparer, string key) => IsLowerOrEqualsThan(val, (decimal)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(decimal val, double comparer, string key, string message) => IsLowerOrEqualsThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(decimal val, float comparer, string key) => IsLowerOrEqualsThan(val, (decimal)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(decimal val, float comparer, string key, string message) => IsLowerOrEqualsThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(decimal val, int comparer, string key) => IsLowerOrEqualsThan(val, (decimal)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(decimal val, int comparer, string key, string message) => IsLowerOrEqualsThan(val, (decimal)comparer, key, message); /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(decimal val, long comparer, string key) => IsLowerOrEqualsThan(val, (decimal)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a decimal is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(decimal val, long comparer, string key, string message) => IsLowerOrEqualsThan(val, (decimal)comparer, key, message); #endregion #region IsMinValue /// /// Requires a decimal has its min value /// /// /// /// public Contract IsMinValue(decimal val, string key) => IsMinValue(val, key, FluntErrorMessages.IsMinValueErrorMessage(key, decimal.MinValue.ToString())); /// /// Requires a decimal has its min value /// /// /// /// /// public Contract IsMinValue(decimal val, string key, string message) { if (val != decimal.MinValue) AddNotification(key, message); return this; } #endregion #region IsNotMinValue /// /// Requires a decimal has not its min value /// /// /// /// public Contract IsNotMinValue(decimal val, string key) => IsNotMinValue(val, key, FluntErrorMessages.IsNotMinValueErrorMessage(key, decimal.MinValue.ToString())); /// /// Requires a decimal has not its min value /// /// /// /// /// public Contract IsNotMinValue(decimal val, string key, string message) { if (val == decimal.MinValue) AddNotification(key, message); return this; } #endregion #region IsMaxValue /// /// Requires a decimal has its max value /// /// /// /// public Contract IsMaxValue(decimal val, string key) => IsMaxValue(val, key, FluntErrorMessages.IsMaxValueErrorMessage(key, decimal.MaxValue.ToString())); /// /// Requires a decimal has its max value /// /// /// /// /// public Contract IsMaxValue(decimal val, string key, string message) { if (val != decimal.MaxValue) AddNotification(key, message); return this; } #endregion #region IsNotMaxValue /// /// Requires a decimal has not its max value /// /// /// /// public Contract IsNotMaxValue(decimal val, string key) => IsNotMaxValue(val, key, FluntErrorMessages.IsNotMaxValueErrorMessage(key, decimal.MaxValue.ToString())); /// /// Requires a decimal has not its min value /// /// /// /// /// public Contract IsNotMaxValue(decimal val, string key, string message) { if (val == decimal.MaxValue) AddNotification(key, message); return this; } #endregion #region AreEquals /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(decimal val, decimal comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(decimal val, decimal comparer, string key, string message) { if (val != comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(decimal val, int comparer, string key) => AreEquals(val, (decimal)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(decimal val, int comparer, string key, string message) => AreEquals(val, (decimal)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(decimal val, float comparer, string key) => AreEquals(val, (decimal)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(decimal val, float comparer, string key, string message) => AreEquals(val, (decimal)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(decimal val, double comparer, string key) => AreEquals(val, (decimal)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(decimal val, double comparer, string key, string message) => AreEquals(val, (decimal)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(decimal val, long comparer, string key) => AreEquals(val, (decimal)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(decimal val, long comparer, string key, string message) => AreEquals(val, (decimal)comparer, key, message); #endregion #region AreNotEquals /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(decimal val, decimal comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(decimal val, decimal comparer, string key, string message) { if (val == comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(decimal val, int comparer, string key) => AreNotEquals(val, (decimal)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(decimal val, int comparer, string key, string message) => AreNotEquals(val, (decimal)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(decimal val, float comparer, string key) => AreNotEquals(val, (decimal)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(decimal val, float comparer, string key, string message) => AreNotEquals(val, (decimal)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(decimal val, double comparer, string key) => AreNotEquals(val, (decimal)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(decimal val, double comparer, string key, string message) => AreNotEquals(val, (decimal)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(decimal val, long comparer, string key) => AreNotEquals(val, (decimal)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(decimal val, long comparer, string key, string message) => AreNotEquals(val, (decimal)comparer, key, message); #endregion #region IsNull /// /// Requires a decimal is null /// /// /// /// public Contract IsNull(decimal? val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires a decimal is null /// /// /// /// /// public Contract IsNull(decimal? val, string key, string message) { if (val != null) AddNotification(key, message); return this; } #endregion #region IsNotNull /// /// Requires a decimal is not null /// /// /// /// public Contract IsNotNull(decimal? val, string key) => IsNotNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires a decimal is not null /// /// /// /// /// public Contract IsNotNull(decimal? val, string key, string message) { if (val == null) AddNotification(key, message); return this; } #endregion #region IsBetween /// /// Requires a decimal is between /// /// /// /// /// /// public Contract IsBetween(decimal val, decimal start, decimal end, string key) => IsBetween(val, start, end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is between /// /// /// /// /// /// /// public Contract IsBetween(decimal val, decimal start, decimal end, string key, string message) { if ((val >= start && val <= end) == false) AddNotification(key, message); return this; } /// /// Requires a decimal is between /// /// /// /// /// /// public Contract IsBetween(decimal val, int start, int end, string key) => IsBetween(val, (decimal)start, (decimal)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is between /// /// /// /// /// /// /// public Contract IsBetween(decimal val, int start, int end, string key, string message) => IsBetween(val, (decimal)start, (decimal)end, key, message); /// /// Requires a decimal is between /// /// /// /// /// /// public Contract IsBetween(decimal val, float start, float end, string key) => IsBetween(val, (decimal)start, (decimal)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is between /// /// /// /// /// /// /// public Contract IsBetween(decimal val, float start, float end, string key, string message) => IsBetween(val, (decimal)start, (decimal)end, key, message); /// /// Requires a decimal is between /// /// /// /// /// /// public Contract IsBetween(decimal val, double start, double end, string key) => IsBetween(val, (decimal)start, (decimal)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is between /// /// /// /// /// /// /// public Contract IsBetween(decimal val, double start, double end, string key, string message) => IsBetween(val, (decimal)start, (decimal)end, key, message); /// /// Requires a decimal is between /// /// /// /// /// /// public Contract IsBetween(decimal val, long start, long end, string key) => IsBetween(val, (decimal)start, (decimal)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is between /// /// /// /// /// /// /// public Contract IsBetween(decimal val, long start, long end, string key, string message) => IsBetween(val, (decimal)start, (decimal)end, key, message); #endregion #region IsNotBetween /// /// Requires a decimal is not between /// /// /// /// /// /// public Contract IsNotBetween(decimal val, decimal start, decimal end, string key) => IsNotBetween(val, start, end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is not between /// /// /// /// /// /// /// public Contract IsNotBetween(decimal val, decimal start, decimal end, string key, string message) { if ((val >= start && val <= end) == true) AddNotification(key, message); return this; } /// /// Requires a decimal is not between /// /// /// /// /// /// public Contract IsNotBetween(decimal val, int start, int end, string key) => IsNotBetween(val, (decimal)start, (decimal)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is not between /// /// /// /// /// /// /// public Contract IsNotBetween(decimal val, int start, int end, string key, string message) => IsNotBetween(val, (decimal)start, (decimal)end, key, message); /// /// Requires a decimal is not between /// /// /// /// /// /// public Contract IsNotBetween(decimal val, float start, float end, string key) => IsNotBetween(val, (decimal)start, (decimal)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is not between /// /// /// /// /// /// /// public Contract IsNotBetween(decimal val, float start, float end, string key, string message) => IsNotBetween(val, (decimal)start, (decimal)end, key, message); /// /// Requires a decimal is not between /// /// /// /// /// /// public Contract IsNotBetween(decimal val, double start, double end, string key) => IsNotBetween(val, (decimal)start, (decimal)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is not between /// /// /// /// /// /// /// public Contract IsNotBetween(decimal val, double start, double end, string key, string message) => IsNotBetween(val, (decimal)start, (decimal)end, key, message); /// /// Requires a decimal is not between /// /// /// /// /// /// public Contract IsNotBetween(decimal val, long start, long end, string key) => IsNotBetween(val, (decimal)start, (decimal)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a decimal is not between /// /// /// /// /// /// /// public Contract IsNotBetween(decimal val, long start, long end, string key, string message) => IsNotBetween(val, (decimal)start, (decimal)end, key, message); #endregion #region Contains /// /// Requires a list contains a decimal /// /// /// /// /// public Contract Contains(decimal val, IEnumerable list, string key) => Contains(val, list, key, FluntErrorMessages.ContainsErrorMessage(key, val.ToString())); /// /// Requires a list contains a decimal /// /// /// /// /// /// public Contract Contains(decimal val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == false) AddNotification(key, message); return this; } #endregion #region NotContains /// /// Requires a list does not contains a decimal /// /// /// /// /// public Contract NotContains(decimal val, IEnumerable list, string key) => NotContains(val, list, key, FluntErrorMessages.NotContainsErrorMessage(key, val.ToString())); /// /// Requires a list does not contains a decimal /// /// /// /// /// /// public Contract NotContains(decimal val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == true) AddNotification(key, message); return this; } #endregion } } ================================================ FILE: Flunt/Validations/DocumentValitionContract.cs ================================================ using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { /// /// Requires a string is a passport number /// /// /// /// public Contract IsPassport(string val, string key) => IsPassport(val, key, FluntErrorMessages.IsPassportErrorMessage(key)); /// /// Requires a string is a passport number /// /// /// /// /// public Contract IsPassport(string val, string key, string message) => Matches(val, FluntRegexPatterns.PassportRegexPattern, key, message); } } ================================================ FILE: Flunt/Validations/DoubleValidationContract.cs ================================================ using System.Collections.Generic; using System.Linq; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { #region IsGreaterThan /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(double val, double comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(double val, double comparer, string key, string message) { if (val <= (double)comparer) AddNotification(key, message); return this; } /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(double val, decimal comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(double val, decimal comparer, string key, string message) => IsGreaterThan(val, (double)comparer, key, message); /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(double val, float comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(double val, float comparer, string key, string message) => IsGreaterThan(val, (double)comparer, key, message); /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(double val, int comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(double val, int comparer, string key, string message) => IsGreaterThan(val, (double)comparer, key, message); /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(double val, long comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(double val, long comparer, string key, string message) => IsGreaterThan(val, (double)comparer, key, message); #endregion #region IsGreaterOrEqualsThan /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(double val, double comparer, string key) => IsGreaterOrEqualsThan(val, comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(double val, double comparer, string key, string message) { if (val < comparer) AddNotification(key, message); return this; } /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(double val, decimal comparer, string key) => IsGreaterOrEqualsThan(val, (double)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(double val, decimal comparer, string key, string message) => IsGreaterOrEqualsThan(val, (double)comparer, key, message); /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(double val, float comparer, string key) => IsGreaterOrEqualsThan(val, (double)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(double val, float comparer, string key, string message) => IsGreaterOrEqualsThan(val, (double)comparer, key, message); /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(double val, int comparer, string key) => IsGreaterOrEqualsThan(val, (double)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(double val, int comparer, string key, string message) => IsGreaterOrEqualsThan(val, (double)comparer, key, message); /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(double val, long comparer, string key) => IsGreaterOrEqualsThan(val, (double)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(double val, long comparer, string key, string message) => IsGreaterOrEqualsThan(val, (double)comparer, key, message); #endregion #region IsLowerThan /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(double val, double comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(double val, double comparer, string key, string message) { if (val >= comparer) AddNotification(key, message); return this; } /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(double val, decimal comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(double val, decimal comparer, string key, string message) => IsLowerThan(val, (double)comparer, key, message); /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(double val, float comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(double val, float comparer, string key, string message) => IsLowerThan(val, (double)comparer, key, message); /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(double val, int comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(double val, int comparer, string key, string message) => IsLowerThan(val, (double)comparer, key, message); /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(double val, long comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(double val, long comparer, string key, string message) => IsLowerThan(val, (double)comparer, key, message); #endregion #region IsLowerOrEqualsThan /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(double val, double comparer, string key) => IsLowerOrEqualsThan(val, comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(double val, double comparer, string key, string message) { if (val > comparer) AddNotification(key, message); return this; } /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(double val, decimal comparer, string key) => IsLowerOrEqualsThan(val, (double)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(double val, decimal comparer, string key, string message) => IsLowerOrEqualsThan(val, (double)comparer, key, message); /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(double val, float comparer, string key) => IsLowerOrEqualsThan(val, (double)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(double val, float comparer, string key, string message) => IsLowerOrEqualsThan(val, (double)comparer, key, message); /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(double val, int comparer, string key) => IsLowerOrEqualsThan(val, (double)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(double val, int comparer, string key, string message) => IsLowerOrEqualsThan(val, (double)comparer, key, message); /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(double val, long comparer, string key) => IsLowerOrEqualsThan(val, (double)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a double is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(double val, long comparer, string key, string message) => IsLowerOrEqualsThan(val, (double)comparer, key, message); #endregion #region IsMinValue /// /// Requires a double has its min value /// /// /// /// public Contract IsMinValue(double val, string key) => IsMinValue(val, key, FluntErrorMessages.IsMinValueErrorMessage(key, double.MinValue.ToString())); /// /// Requires a double has its min value /// /// /// /// /// public Contract IsMinValue(double val, string key, string message) { if (val != double.MinValue) AddNotification(key, message); return this; } #endregion #region IsNotMinValue /// /// Requires a double has not its min value /// /// /// /// public Contract IsNotMinValue(double val, string key) => IsNotMinValue(val, key, FluntErrorMessages.IsNotMinValueErrorMessage(key, double.MinValue.ToString())); /// /// Requires a double has not its min value /// /// /// /// /// public Contract IsNotMinValue(double val, string key, string message) { if (val == double.MinValue) AddNotification(key, message); return this; } #endregion #region IsMaxValue /// /// Requires a double has its max value /// /// /// /// public Contract IsMaxValue(double val, string key) => IsMaxValue(val, key, FluntErrorMessages.IsMaxValueErrorMessage(key, double.MaxValue.ToString())); /// /// Requires a double has its max value /// /// /// /// /// public Contract IsMaxValue(double val, string key, string message) { if (val != double.MaxValue) AddNotification(key, message); return this; } #endregion #region IsNotMaxValue /// /// Requires a double has not its max value /// /// /// /// public Contract IsNotMaxValue(double val, string key) => IsNotMaxValue(val, key, FluntErrorMessages.IsNotMaxValueErrorMessage(key, double.MaxValue.ToString())); /// /// Requires a double has not its min value /// /// /// /// /// public Contract IsNotMaxValue(double val, string key, string message) { if (val == double.MaxValue) AddNotification(key, message); return this; } #endregion #region AreEquals /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(double val, double comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(double val, double comparer, string key, string message) { if (val != comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(double val, int comparer, string key) => AreEquals(val, (double)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(double val, int comparer, string key, string message) => AreEquals(val, (double)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(double val, float comparer, string key) => AreEquals(val, (double)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(double val, float comparer, string key, string message) => AreEquals(val, (double)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(double val, decimal comparer, string key) => AreEquals(val, (double)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(double val, decimal comparer, string key, string message) => AreEquals(val, (double)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(double val, long comparer, string key) => AreEquals(val, (double)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(double val, long comparer, string key, string message) => AreEquals(val, (double)comparer, key, message); #endregion #region AreNotEquals /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(double val, double comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(double val, double comparer, string key, string message) { if (val == comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(double val, int comparer, string key) => AreNotEquals(val, (double)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(double val, int comparer, string key, string message) => AreNotEquals(val, (double)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(double val, float comparer, string key) => AreNotEquals(val, (double)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(double val, float comparer, string key, string message) => AreNotEquals(val, (double)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(double val, decimal comparer, string key) => AreNotEquals(val, (double)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(double val, decimal comparer, string key, string message) => AreNotEquals(val, (double)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(double val, long comparer, string key) => AreNotEquals(val, (double)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(double val, long comparer, string key, string message) => AreNotEquals(val, (double)comparer, key, message); #endregion #region IsNull /// /// Requires a double is null /// /// /// /// public Contract IsNull(double? val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires a double is null /// /// /// /// /// public Contract IsNull(double? val, string key, string message) { if (val != null) AddNotification(key, message); return this; } #endregion #region IsNotNull /// /// Requires a double is not null /// /// /// /// public Contract IsNotNull(double? val, string key) => IsNotNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires a double is not null /// /// /// /// /// public Contract IsNotNull(double? val, string key, string message) { if (val == null) AddNotification(key, message); return this; } #endregion #region IsBetween /// /// Requires a double is between /// /// /// /// /// /// public Contract IsBetween(double val, double start, double end, string key) => IsBetween(val, start, end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is between /// /// /// /// /// /// /// public Contract IsBetween(double val, double start, double end, string key, string message) { if ((val >= start && val <= end) == false) AddNotification(key, message); return this; } /// /// Requires a double is between /// /// /// /// /// /// public Contract IsBetween(double val, int start, int end, string key) => IsBetween(val, (double)start, (double)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is between /// /// /// /// /// /// /// public Contract IsBetween(double val, int start, int end, string key, string message) => IsBetween(val, (double)start, (double)end, key, message); /// /// Requires a double is between /// /// /// /// /// /// public Contract IsBetween(double val, float start, float end, string key) => IsBetween(val, (double)start, (double)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is between /// /// /// /// /// /// /// public Contract IsBetween(double val, float start, float end, string key, string message) => IsBetween(val, (double)start, (double)end, key, message); /// /// Requires a double is between /// /// /// /// /// /// public Contract IsBetween(double val, decimal start, decimal end, string key) => IsBetween(val, (double)start, (double)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is between /// /// /// /// /// /// /// public Contract IsBetween(double val, decimal start, decimal end, string key, string message) => IsBetween(val, (double)start, (double)end, key, message); /// /// Requires a double is between /// /// /// /// /// /// public Contract IsBetween(double val, long start, long end, string key) => IsBetween(val, (double)start, (double)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is between /// /// /// /// /// /// /// public Contract IsBetween(double val, long start, long end, string key, string message) => IsBetween(val, (double)start, (double)end, key, message); #endregion #region IsNotBetween /// /// Requires a double is not between /// /// /// /// /// /// public Contract IsNotBetween(double val, double start, double end, string key) => IsNotBetween(val, start, end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is not between /// /// /// /// /// /// /// public Contract IsNotBetween(double val, double start, double end, string key, string message) { if ((val >= start && val <= end) == true) AddNotification(key, message); return this; } /// /// Requires a double is not between /// /// /// /// /// /// public Contract IsNotBetween(double val, int start, int end, string key) => IsNotBetween(val, (double)start, (double)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is not between /// /// /// /// /// /// /// public Contract IsNotBetween(double val, int start, int end, string key, string message) => IsNotBetween(val, (double)start, (double)end, key, message); /// /// Requires a double is not between /// /// /// /// /// /// public Contract IsNotBetween(double val, float start, float end, string key) => IsNotBetween(val, (double)start, (double)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is not between /// /// /// /// /// /// /// public Contract IsNotBetween(double val, float start, float end, string key, string message) => IsNotBetween(val, (double)start, (double)end, key, message); /// /// Requires a double is not between /// /// /// /// /// /// public Contract IsNotBetween(double val, decimal start, decimal end, string key) => IsNotBetween(val, (double)start, (double)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is not between /// /// /// /// /// /// /// public Contract IsNotBetween(double val, decimal start, decimal end, string key, string message) => IsNotBetween(val, (double)start, (double)end, key, message); /// /// Requires a double is not between /// /// /// /// /// /// public Contract IsNotBetween(double val, long start, long end, string key) => IsNotBetween(val, (double)start, (double)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a double is not between /// /// /// /// /// /// /// public Contract IsNotBetween(double val, long start, long end, string key, string message) => IsNotBetween(val, (double)start, (double)end, key, message); #endregion #region Contains /// /// Requires a list contains a double /// /// /// /// /// public Contract Contains(double val, IEnumerable list, string key) => Contains(val, list, key, FluntErrorMessages.ContainsErrorMessage(key, val.ToString())); /// /// Requires a list contains a double /// /// /// /// /// /// public Contract Contains(double val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == false) AddNotification(key, message); return this; } #endregion #region NotContains /// /// Requires a list does not contains a double /// /// /// /// /// public Contract NotContains(double val, IEnumerable list, string key) => NotContains(val, list, key, FluntErrorMessages.NotContainsErrorMessage(key, val.ToString())); /// /// Requires a list does not contains a double /// /// /// /// /// /// public Contract NotContains(double val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == true) AddNotification(key, message); return this; } #endregion } } ================================================ FILE: Flunt/Validations/EmailValidationContract.cs ================================================ using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { /// /// Requires a string is an email /// /// /// /// public Contract IsEmail(string val, string key) => IsEmail(val, key, FluntErrorMessages.IsEmailErrorMessage(key)); /// /// Requires a string is an email /// /// /// /// /// public Contract IsEmail(string val, string key, string message) { return Matches(val, FluntRegexPatterns.EmailRegexPattern, key, message); } /// /// Requires a string is an email or empty /// /// /// /// public Contract IsEmailOrEmpty(string val, string key) => IsEmailOrEmpty(val, key, FluntErrorMessages.IsEmailOrEmptyErrorMessage(key)); /// /// Requires a string is an email or empty /// /// /// /// /// public Contract IsEmailOrEmpty(string val, string key, string message) { return string.IsNullOrEmpty(val) ? this : IsEmail(val, key, message); } /// /// Requires a string is not an email /// /// /// /// public Contract IsNotEmail(string val, string key) => IsNotEmail(val, key, FluntErrorMessages.IsNotEmailErrorMessage(key)); /// /// Requires a string is not an email /// /// /// /// /// public Contract IsNotEmail(string val, string key, string message) { return NotMatches(val, FluntRegexPatterns.EmailRegexPattern, key, message); } } } ================================================ FILE: Flunt/Validations/FloatValidationContract.cs ================================================ using System.Collections.Generic; using System.Linq; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { #region IsGreaterThan /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(float val, float comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(float val, float comparer, string key, string message) { if (val <= (float)comparer) AddNotification(key, message); return this; } /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(float val, decimal comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(float val, decimal comparer, string key, string message) => IsGreaterThan(val, (float)comparer, key, message); /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(float val, double comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(float val, double comparer, string key, string message) => IsGreaterThan(val, (float)comparer, key, message); /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(float val, int comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(float val, int comparer, string key, string message) => IsGreaterThan(val, (float)comparer, key, message); /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(float val, long comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(float val, long comparer, string key, string message) => IsGreaterThan(val, (float)comparer, key, message); #endregion #region IsGreaterOrEqualsThan /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(float val, float comparer, string key) => IsGreaterOrEqualsThan(val, comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(float val, float comparer, string key, string message) { if (val < comparer) AddNotification(key, message); return this; } /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(float val, decimal comparer, string key) => IsGreaterOrEqualsThan(val, (float)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(float val, decimal comparer, string key, string message) => IsGreaterOrEqualsThan(val, (float)comparer, key, message); /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(float val, double comparer, string key) => IsGreaterOrEqualsThan(val, (float)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(float val, double comparer, string key, string message) => IsGreaterOrEqualsThan(val, (float)comparer, key, message); /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(float val, int comparer, string key) => IsGreaterOrEqualsThan(val, (float)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(float val, int comparer, string key, string message) => IsGreaterOrEqualsThan(val, (float)comparer, key, message); /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(float val, long comparer, string key) => IsGreaterOrEqualsThan(val, (float)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(float val, long comparer, string key, string message) => IsGreaterOrEqualsThan(val, (float)comparer, key, message); #endregion #region IsLowerThan /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(float val, float comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(float val, float comparer, string key, string message) { if (val >= comparer) AddNotification(key, message); return this; } /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(float val, decimal comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(float val, decimal comparer, string key, string message) => IsLowerThan(val, (float)comparer, key, message); /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(float val, double comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(float val, double comparer, string key, string message) => IsLowerThan(val, (float)comparer, key, message); /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(float val, int comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(float val, int comparer, string key, string message) => IsLowerThan(val, (float)comparer, key, message); /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(float val, long comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(float val, long comparer, string key, string message) => IsLowerThan(val, (float)comparer, key, message); #endregion #region IsLowerOrEqualsThan /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(float val, float comparer, string key) => IsLowerOrEqualsThan(val, comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(float val, float comparer, string key, string message) { if (val > comparer) AddNotification(key, message); return this; } /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(float val, decimal comparer, string key) => IsLowerOrEqualsThan(val, (float)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(float val, decimal comparer, string key, string message) => IsLowerOrEqualsThan(val, (float)comparer, key, message); /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(float val, double comparer, string key) => IsLowerOrEqualsThan(val, (float)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(float val, double comparer, string key, string message) => IsLowerOrEqualsThan(val, (float)comparer, key, message); /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(float val, int comparer, string key) => IsLowerOrEqualsThan(val, (float)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(float val, int comparer, string key, string message) => IsLowerOrEqualsThan(val, (float)comparer, key, message); /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(float val, long comparer, string key) => IsLowerOrEqualsThan(val, (float)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a float is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(float val, long comparer, string key, string message) => IsLowerOrEqualsThan(val, (float)comparer, key, message); #endregion #region IsMinValue /// /// Requires a float has its min value /// /// /// /// public Contract IsMinValue(float val, string key) => IsMinValue(val, key, FluntErrorMessages.IsMinValueErrorMessage(key, decimal.MinValue.ToString())); /// /// Requires a float has its min value /// /// /// /// /// public Contract IsMinValue(float val, string key, string message) { if (val != float.MinValue) AddNotification(key, message); return this; } #endregion #region IsNotMinValue /// /// Requires a float has not its min value /// /// /// /// public Contract IsNotMinValue(float val, string key) => IsNotMinValue(val, key, FluntErrorMessages.IsNotMinValueErrorMessage(key, decimal.MinValue.ToString())); /// /// Requires a float has not its min value /// /// /// /// /// public Contract IsNotMinValue(float val, string key, string message) { if (val == float.MinValue) AddNotification(key, message); return this; } #endregion #region IsMaxValue /// /// Requires a float has its max value /// /// /// /// public Contract IsMaxValue(float val, string key) => IsMaxValue(val, key, FluntErrorMessages.IsMaxValueErrorMessage(key, decimal.MaxValue.ToString())); /// /// Requires a float has its max value /// /// /// /// /// public Contract IsMaxValue(float val, string key, string message) { if (val != float.MaxValue) AddNotification(key, message); return this; } #endregion #region IsNotMaxValue /// /// Requires a float has not its max value /// /// /// /// public Contract IsNotMaxValue(float val, string key) => IsNotMaxValue(val, key, FluntErrorMessages.IsNotMaxValueErrorMessage(key, decimal.MaxValue.ToString())); /// /// Requires a float has not its min value /// /// /// /// /// public Contract IsNotMaxValue(float val, string key, string message) { if (val == float.MaxValue) AddNotification(key, message); return this; } #endregion #region AreEquals /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(float val, float comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(float val, float comparer, string key, string message) { if (val != comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(float val, int comparer, string key) => AreEquals(val, (float)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(float val, int comparer, string key, string message) => AreEquals(val, (float)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(float val, double comparer, string key) => AreEquals(val, (float)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(float val, double comparer, string key, string message) => AreEquals(val, (float)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(float val, decimal comparer, string key) => AreEquals(val, (float)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(float val, decimal comparer, string key, string message) => AreEquals(val, (float)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(float val, long comparer, string key) => AreEquals(val, (float)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(float val, long comparer, string key, string message) => AreEquals(val, (float)comparer, key, message); #endregion #region AreNotEquals /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(float val, float comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(float val, float comparer, string key, string message) { if (val == comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(float val, int comparer, string key) => AreNotEquals(val, (float)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(float val, int comparer, string key, string message) => AreNotEquals(val, (float)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(float val, double comparer, string key) => AreNotEquals(val, (float)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(float val, double comparer, string key, string message) => AreNotEquals(val, (float)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(float val, decimal comparer, string key) => AreNotEquals(val, (float)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(float val, decimal comparer, string key, string message) => AreNotEquals(val, (float)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(float val, long comparer, string key) => AreNotEquals(val, (float)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(float val, long comparer, string key, string message) => AreNotEquals(val, (float)comparer, key, message); #endregion #region IsNull /// /// Requires a float is null /// /// /// /// public Contract IsNull(float? val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires a float is null /// /// /// /// /// public Contract IsNull(float? val, string key, string message) { if (val != null) AddNotification(key, message); return this; } #endregion #region IsNotNull /// /// Requires a float is not null /// /// /// /// public Contract IsNotNull(float? val, string key) => IsNotNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires a float is not null /// /// /// /// /// public Contract IsNotNull(float? val, string key, string message) { if (val == null) AddNotification(key, message); return this; } #endregion #region IsBetween /// /// Requires a float is between /// /// /// /// /// /// public Contract IsBetween(float val, float start, float end, string key) => IsBetween(val, start, end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is between /// /// /// /// /// /// /// public Contract IsBetween(float val, float start, float end, string key, string message) { if ((val >= start && val <= end) == false) AddNotification(key, message); return this; } /// /// Requires a float is between /// /// /// /// /// /// public Contract IsBetween(float val, int start, int end, string key) => IsBetween(val, (float)start, (float)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is between /// /// /// /// /// /// /// public Contract IsBetween(float val, int start, int end, string key, string message) => IsBetween(val, (float)start, (float)end, key, message); /// /// Requires a float is between /// /// /// /// /// /// public Contract IsBetween(float val, double start, double end, string key) => IsBetween(val, (float)start, (float)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is between /// /// /// /// /// /// /// public Contract IsBetween(float val, double start, double end, string key, string message) => IsBetween(val, (float)start, (float)end, key, message); /// /// Requires a float is between /// /// /// /// /// /// public Contract IsBetween(float val, decimal start, decimal end, string key) => IsBetween(val, (float)start, (float)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is between /// /// /// /// /// /// /// public Contract IsBetween(float val, decimal start, decimal end, string key, string message) => IsBetween(val, (float)start, (float)end, key, message); /// /// Requires a float is between /// /// /// /// /// /// public Contract IsBetween(float val, long start, long end, string key) => IsBetween(val, (float)start, (float)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is between /// /// /// /// /// /// /// public Contract IsBetween(float val, long start, long end, string key, string message) => IsBetween(val, (float)start, (float)end, key, message); #endregion #region IsNotBetween /// /// Requires a float is not between /// /// /// /// /// /// public Contract IsNotBetween(float val, float start, float end, string key) => IsNotBetween(val, start, end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is not between /// /// /// /// /// /// /// public Contract IsNotBetween(float val, float start, float end, string key, string message) { if ((val >= start && val <= end) == true) AddNotification(key, message); return this; } /// /// Requires a float is not between /// /// /// /// /// /// public Contract IsNotBetween(float val, int start, int end, string key) => IsNotBetween(val, (float)start, (float)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is not between /// /// /// /// /// /// /// public Contract IsNotBetween(float val, int start, int end, string key, string message) => IsNotBetween(val, (float)start, (float)end, key, message); /// /// Requires a float is not between /// /// /// /// /// /// public Contract IsNotBetween(float val, double start, double end, string key) => IsNotBetween(val, (float)start, (float)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is not between /// /// /// /// /// /// /// public Contract IsNotBetween(float val, double start, double end, string key, string message) => IsNotBetween(val, (float)start, (float)end, key, message); /// /// Requires a float is not between /// /// /// /// /// /// public Contract IsNotBetween(float val, decimal start, decimal end, string key) => IsNotBetween(val, (float)start, (float)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is not between /// /// /// /// /// /// /// public Contract IsNotBetween(float val, decimal start, decimal end, string key, string message) => IsNotBetween(val, (float)start, (float)end, key, message); /// /// Requires a float is not between /// /// /// /// /// /// public Contract IsNotBetween(float val, long start, long end, string key) => IsNotBetween(val, (float)start, (float)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a float is not between /// /// /// /// /// /// /// public Contract IsNotBetween(float val, long start, long end, string key, string message) => IsNotBetween(val, (float)start, (float)end, key, message); #endregion #region Contains /// /// Requires a list contains a float /// /// /// /// /// public Contract Contains(float val, IEnumerable list, string key) => Contains(val, list, key, FluntErrorMessages.ContainsErrorMessage(key, val.ToString())); /// /// Requires a list contains a float /// /// /// /// /// /// public Contract Contains(float val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == false) AddNotification(key, message); return this; } #endregion #region NotContains /// /// Requires a list does not contains a float /// /// /// /// /// public Contract NotContains(float val, IEnumerable list, string key) => NotContains(val, list, key, FluntErrorMessages.NotContainsErrorMessage(key, val.ToString())); /// /// Requires a list does not contains a float /// /// /// /// /// /// public Contract NotContains(float val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == true) AddNotification(key, message); return this; } #endregion } } ================================================ FILE: Flunt/Validations/GuidValidationContract.cs ================================================ using System; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { /// /// Requires two Guids are equals /// /// /// /// /// public Contract AreEquals(Guid val, Guid comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two Guids are equals /// /// /// /// /// /// public Contract AreEquals(Guid val, Guid comparer, string key, string message) { if (val != comparer) AddNotification(key, message); return this; } /// /// Requires two Guids are not equals /// /// /// /// /// public Contract AreNotEquals(Guid val, Guid comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two Guids are not equals /// /// /// /// /// /// public Contract AreNotEquals(Guid val, Guid comparer, string key, string message) { if (val == comparer) AddNotification(key, message); return this; } /// /// Requires a Guid is empty /// /// /// /// public Contract IsEmpty(Guid val, string key) => IsEmpty(val, key, FluntErrorMessages.IsEmptyErrorMessage(key)); /// /// Requires a Guid is empty /// /// /// /// /// public Contract IsEmpty(Guid val, string key, string message) { if (val != Guid.Empty) AddNotification(key, message); return this; } /// /// Requires a Guid is not empty /// /// /// /// public Contract IsNotEmpty(Guid val, string key) => IsNotEmpty(val, key, FluntErrorMessages.IsNotEmptyErrorMessage(key)); /// /// Requires a Guid is not empty /// /// /// /// /// public Contract IsNotEmpty(Guid val, string key, string message) { if (val == Guid.Empty) AddNotification(key, message); return this; } } } ================================================ FILE: Flunt/Validations/IntValidationContract.cs ================================================ using System.Collections.Generic; using System.Linq; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { #region IsGreaterThan /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(int val, int comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(int val, int comparer, string key, string message) { if (val <= (int)comparer) AddNotification(key, message); return this; } /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(int val, decimal comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(int val, decimal comparer, string key, string message) => IsGreaterThan(val, (int)comparer, key, message); /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(int val, double comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(int val, double comparer, string key, string message) => IsGreaterThan(val, (int)comparer, key, message); /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(int val, float comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(int val, float comparer, string key, string message) => IsGreaterThan(val, (int)comparer, key, message); /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(int val, long comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(int val, long comparer, string key, string message) => IsGreaterThan(val, (int)comparer, key, message); #endregion #region IsGreaterOrEqualsThan /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(int val, int comparer, string key) => IsGreaterOrEqualsThan(val, comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(int val, int comparer, string key, string message) { if (val < comparer) AddNotification(key, message); return this; } /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(int val, decimal comparer, string key) => IsGreaterOrEqualsThan(val, (int)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(int val, decimal comparer, string key, string message) => IsGreaterOrEqualsThan(val, (int)comparer, key, message); /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(int val, double comparer, string key) => IsGreaterOrEqualsThan(val, (int)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(int val, double comparer, string key, string message) => IsGreaterOrEqualsThan(val, (int)comparer, key, message); /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(int val, float comparer, string key) => IsGreaterOrEqualsThan(val, (int)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(int val, float comparer, string key, string message) => IsGreaterOrEqualsThan(val, (int)comparer, key, message); /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(int val, long comparer, string key) => IsGreaterOrEqualsThan(val, (int)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(int val, long comparer, string key, string message) => IsGreaterOrEqualsThan(val, (int)comparer, key, message); #endregion #region IsLowerThan /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(int val, int comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(int val, int comparer, string key, string message) { if (val >= comparer) AddNotification(key, message); return this; } /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(int val, decimal comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(int val, decimal comparer, string key, string message) => IsLowerThan(val, (int)comparer, key, message); /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(int val, double comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(int val, double comparer, string key, string message) => IsLowerThan(val, (int)comparer, key, message); /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(int val, float comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(int val, float comparer, string key, string message) => IsLowerThan(val, (int)comparer, key, message); /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(int val, long comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(int val, long comparer, string key, string message) => IsLowerThan(val, (int)comparer, key, message); #endregion #region IsLowerOrEqualsThan /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(int val, int comparer, string key) => IsLowerOrEqualsThan(val, comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(int val, int comparer, string key, string message) { if (val > comparer) AddNotification(key, message); return this; } /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(int val, decimal comparer, string key) => IsLowerOrEqualsThan(val, (int)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(int val, decimal comparer, string key, string message) => IsLowerOrEqualsThan(val, (int)comparer, key, message); /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(int val, double comparer, string key) => IsLowerOrEqualsThan(val, (int)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(int val, double comparer, string key, string message) => IsLowerOrEqualsThan(val, (int)comparer, key, message); /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(int val, float comparer, string key) => IsLowerOrEqualsThan(val, (int)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(int val, float comparer, string key, string message) => IsLowerOrEqualsThan(val, (int)comparer, key, message); /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(int val, long comparer, string key) => IsLowerOrEqualsThan(val, (int)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires an int is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(int val, long comparer, string key, string message) => IsLowerOrEqualsThan(val, (int)comparer, key, message); #endregion #region IsMinValue /// /// Requires an int has its min value /// /// /// /// public Contract IsMinValue(int val, string key) => IsMinValue(val, key, FluntErrorMessages.IsMinValueErrorMessage(key, int.MinValue.ToString())); /// /// Requires an int has its min value /// /// /// /// /// public Contract IsMinValue(int val, string key, string message) { if (val != int.MinValue) AddNotification(key, message); return this; } #endregion #region IsNotMinValue /// /// Requires an int has not its min value /// /// /// /// public Contract IsNotMinValue(int val, string key) => IsNotMinValue(val, key, FluntErrorMessages.IsNotMinValueErrorMessage(key, int.MinValue.ToString())); /// /// Requires an int has not its min value /// /// /// /// /// public Contract IsNotMinValue(int val, string key, string message) { if (val == int.MinValue) AddNotification(key, message); return this; } #endregion #region IsMaxValue /// /// Requires an int has its max value /// /// /// /// public Contract IsMaxValue(int val, string key) => IsMaxValue(val, key, FluntErrorMessages.IsMaxValueErrorMessage(key, int.MaxValue.ToString())); /// /// Requires an int has its max value /// /// /// /// /// public Contract IsMaxValue(int val, string key, string message) { if (val != int.MaxValue) AddNotification(key, message); return this; } #endregion #region IsNotMaxValue /// /// Requires an int has not its max value /// /// /// /// public Contract IsNotMaxValue(int val, string key) => IsNotMaxValue(val, key, FluntErrorMessages.IsNotMaxValueErrorMessage(key, int.MaxValue.ToString())); /// /// Requires an int has not its min value /// /// /// /// /// public Contract IsNotMaxValue(int val, string key, string message) { if (val == int.MaxValue) AddNotification(key, message); return this; } #endregion #region AreEquals /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(int val, int comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(int val, int comparer, string key, string message) { if (val != comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(int val, float comparer, string key) => AreEquals(val, (int)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(int val, float comparer, string key, string message) => AreEquals(val, (int)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(int val, double comparer, string key) => AreEquals(val, (int)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(int val, double comparer, string key, string message) => AreEquals(val, (int)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(int val, decimal comparer, string key) => AreEquals(val, (int)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(int val, decimal comparer, string key, string message) => AreEquals(val, (int)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(int val, long comparer, string key) => AreEquals(val, (int)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(int val, long comparer, string key, string message) => AreEquals(val, (int)comparer, key, message); #endregion #region AreNotEquals /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(int val, int comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(int val, int comparer, string key, string message) { if (val == comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(int val, float comparer, string key) => AreNotEquals(val, (int)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(int val, float comparer, string key, string message) => AreNotEquals(val, (int)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(int val, double comparer, string key) => AreNotEquals(val, (int)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(int val, double comparer, string key, string message) => AreNotEquals(val, (int)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(int val, decimal comparer, string key) => AreNotEquals(val, (int)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(int val, decimal comparer, string key, string message) => AreNotEquals(val, (int)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(int val, long comparer, string key) => AreNotEquals(val, (int)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(int val, long comparer, string key, string message) => AreNotEquals(val, (int)comparer, key, message); #endregion #region IsNull /// /// Requires an int is null /// /// /// /// public Contract IsNull(int? val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires an int is null /// /// /// /// /// public Contract IsNull(int? val, string key, string message) { if (val != null) AddNotification(key, message); return this; } #endregion #region IsNotNull /// /// Requires an int is not null /// /// /// /// public Contract IsNotNull(int? val, string key) => IsNotNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires an int is not null /// /// /// /// /// public Contract IsNotNull(int? val, string key, string message) { if (val == null) AddNotification(key, message); return this; } #endregion #region IsBetween /// /// Requires an int is between /// /// /// /// /// /// public Contract IsBetween(int val, int start, int end, string key) => IsBetween(val, start, end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is between /// /// /// /// /// /// /// public Contract IsBetween(int val, int start, int end, string key, string message) { if ((val >= start && val <= end) == false) AddNotification(key, message); return this; } /// /// Requires an int is between /// /// /// /// /// /// public Contract IsBetween(int val, float start, float end, string key) => IsBetween(val, (int)start, (int)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is between /// /// /// /// /// /// /// public Contract IsBetween(int val, float start, float end, string key, string message) => IsBetween(val, (int)start, (int)end, key, message); /// /// Requires an int is between /// /// /// /// /// /// public Contract IsBetween(int val, double start, double end, string key) => IsBetween(val, (int)start, (int)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is between /// /// /// /// /// /// /// public Contract IsBetween(int val, double start, double end, string key, string message) => IsBetween(val, (int)start, (int)end, key, message); /// /// Requires an int is between /// /// /// /// /// /// public Contract IsBetween(int val, decimal start, decimal end, string key) => IsBetween(val, (int)start, (int)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is between /// /// /// /// /// /// /// public Contract IsBetween(int val, decimal start, decimal end, string key, string message) => IsBetween(val, (int)start, (int)end, key, message); /// /// Requires an int is between /// /// /// /// /// /// public Contract IsBetween(int val, long start, long end, string key) => IsBetween(val, (int)start, (int)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is between /// /// /// /// /// /// /// public Contract IsBetween(int val, long start, long end, string key, string message) => IsBetween(val, (int)start, (int)end, key, message); #endregion #region IsNotBetween /// /// Requires an int is not between /// /// /// /// /// /// public Contract IsNotBetween(int val, int start, int end, string key) => IsNotBetween(val, start, end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is not between /// /// /// /// /// /// /// public Contract IsNotBetween(int val, int start, int end, string key, string message) { if ((val >= start && val <= end) == true) AddNotification(key, message); return this; } /// /// Requires an int is not between /// /// /// /// /// /// public Contract IsNotBetween(int val, float start, float end, string key) => IsNotBetween(val, (int)start, (int)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is not between /// /// /// /// /// /// /// public Contract IsNotBetween(int val, float start, float end, string key, string message) => IsNotBetween(val, (int)start, (int)end, key, message); /// /// Requires an int is not between /// /// /// /// /// /// public Contract IsNotBetween(int val, double start, double end, string key) => IsNotBetween(val, (int)start, (int)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is not between /// /// /// /// /// /// /// public Contract IsNotBetween(int val, double start, double end, string key, string message) => IsNotBetween(val, (int)start, (int)end, key, message); /// /// Requires an int is not between /// /// /// /// /// /// public Contract IsNotBetween(int val, decimal start, decimal end, string key) => IsNotBetween(val, (int)start, (int)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is not between /// /// /// /// /// /// /// public Contract IsNotBetween(int val, decimal start, decimal end, string key, string message) => IsNotBetween(val, (int)start, (int)end, key, message); /// /// Requires an int is not between /// /// /// /// /// /// public Contract IsNotBetween(int val, long start, long end, string key) => IsNotBetween(val, (int)start, (int)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires an int is not between /// /// /// /// /// /// /// public Contract IsNotBetween(int val, long start, long end, string key, string message) => IsNotBetween(val, (int)start, (int)end, key, message); #endregion #region Contains /// /// Requires a list contains an int /// /// /// /// /// public Contract Contains(int val, IEnumerable list, string key) => Contains(val, list, key, FluntErrorMessages.ContainsErrorMessage(key, val.ToString())); /// /// Requires a list contains an int /// /// /// /// /// /// public Contract Contains(int val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == false) AddNotification(key, message); return this; } #endregion #region NotContains /// /// Requires a list does not contains an int /// /// /// /// /// public Contract NotContains(int val, IEnumerable list, string key) => NotContains(val, list, key, FluntErrorMessages.NotContainsErrorMessage(key, val.ToString())); /// /// Requires a list does not contains an int /// /// /// /// /// /// public Contract NotContains(int val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == true) AddNotification(key, message); return this; } #endregion } } ================================================ FILE: Flunt/Validations/ListValidationContract.cs ================================================ using System.Collections.Generic; using System.Linq; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { /// /// Requires a list is null /// /// /// /// /// public Contract IsNull(IEnumerable val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires a list is null /// /// /// /// /// /// public Contract IsNull(IEnumerable val, string key, string message) { if (val != null) AddNotification(key, message); return this; } /// /// Requires a list is not null /// /// /// /// /// public Contract IsNotNull(IEnumerable val, string key) => IsNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires a list is not null /// /// /// /// /// /// public Contract IsNotNull(IEnumerable val, string key, string message) { if (val == null) AddNotification(key, message); return this; } /// /// Requires a list contains no elements /// /// /// /// /// public Contract IsEmpty(IEnumerable val, string key) => IsEmpty(val, key, FluntErrorMessages.IsEmptyErrorMessage(key)); /// /// Requires a list contains no elements /// /// /// /// /// /// public Contract IsEmpty(IEnumerable val, string key, string message) { if (val.Any()) AddNotification(key, message); return this; } /// /// Requires a list contains at least one element /// /// /// /// /// public Contract IsNotEmpty(IEnumerable val, string key) => IsNotEmpty(val, key, FluntErrorMessages.IsNotEmptyErrorMessage(key)); /// /// Requires a list contains at least one element /// /// /// /// /// /// public Contract IsNotEmpty(IEnumerable val, string key, string message) { if (val.Any() == false) AddNotification(key, message); return this; } /// /// Requires a list count is greater than /// /// /// /// /// /// public Contract IsGreaterThan(IEnumerable val, int comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a list count is greater than /// /// /// /// /// /// /// public Contract IsGreaterThan(IEnumerable val, int comparer, string key, string message) { if (val?.Count() <= comparer) AddNotification(key, message); return this; } /// /// Requires a list count is greater or equals than /// /// /// /// /// /// public Contract IsGreaterOrEqualsThan(IEnumerable val, int comparer, string key) => IsGreaterOrEqualsThan(val, comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a list count is greater or equals than /// /// /// /// /// /// /// public Contract IsGreaterOrEqualsThan(IEnumerable val, int comparer, string key, string message) { if (val?.Count() < comparer) AddNotification(key, message); return this; } /// /// Requires a list count is lower than /// /// /// /// /// /// public Contract IsLowerThan(IEnumerable val, int comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a list count is lower than /// /// /// /// /// /// /// public Contract IsLowerThan(IEnumerable val, int comparer, string key, string message) { if (val?.Count() >= comparer) AddNotification(key, message); return this; } /// /// Requires a list count is lower or equals than /// /// /// /// /// /// public Contract IsLowerOrEqualsThan(IEnumerable val, int comparer, string key) => IsLowerOrEqualsThan(val, comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a list count is lower or equals than /// /// /// /// /// /// /// public Contract IsLowerOrEqualsThan(IEnumerable val, int comparer, string key, string message) { if (val?.Count() > comparer) AddNotification(key, message); return this; } } } ================================================ FILE: Flunt/Validations/LongValidationContract.cs ================================================ using System.Collections.Generic; using System.Linq; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { #region IsGreaterThan /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(long val, long comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(long val, long comparer, string key, string message) { if (val <= (long)comparer) AddNotification(key, message); return this; } /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(long val, decimal comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(long val, decimal comparer, string key, string message) => IsGreaterThan(val, (long)comparer, key, message); /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(long val, double comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(long val, double comparer, string key, string message) => IsGreaterThan(val, (long)comparer, key, message); /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(long val, float comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(long val, float comparer, string key, string message) => IsGreaterThan(val, (long)comparer, key, message); /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(long val, int comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterThan(long val, int comparer, string key, string message) => IsGreaterThan(val, (long)comparer, key, message); #endregion #region IsGreaterOrEqualsThan /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(long val, long comparer, string key) => IsGreaterOrEqualsThan(val, comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(long val, long comparer, string key, string message) { if (val < comparer) AddNotification(key, message); return this; } /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(long val, decimal comparer, string key) => IsGreaterOrEqualsThan(val, (long)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(long val, decimal comparer, string key, string message) => IsGreaterOrEqualsThan(val, (long)comparer, key, message); /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(long val, double comparer, string key) => IsGreaterOrEqualsThan(val, (long)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(long val, double comparer, string key, string message) => IsGreaterOrEqualsThan(val, (long)comparer, key, message); /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(long val, float comparer, string key) => IsGreaterOrEqualsThan(val, (long)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(long val, float comparer, string key, string message) => IsGreaterOrEqualsThan(val, (long)comparer, key, message); /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsGreaterOrEqualsThan(long val, int comparer, string key) => IsGreaterOrEqualsThan(val, (long)comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is greater or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsGreaterOrEqualsThan(long val, int comparer, string key, string message) => IsGreaterOrEqualsThan(val, (long)comparer, key, message); #endregion #region IsLowerThan /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(long val, long comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(long val, long comparer, string key, string message) { if (val >= comparer) AddNotification(key, message); return this; } /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(long val, decimal comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(long val, decimal comparer, string key, string message) => IsLowerThan(val, (long)comparer, key, message); /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(long val, double comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(long val, double comparer, string key, string message) => IsLowerThan(val, (long)comparer, key, message); /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(long val, float comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(long val, float comparer, string key, string message) => IsLowerThan(val, (long)comparer, key, message); /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(long val, int comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerThan(long val, int comparer, string key, string message) => IsLowerThan(val, (long)comparer, key, message); #endregion #region IsLowerOrEqualsThan /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(long val, long comparer, string key) => IsLowerOrEqualsThan(val, comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(long val, long comparer, string key, string message) { if (val >comparer) AddNotification(key, message); return this; } /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(long val, decimal comparer, string key) => IsLowerOrEqualsThan(val, (long)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(long val, decimal comparer, string key, string message) => IsLowerOrEqualsThan(val, (long)comparer, key, message); /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(long val, double comparer, string key) => IsLowerOrEqualsThan(val, (long)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(long val, double comparer, string key, string message) => IsLowerOrEqualsThan(val, (long)comparer, key, message); /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(long val, float comparer, string key) => IsLowerOrEqualsThan(val, (long)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(long val, float comparer, string key, string message) => IsLowerOrEqualsThan(val, (long)comparer, key, message); /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// public Contract IsLowerOrEqualsThan(long val, int comparer, string key) => IsLowerOrEqualsThan(val, (long)comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a long is lower or equals than /// /// val /// comparer /// Key or Property Message /// Customer error message /// public Contract IsLowerOrEqualsThan(long val, int comparer, string key, string message) => IsLowerOrEqualsThan(val, (long)comparer, key, message); #endregion #region IsMinValue /// /// Requires a long has its min value /// /// /// /// public Contract IsMinValue(long val, string key) => IsMinValue(val, key, FluntErrorMessages.IsMinValueErrorMessage(key, long.MinValue.ToString())); /// /// Requires a long has its min value /// /// /// /// /// public Contract IsMinValue(long val, string key, string message) { if (val != long.MinValue) AddNotification(key, message); return this; } #endregion #region IsNotMinValue /// /// Requires a long has not its min value /// /// /// /// public Contract IsNotMinValue(long val, string key) => IsNotMinValue(val, key, FluntErrorMessages.IsNotMinValueErrorMessage(key, long.MinValue.ToString())); /// /// Requires a long has not its min value /// /// /// /// /// public Contract IsNotMinValue(long val, string key, string message) { if (val == long.MinValue) AddNotification(key, message); return this; } #endregion #region IsMaxValue /// /// Requires a long has its max value /// /// /// /// public Contract IsMaxValue(long val, string key) => IsMaxValue(val, key, FluntErrorMessages.IsMaxValueErrorMessage(key, long.MaxValue.ToString())); /// /// Requires a long has its max value /// /// /// /// /// public Contract IsMaxValue(long val, string key, string message) { if (val != long.MaxValue) AddNotification(key, message); return this; } #endregion #region IsNotMaxValue /// /// Requires a long has not its max value /// /// /// /// public Contract IsNotMaxValue(long val, string key) => IsNotMaxValue(val, key, FluntErrorMessages.IsNotMaxValueErrorMessage(key, long.MaxValue.ToString())); /// /// Requires a long has not its min value /// /// /// /// /// public Contract IsNotMaxValue(long val, string key, string message) { if (val == long.MaxValue) AddNotification(key, message); return this; } #endregion #region AreEquals /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(long val, long comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(long val, long comparer, string key, string message) { if (val != comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(long val, float comparer, string key) => AreEquals(val, (long)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(long val, float comparer, string key, string message) => AreEquals(val, (long)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(long val, double comparer, string key) => AreEquals(val, (long)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(long val, double comparer, string key, string message) => AreEquals(val, (long)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(long val, decimal comparer, string key) => AreEquals(val, (long)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(long val, decimal comparer, string key, string message) => AreEquals(val, (long)comparer, key, message); /// /// Requires two decimals are equals /// /// /// /// /// public Contract AreEquals(long val, int comparer, string key) => AreEquals(val, (long)comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are equals /// /// /// /// /// /// public Contract AreEquals(long val, int comparer, string key, string message) => AreEquals(val, (long)comparer, key, message); #endregion #region AreNotEquals /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(long val, long comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(long val, long comparer, string key, string message) { if (val == comparer) AddNotification(key, message); return this; } /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(long val, float comparer, string key) => AreNotEquals(val, (long)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(long val, float comparer, string key, string message) => AreNotEquals(val, (long)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(long val, double comparer, string key) => AreNotEquals(val, (long)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(long val, double comparer, string key, string message) => AreNotEquals(val, (long)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(long val, decimal comparer, string key) => AreNotEquals(val, (long)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(long val, decimal comparer, string key, string message) => AreNotEquals(val, (long)comparer, key, message); /// /// Requires two decimals are not equals /// /// /// /// /// public Contract AreNotEquals(long val, int comparer, string key) => AreNotEquals(val, (long)comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two decimals are not equals /// /// /// /// /// /// public Contract AreNotEquals(long val, int comparer, string key, string message) => AreNotEquals(val, (long)comparer, key, message); #endregion #region IsNull /// /// Requires a long is null /// /// /// /// public Contract IsNull(long? val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires a long is null /// /// /// /// /// public Contract IsNull(long? val, string key, string message) { if (val != null) AddNotification(key, message); return this; } #endregion #region IsNotNull /// /// Requires a long is not null /// /// /// /// public Contract IsNotNull(long? val, string key) => IsNotNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires a long is not null /// /// /// /// /// public Contract IsNotNull(long? val, string key, string message) { if (val == null) AddNotification(key, message); return this; } #endregion #region IsBetween /// /// Requires a long is between /// /// /// /// /// /// public Contract IsBetween(long val, long start, long end, string key) => IsBetween(val, start, end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is between /// /// /// /// /// /// /// public Contract IsBetween(long val, long start, long end, string key, string message) { if ((val >= start && val <= end) == false) AddNotification(key, message); return this; } /// /// Requires a long is between /// /// /// /// /// /// public Contract IsBetween(long val, float start, float end, string key) => IsBetween(val, (long)start, (long)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is between /// /// /// /// /// /// /// public Contract IsBetween(long val, float start, float end, string key, string message) => IsBetween(val, (long)start, (long)end, key, message); /// /// Requires a long is between /// /// /// /// /// /// public Contract IsBetween(long val, double start, double end, string key) => IsBetween(val, (long)start, (long)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is between /// /// /// /// /// /// /// public Contract IsBetween(long val, double start, double end, string key, string message) => IsBetween(val, (long)start, (long)end, key, message); /// /// Requires a long is between /// /// /// /// /// /// public Contract IsBetween(long val, decimal start, decimal end, string key) => IsBetween(val, (long)start, (long)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is between /// /// /// /// /// /// /// public Contract IsBetween(long val, decimal start, decimal end, string key, string message) => IsBetween(val, (long)start, (long)end, key, message); /// /// Requires a long is between /// /// /// /// /// /// public Contract IsBetween(long val, int start, int end, string key) => IsBetween(val, (long)start, (long)end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is between /// /// /// /// /// /// /// public Contract IsBetween(long val, int start, int end, string key, string message) => IsBetween(val, (long)start, (long)end, key, message); #endregion #region IsNotBetween /// /// Requires a long is not between /// /// /// /// /// /// public Contract IsNotBetween(long val, long start, long end, string key) => IsNotBetween(val, start, end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is not between /// /// /// /// /// /// /// public Contract IsNotBetween(long val, long start, long end, string key, string message) { if ((val >= start && val <= end) == true) AddNotification(key, message); return this; } /// /// Requires a long is not between /// /// /// /// /// /// public Contract IsNotBetween(long val, float start, float end, string key) => IsNotBetween(val, (long)start, (long)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is not between /// /// /// /// /// /// /// public Contract IsNotBetween(long val, float start, float end, string key, string message) => IsNotBetween(val, (long)start, (long)end, key, message); /// /// Requires a long is not between /// /// /// /// /// /// public Contract IsNotBetween(long val, double start, double end, string key) => IsNotBetween(val, (long)start, (long)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is not between /// /// /// /// /// /// /// public Contract IsNotBetween(long val, double start, double end, string key, string message) => IsNotBetween(val, (long)start, (long)end, key, message); /// /// Requires a long is not between /// /// /// /// /// /// public Contract IsNotBetween(long val, decimal start, decimal end, string key) => IsNotBetween(val, (long)start, (long)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is not between /// /// /// /// /// /// /// public Contract IsNotBetween(long val, decimal start, decimal end, string key, string message) => IsNotBetween(val, (long)start, (long)end, key, message); /// /// Requires a long is not between /// /// /// /// /// /// public Contract IsNotBetween(long val, int start, int end, string key) => IsNotBetween(val, (long)start, (long)end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(FluntFormats.DateTimeFormat), end.ToString(FluntFormats.DateTimeFormat))); /// /// Requires a long is not between /// /// /// /// /// /// /// public Contract IsNotBetween(long val, int start, int end, string key, string message) => IsNotBetween(val, (long)start, (long)end, key, message); #endregion #region Contains /// /// Requires a list contains a long /// /// /// /// /// public Contract Contains(long val, IEnumerable list, string key) => Contains(val, list, key, FluntErrorMessages.ContainsErrorMessage(key, val.ToString())); /// /// Requires a list contains a long /// /// /// /// /// /// public Contract Contains(long val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == false) AddNotification(key, message); return this; } #endregion #region NotContains /// /// Requires a list does not contains a long /// /// /// /// /// public Contract NotContains(long val, IEnumerable list, string key) => NotContains(val, list, key, FluntErrorMessages.NotContainsErrorMessage(key, val.ToString())); /// /// Requires a list does not contains a long /// /// /// /// /// /// public Contract NotContains(long val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == true) AddNotification(key, message); return this; } #endregion } } ================================================ FILE: Flunt/Validations/ObjectValidationContract.cs ================================================ using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { /// /// Requires an object is null /// /// /// /// public Contract IsNull(object val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires an object is null /// /// /// /// /// public Contract IsNull(object val, string key, string message) { if (val != null) AddNotification(key, message); return this; } /// /// Requires an object is not null /// /// /// /// public Contract IsNotNull(object val, string key) => IsNotNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires an object is not null /// /// /// /// /// public Contract IsNotNull(object val, string key, string message) { if (val == null) AddNotification(key, message); return this; } /// /// Requires two objects are equals /// /// /// /// /// public Contract AreEquals(object val, object comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val?.ToString(), comparer?.ToString())); /// /// Requires two objects are equals /// /// /// /// /// /// public Contract AreEquals(object val, object comparer, string key, string message) { if (val == null || comparer == null) return this; if (val.Equals(comparer) == false) AddNotification(key, message); return this; } /// /// Requires two objects are not equals /// /// /// /// /// public Contract AreNotEquals(object val, object comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val?.ToString(), comparer?.ToString())); /// /// Requires two objects are not equals /// /// /// /// /// /// public Contract AreNotEquals(object val, object comparer, string key, string message) { if (val == null || comparer == null) return this; if (val.Equals(comparer)) AddNotification(key, message); return this; } } } ================================================ FILE: Flunt/Validations/RegexValidationContract.cs ================================================ using System.Text.RegularExpressions; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { /// /// Requires a string matches a regex pattern /// /// /// /// /// public Contract Matches(string val, string pattern, string key) => Matches(val, pattern, key, FluntErrorMessages.MatchesErrorMessage(key, pattern)); /// /// Requires a string matches a regex pattern /// /// /// /// /// /// public Contract Matches(string val, string pattern, string key, string message) { if (!Regex.IsMatch(val ?? "", pattern)) AddNotification(key, message); return this; } /// /// Requires a string not matches a regex pattern /// /// /// /// /// public Contract NotMatches(string val, string pattern, string key) => NotMatches(val, pattern, key, FluntErrorMessages.NotMatchesErrorMessage(key, pattern)); /// /// Requires a string not matches a regex pattern /// /// /// /// /// /// public Contract NotMatches(string val, string pattern, string key, string message) { if (Regex.IsMatch(val ?? "", pattern)) AddNotification(key, message); return this; } } } ================================================ FILE: Flunt/Validations/StringValidationContract.cs ================================================ using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { /// /// Requires a string is null /// /// /// /// public Contract IsNull(string val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires a string is null /// /// /// /// /// public Contract IsNull(string val, string key, string message) { if (val != null) AddNotification(key, message); return this; } /// /// Requires a string is not null /// /// /// /// public Contract IsNotNull(string val, string key) => IsNotNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires a string is not null /// /// /// /// /// public Contract IsNotNull(string val, string key, string message) { if (val == null) AddNotification(key, message); return this; } /// /// Requires a string is null or empty /// /// /// /// public Contract IsNullOrEmpty(string val, string key) => IsNullOrEmpty(val, key, FluntErrorMessages.IsNullOrEmptyErrorMessage(key)); /// /// Requires a string is null or empty /// /// /// /// /// public Contract IsNullOrEmpty(string val, string key, string message) { if (string.IsNullOrEmpty(val) == false) AddNotification(key, message); return this; } /// /// Requires a string is not null or empty /// /// /// /// public Contract IsNotNullOrEmpty(string val, string key) => IsNotNullOrEmpty(val, key, FluntErrorMessages.IsNotNullOrEmptyErrorMessage(key)); /// /// Requires a string is not null or empty /// /// /// /// /// public Contract IsNotNullOrEmpty(string val, string key, string message) { if (string.IsNullOrEmpty(val)) AddNotification(key, message); return this; } /// /// Requires a string is null or white space /// /// /// /// public Contract IsNullOrWhiteSpace(string val, string key) => IsNullOrWhiteSpace(val, key, FluntErrorMessages.IsNullOrWhiteSpaceErrorMessage(key)); /// /// Requires a string is null or white space /// /// /// /// /// public Contract IsNullOrWhiteSpace(string val, string key, string message) { if (string.IsNullOrWhiteSpace(val) == false) AddNotification(key, message); return this; } /// /// Requires a string is not null or white space /// /// /// /// public Contract IsNotNullOrWhiteSpace(string val, string key) => IsNotNullOrWhiteSpace(val, key, FluntErrorMessages.IsNotNullOrWhiteSpaceErrorMessage(key)); /// /// Requires a string is not null or white space /// /// /// /// /// public Contract IsNotNullOrWhiteSpace(string val, string key, string message) { if (string.IsNullOrWhiteSpace(val)) AddNotification(key, message); return this; } /// /// Requires two strings are equals /// /// /// /// /// public Contract AreEquals(string val, string comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val, comparer)); /// /// Requires two strings are equals /// /// /// /// /// /// public Contract AreEquals(string val, string comparer, string key, string message) { if (val != comparer) AddNotification(key, message); return this; } /// /// Requires a string have a len /// /// /// /// /// /// public Contract AreEquals(string val, int comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val, comparer.ToString())); /// /// Requires a string have a len /// /// /// /// /// /// public Contract AreEquals(string val, int comparer, string key, string message) { if (val == null) return this; if (val.Length != comparer) AddNotification(key, message); return this; } /// /// Requires two strings are not equals /// /// /// /// /// public Contract AreNotEquals(string val, string comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val, comparer)); /// /// Requires two strings are not equals /// /// /// /// /// /// public Contract AreNotEquals(string val, string comparer, string key, string message) { if (val == comparer) AddNotification(key, message); return this; } /// /// Requires a string do not have a len /// /// /// /// /// /// public Contract AreNotEquals(string val, int comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val, comparer.ToString())); /// /// Requires a string do not have a len /// /// /// /// /// /// public Contract AreNotEquals(string val, int comparer, string key, string message) { if (val == null) return this; if (val.Length == comparer) AddNotification(key, message); return this; } /// /// Requires a string contains /// /// /// /// /// public Contract Contains(string val, string comparer, string key) => Contains(val, comparer, key, FluntErrorMessages.ContainsErrorMessage(val, comparer)); /// /// Requires a string contains /// /// /// /// /// /// public Contract Contains(string val, string comparer, string key, string message) { if (string.IsNullOrEmpty(val)) val = string.Empty; if (val.Contains(comparer) == false) AddNotification(key, message); return this; } /// /// Requires a string not contains /// /// /// /// /// public Contract NotContains(string val, string comparer, string key) => NotContains(val, comparer, key, FluntErrorMessages.NotContainsErrorMessage(val, comparer)); /// /// Requires a string not contains /// /// /// /// /// /// public Contract NotContains(string val, string comparer, string key, string message) { if (string.IsNullOrEmpty(val)) val = string.Empty; if (val.Contains(comparer)) AddNotification(key, message); return this; } /// /// Requires a string len is greater than /// /// /// /// /// public Contract IsGreaterThan(string val, int comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a string is greater than /// /// /// /// /// /// public Contract IsGreaterThan(string val, int comparer, string key, string message) { if (val == null) return this; if (val.Length <= comparer) AddNotification(key, message); return this; } /// /// Requires a string len is greater or equals than /// /// /// /// /// public Contract IsGreaterOrEqualsThan(string val, int comparer, string key) => IsGreaterOrEqualsThan(val, comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a string len is greater or equals than /// /// /// /// /// /// public Contract IsGreaterOrEqualsThan(string val, int comparer, string key, string message) { if (val == null) return this; if (val.Length < comparer) AddNotification(key, message); return this; } /// /// Requires a string len is lower than /// /// /// /// /// public Contract IsLowerThan(string val, int comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a string len is lower than /// /// /// /// /// /// public Contract IsLowerThan(string val, int comparer, string key, string message) { if (val == null) return this; if (val.Length >= comparer) AddNotification(key, message); return this; } /// /// Requires a string len is lower or equals than /// /// /// /// /// public Contract IsLowerOrEqualsThan(string val, int comparer, string key) => IsLowerOrEqualsThan(val, comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a string len is lower or equals than /// /// /// /// /// /// public Contract IsLowerOrEqualsThan(string val, int comparer, string key, string message) { if (val == null) return this; if (val.Length > comparer) AddNotification(key, message); return this; } /// /// Requires a string len is between /// /// /// /// /// /// /// public Contract IsBetween(string val, int min, int max, string key, string message) { if (val == null) return this; if (string.IsNullOrEmpty(val) || string.IsNullOrWhiteSpace(val)) return this; if (val.Length < min || val.Length > max) AddNotification(key, message); return this; } } } ================================================ FILE: Flunt/Validations/TimeSpanValidationContract.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { #region IsGreaterThan /// /// Requires a date is greater than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterThan(TimeSpan val, TimeSpan comparer, string key) => IsGreaterThan(val, comparer, key, FluntErrorMessages.IsGreaterThanErrorMessage(key, comparer.ToString())); /// /// Requires a date is greater than /// /// val /// comparer /// Key or Property Name /// Customer error message /// public Contract IsGreaterThan(TimeSpan val, TimeSpan comparer, string key, string message) { if (val <= comparer) AddNotification(key, message); return this; } #endregion #region IsGreaterOrEqualsThan /// /// Requires a date is greater or equals than /// /// val /// comparer /// Key or Property Name /// public Contract IsGreaterOrEqualsThan(TimeSpan val, TimeSpan comparer, string key) => IsGreaterOrEqualsThan(val, comparer, key, FluntErrorMessages.IsGreaterOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a date is greater or equals than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsGreaterOrEqualsThan(TimeSpan val, TimeSpan comparer, string key, string message) { if (val < comparer) AddNotification(key, message); return this; } #endregion #region IsLowerThan /// /// Requires a date is lower than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerThan(TimeSpan val, TimeSpan comparer, string key) => IsLowerThan(val, comparer, key, FluntErrorMessages.IsLowerThanErrorMessage(key, comparer.ToString())); /// /// Requires a date is lower than /// /// val /// comparer /// Key or Property Name /// Customer error message /// public Contract IsLowerThan(TimeSpan val, TimeSpan comparer, string key, string message) { if (val >= comparer) AddNotification(key, message); return this; } #endregion #region IsLowerOrEqualsThan /// /// Requires a date is lower or equals than /// /// val /// comparer /// Key or Property Name /// public Contract IsLowerOrEqualsThan(TimeSpan val, TimeSpan comparer, string key) => IsLowerOrEqualsThan(val, comparer, key, FluntErrorMessages.IsLowerOrEqualsThanErrorMessage(key, comparer.ToString())); /// /// Requires a date is lower or equals than /// /// val /// comparer /// Key or Property Name /// Custom error message /// public Contract IsLowerOrEqualsThan(TimeSpan val, TimeSpan comparer, string key, string message) { if (val > comparer) AddNotification(key, message); return this; } #endregion #region IsNull /// /// Requires a date is null /// /// date /// Key or Property Name /// public Contract IsNull(TimeSpan? val, string key) => IsNull(val, key, FluntErrorMessages.IsNullErrorMessage(key)); /// /// Requires a date is null /// /// date /// Key or Property Name /// Custom error message /// public Contract IsNull(TimeSpan? val, string key, string message) { if (val != null) AddNotification(key, message); return this; } #endregion #region IsNotNull /// /// Requires a date is not null /// /// date /// Key or Property Name /// public Contract IsNotNull(TimeSpan? val, string key) => IsNotNull(val, key, FluntErrorMessages.IsNotNullErrorMessage(key)); /// /// Requires a date is not null /// /// date /// Key or Property Name /// Custom error message /// public Contract IsNotNull(TimeSpan? val, string key, string message) { if (val == null) AddNotification(key, message); return this; } #endregion #region IsBetween /// /// Requires a date is between /// /// date /// start date /// end date /// Key or Property Name /// public Contract IsBetween(TimeSpan val, TimeSpan start, TimeSpan end, string key) => IsBetween(val, start, end, key, FluntErrorMessages.IsBetweenErrorMessage(key, start.ToString(), end.ToString())); /// /// Requires a date is between /// /// date /// start date /// end date /// Key or Property Name /// Customer error message /// public Contract IsBetween(TimeSpan val, TimeSpan start, TimeSpan end, string key, string message) { if ((val >= start && val <= end) == false) AddNotification(key, message); return this; } #endregion #region IsNotBetween /// /// Requires a date is not between /// /// date /// start date /// end date /// Key or Property Name /// public Contract IsNotBetween(TimeSpan val, TimeSpan start, TimeSpan end, string key) => IsNotBetween(val, start, end, key, FluntErrorMessages.IsNotBetweenErrorMessage(key, start.ToString(), end.ToString())); /// /// Requires a date is not between /// /// date /// start date /// end date /// Key or Property Name /// Customer error message /// public Contract IsNotBetween(TimeSpan val, TimeSpan start, TimeSpan end, string key, string message) { if ((val >= start && val <= end) == true) AddNotification(key, message); return this; } #endregion #region IsMinValue /// /// Requires a date is min value /// /// date /// Key or Property Name /// public Contract IsMinValue(TimeSpan val, string key) => IsMinValue(val, key, FluntErrorMessages.IsMinValueErrorMessage(key, TimeSpan.MinValue.ToString())); /// /// Requires a date is min value /// /// date /// Key or Property Name /// Custom error message /// public Contract IsMinValue(TimeSpan val, string key, string message) { if (val != TimeSpan.MinValue) AddNotification(key, message); return this; } #endregion #region IsNotMinValue /// /// Requires a date is not min value /// /// date /// Key or Property Name /// public Contract IsNotMinValue(TimeSpan val, string key) => IsNotMinValue(val, key, FluntErrorMessages.IsNotMinValueErrorMessage(key, TimeSpan.MinValue.ToString())); /// /// Requires a date is not min value /// /// date /// Key or Property Name /// Custom error message /// public Contract IsNotMinValue(TimeSpan val, string key, string message) { if (val == TimeSpan.MinValue) AddNotification(key, message); return this; } #endregion #region IsMaxValue /// /// Requires a date is max value /// /// date /// Key or Property Name /// public Contract IsMaxValue(TimeSpan val, string key) => IsMaxValue(val, key, FluntErrorMessages.IsMaxValueErrorMessage(key, TimeSpan.MaxValue.ToString())); /// /// Requires a date is max value /// /// date /// Key or Property Name /// Custom error message /// public Contract IsMaxValue(TimeSpan val, string key, string message) { if (val != TimeSpan.MaxValue) AddNotification(key, message); return this; } #endregion #region IsNotMaxValue /// /// Requires a date is not max value /// /// date /// Key or Property Name /// public Contract IsNotMaxValue(TimeSpan val, string key) => IsNotMaxValue(val, key, FluntErrorMessages.IsNotMaxValueErrorMessage(key, TimeSpan.MaxValue.ToString())); /// /// Requires a date is not max value /// /// date /// Key or Property Name /// Custom error message /// public Contract IsNotMaxValue(TimeSpan val, string key, string message) { if (val == TimeSpan.MaxValue) AddNotification(key, message); return this; } #endregion #region AreEquals /// /// Require dates are equals /// /// date /// date /// Key or Property Name /// public Contract AreEquals(TimeSpan val, TimeSpan comparer, string key) => AreEquals(val, comparer, key, FluntErrorMessages.AreEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Require dates are equals /// /// date /// date /// Key or Property Name /// Customer error message /// public Contract AreEquals(TimeSpan val, TimeSpan comparer, string key, string message) { if (val != comparer) AddNotification(key, message); return this; } #endregion #region AreNotEquals /// /// Requires two dates are not equals /// /// date /// date /// Key or Property Name /// public Contract AreNotEquals(TimeSpan val, TimeSpan comparer, string key) => AreNotEquals(val, comparer, key, FluntErrorMessages.AreNotEqualsErrorMessage(val.ToString(), comparer.ToString())); /// /// Requires two dates are not equals /// /// date /// date /// Key or Property Name /// Custom error message /// public Contract AreNotEquals(TimeSpan val, TimeSpan comparer, string key, string message) { if (val == comparer) AddNotification(key, message); return this; } #endregion #region Contains /// /// Requires a list contains a date /// /// date /// list of dates /// Key or Property Name /// public Contract Contains(TimeSpan val, IEnumerable list, string key) => Contains(val, list, key, FluntErrorMessages.ContainsErrorMessage(key, val.ToString())); /// /// Requires a list contains a date /// /// date /// list of dates /// Key or Property Name /// Custom error message /// public Contract Contains(TimeSpan val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == false) AddNotification(key, message); return this; } #endregion #region NotContains /// /// Requires a list not contains a date /// /// date /// list of dates /// Key or Property Name /// public Contract NotContains(TimeSpan val, IEnumerable list, string key) => NotContains(val, list, key, FluntErrorMessages.NotContainsErrorMessage(key, val.ToString())); /// /// Requires a list not contains a date /// /// date /// list of dates /// Key or Property Name /// Custom error message /// public Contract NotContains(TimeSpan val, IEnumerable list, string key, string message) { if (list.Any(x => x == val) == true) AddNotification(key, message); return this; } #endregion } } ================================================ FILE: Flunt/Validations/UrlValidationContract.cs ================================================ using Flunt.Localization; namespace Flunt.Validations { public partial class Contract { /// /// Requires a string is an URL /// /// /// /// public Contract IsUrl(string val, string key) => IsUrl(val, key, FluntErrorMessages.IsUrlErrorMessage(key)); /// /// Requires a string is an URL /// /// /// /// /// public Contract IsUrl(string val, string key, string message) => Matches(val, FluntRegexPatterns.UrlRegexPattern, key, message); /// /// Requires a string is an URL or empty /// /// /// /// public Contract IsUrlOrEmpty(string val, string key) => IsUrlOrEmpty(val, key, FluntErrorMessages.IsUrlOrEmptyErrorMessage(key)); /// /// Requires a string is an URL or empty /// /// /// /// /// public Contract IsUrlOrEmpty(string val, string key, string message) { return string.IsNullOrEmpty(val) ? this : Matches(val, FluntRegexPatterns.UrlRegexPattern, key, message); } /// /// Requires a string is not an URL /// /// /// /// public Contract IsNotUrl(string val, string key) => IsNotUrl(val, key, FluntErrorMessages.IsNotUrlErrorMessage(key)); /// /// Requires a string is not an URL /// /// /// /// /// public Contract IsNotUrl(string val, string key, string message) => NotMatches(val, FluntRegexPatterns.UrlRegexPattern, key, message); /// /// Requires a string is not an URL or is empty /// /// /// /// public Contract IsNotUrlOrEmpty(string val, string key) => IsNotUrlOrEmpty(val, key, FluntErrorMessages.IsNotUrlOrEmptyErrorMessage(key)); /// /// Requires a string is not an URL or is empty /// /// /// /// /// public Contract IsNotUrlOrEmpty(string val, string key, string message) { return string.IsNullOrEmpty(val) ? this : NotMatches(val, FluntRegexPatterns.UrlRegexPattern, key, message); } } } ================================================ FILE: Flunt.Samples/Entities/Contracts/CreateCustomerContract.cs ================================================ using Flunt.Validations; namespace Flunt.Samples.Entities.Contracts { public class CreateCustomerContract : Contract { public CreateCustomerContract(Customer customer) { Requires() .IsNotNullOrEmpty(customer.Name, "Name", "Custom error message"); } } } ================================================ FILE: Flunt.Samples/Entities/Contracts/UpdateCustomerBirthDateContract.cs ================================================ using System; using Flunt.Validations; namespace Flunt.Samples.Entities.Contracts { public class UpdateCustomerBirthDateContract : Contract { public UpdateCustomerBirthDateContract(Customer customer) { Requires() .IsLowerThan(customer.BirthDate, DateTime.Now.AddYears(-18), "BirthDate"); } } } ================================================ FILE: Flunt.Samples/Entities/Customer.cs ================================================ using System; using Flunt.Samples.Entities.Contracts; using Flunt.Samples.ValueObjects; namespace Flunt.Samples.Entities { public class Customer : Entity { public Customer(string name, Email email) { Name = name; Email = email; AddNotifications(new CreateCustomerContract(this)); } public string Name { get; private set; } public Email Email { get; private set; } public DateTime BirthDate { get; private set; } public void UpdateBirthDate(DateTime birthDate) { BirthDate = birthDate; AddNotifications(new UpdateCustomerBirthDateContract(this)); } } } ================================================ FILE: Flunt.Samples/Entities/Entity.cs ================================================ using System; using Flunt.Notifications; namespace Flunt.Samples.Entities { public abstract class Entity : Notifiable { protected Entity() { Id = Guid.NewGuid(); } public Guid Id { get; private set; } } } ================================================ FILE: Flunt.Samples/Entities/Order.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Flunt.Samples.Entities { class Order { } } ================================================ FILE: Flunt.Samples/Entities/OrderLine.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Flunt.Samples.Entities { class OrderLine { } } ================================================ FILE: Flunt.Samples/Flunt.Samples.csproj ================================================ Exe net5.0 ================================================ FILE: Flunt.Samples/Handlers/CustomerHandler.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Flunt.Notifications; using Flunt.Samples.Entities; using Flunt.Samples.Handlers.Requests; using Flunt.Samples.ValueObjects; namespace Flunt.Samples.Handlers { public class CustomerHandler : Notifiable { public bool Handle(CreateCustomerRequest request) { if (request.IsValid == false) { AddNotifications(request.Notifications); return false; } var email = new Email(request.Email); var customer = new Customer(request.Name, email); AddNotifications(email.Notifications); AddNotifications(customer.Notifications); return IsValid; } } } ================================================ FILE: Flunt.Samples/Handlers/Requests/Contracts/CreateCustomerRequestContract.cs ================================================ using Flunt.Validations; namespace Flunt.Samples.Handlers.Requests.Contracts { public class CreateCustomerRequestContract : Contract { public CreateCustomerRequestContract(CreateCustomerRequest request) { Requires() .IsNotNullOrEmpty(request.Name, "Name", "Custom error message") .IsEmail(request.Email, "Email"); } } } ================================================ FILE: Flunt.Samples/Handlers/Requests/CreateCustomerRequest.cs ================================================ using Flunt.Notifications; using Flunt.Samples.Handlers.Requests.Contracts; namespace Flunt.Samples.Handlers.Requests { public class CreateCustomerRequest : Notifiable { public CreateCustomerRequest(string name, string email) { Name = name; Email = email; AddNotifications(new CreateCustomerRequestContract(this)); } public string Name { get; private set; } public string Email { get; private set; } } } ================================================ FILE: Flunt.Samples/Program.cs ================================================ using System; using Flunt.Localization; using Flunt.Samples.Handlers; using Flunt.Samples.Handlers.Requests; namespace Flunt.Samples { class Program { static void Main(string[] args) { FluntErrorMessages.IsEmailLocalizationErrorMessage = "deve ser um E-mail"; var request = new CreateCustomerRequest("", ""); var handler = new CustomerHandler(); var response = handler.Handle(request); if (response == false) { foreach (var item in handler.Notifications) { Console.WriteLine($"{item.Key} - {item.Message}"); } } Console.ReadKey(); } } } ================================================ FILE: Flunt.Samples/ValueObjects/Contracts/CreateEmailContract.cs ================================================ using Flunt.Validations; namespace Flunt.Samples.ValueObjects.Contracts { public class CreateEmailContract : Contract { public CreateEmailContract(Email email) { Requires() .IsEmail(email.Address, "Email"); } } } ================================================ FILE: Flunt.Samples/ValueObjects/Email.cs ================================================ using Flunt.Notifications; using Flunt.Samples.ValueObjects.Contracts; namespace Flunt.Samples.ValueObjects { public class Email : Notifiable { public Email(string address) { Address = address; AddNotifications(new CreateEmailContract(this)); } public string Address { get; private set; } } } ================================================ FILE: Flunt.Tests/BoolValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class BoolValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("Bool Validation")] [TestMethod("Requires that a bool is true")] public void RequiresBoolIsTrue() { var contract = new Contract() .Requires() .IsTrue(_entity.BoolTrueProperty, "Bool") .IsTrue(_entity.BoolTrueProperty, "Bool", "Custom message here") .IsTrue(_entity.BoolFalseProperty, "Bool") .IsTrue(_entity.BoolFalseProperty, "Bool", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Bool Validation")] [TestMethod("Requires that a bool is false")] public void RequiresBoolIsFalse() { var contract = new Contract() .Requires() .IsFalse(_entity.BoolTrueProperty, "Bool") .IsFalse(_entity.BoolTrueProperty, "Bool", "Custom message here") .IsFalse(_entity.BoolFalseProperty, "Bool") .IsFalse(_entity.BoolFalseProperty, "Bool", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Bool Validation")] [TestMethod("Requires that a bool is not null")] public void RequiresBoolIsNotNull() { var contract = new Contract() .Requires() .IsNotNull(_entity.BoolTrueProperty, "Bool") .IsNotNull(_entity.BoolTrueProperty, "Bool", "Custom message here") .IsNotNull(_entity.BoolNullProperty, "Bool") .IsNotNull(_entity.BoolNullProperty, "Bool", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Bool Validation")] [TestMethod("Requires that a bool is null")] public void RequiresBoolIsNull() { var contract = new Contract() .Requires() .IsNull(_entity.BoolTrueProperty, "Bool") .IsNull(_entity.BoolTrueProperty, "Bool", "Custom message here") .IsNull(_entity.BoolNullProperty, "Bool") .IsNull(_entity.BoolNullProperty, "Bool", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } } } ================================================ FILE: Flunt.Tests/CreditCardValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class CreditCardValidationTests { [TestCategory("Credit Card Validation")] [TestMethod("Requires a string is a credit card")] public void IsCreditCard() { var contract = new Contract() .Requires() // Invalid .IsCreditCard("0123-4567-8910-1112", "Credit Card") .IsCreditCard("0123-4567-8910-1112", "Credit Card", "Custom error message") // AMEX .IsCreditCard("373433821922186", "Credit Card") .IsCreditCard("3427-6024-6436-857", "Credit Card", "Custom error message") .IsCreditCard("346632758191947", "Credit Card") .IsCreditCard("4485 2186 4519 4493", "Credit Card", "Custom error message") .IsCreditCard("375194347138826", "Credit Card") .IsCreditCard("346935889946281", "Credit Card", "Custom error message") // MASTER .IsCreditCard("5568520982367328", "Credit Card") .IsCreditCard("5431-3877-6236-1722", "Credit Card", "Custom error message") .IsCreditCard("5169078428154498", "Credit Card") .IsCreditCard("5448 9922 6407 5729", "Credit Card", "Custom error message") .IsCreditCard("5263491699272904", "Credit Card") // VISA .IsCreditCard("4532988359995672", "Credit Card") .IsCreditCard("4501-2496-9117-8544", "Credit Card", "Custom error message") .IsCreditCard("4716369734700038", "Credit Card") .IsCreditCard("4024 0071 2090 7083", "Credit Card", "Custom error message") .IsCreditCard("4916412584685087", "Credit Card") // DISCOVER .IsCreditCard("6011825815766898", "Credit Card") .IsCreditCard("6011-8178-9685-9379", "Credit Card", "Custom error message") .IsCreditCard("6011926127588515", "Credit Card") .IsCreditCard("6011 1719 2817 3668", "Credit Card", "Custom error message") .IsCreditCard("601 11 4054-68 367 33", "Credit Card"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } } } ================================================ FILE: Flunt.Tests/CustomNotificationsTests.cs ================================================ using System; using System.Collections.Generic; using Flunt.Notifications; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class CustomNotificationsTests { private readonly Customer _customer; public CustomNotificationsTests() { _customer = new Customer(); } [TestCategory("Custom Notification")] [TestMethod("Should not register a customer without a name")] public void ShouldNotRegisterACustomerWithoutAName() { _customer.Name = string.Empty; _customer.Save(); Assert.AreEqual(_customer.IsValid, false); Assert.AreEqual(_customer.Notifications.Count, 1); } [TestCategory("Custom Notification")] [TestMethod("Should not update a customer without an email")] public void ShouldNotUpdateACustomerWithoutAnEmail() { _customer.Name = "Andr Baltieri"; _customer.Email = string.Empty; _customer.Update(); Assert.AreEqual(_customer.IsValid, false); Assert.AreEqual(_customer.Notifications.Count, 1); } [TestCategory("Custom Notification")] [TestMethod("Should not update a customer with test email")] public void ShouldNotUpdateCustomersWithTestEmails() { _customer.Name = "Andr Baltieri"; _customer.Email = "teste@teste.com"; _customer.Update(); Assert.AreEqual(_customer.IsValid, false); Assert.AreEqual(_customer.Notifications.Count, 1); } } #region #1. Create a custom notifiable class public class CustomNotifiable : Notifiable, INotifiable { public void AddNotifications(IEnumerable notifications) { foreach (var item in notifications) { var notification = new CustomNotification(item.Key, item.Message, DateTime.Now); AddNotification(notification); } } } #endregion #region #2. Create your custom notification public class CustomNotification : Notification { public CustomNotification(string key, string message) { Key = key; Message = message; Date = DateTime.Now; } public CustomNotification(string key, string message, DateTime date) { Key = key; Message = message; Date = date; } // Your notifications now have a date time public DateTime Date { get; set; } } #endregion #region #3. Prepare your class/contract public class Customer : CustomNotifiable { public string Name { get; set; } public string Email { get; set; } public void Save() { var contract = new CreateCustomerSpecification(this); AddNotifications(contract.Notifications); } public void Update() { var contract = new UpdateCustomerSpecification(this); if (Email == "teste@teste.com") AddNotification(new CustomNotification("Email", "Invalid email address")); AddNotifications(contract.Notifications); } } public class CreateCustomerSpecification : Contract { public CreateCustomerSpecification(Customer customer) { Requires() .IsNotNullOrEmpty(customer.Name, "FirstName", "First Name should have at least 3 chars"); } } public class UpdateCustomerSpecification : Contract { public UpdateCustomerSpecification(Customer customer) { Requires() .IsNotNullOrEmpty(customer.Name, "FirstName", "Custom error message") .IsNotNullOrEmpty(customer.Email, "Email", "Custom error message"); } } #endregion } ================================================ FILE: Flunt.Tests/DateTimeValidationTests.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class DateTimeValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("DateTime Validation")] [TestMethod("Requires a date is greater than")] public void RequiresDateIsGreaterThan() { var contract = new Contract() .Requires() .IsGreaterThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterThanNow, "DateTime") .IsGreaterThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterThanNow, "DateTime", "Custom message here") .IsGreaterThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerThanNow, "DateTime") .IsGreaterThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerThanNow, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is greater or equals than")] public void RequiresDateIsGreaterOrEqualsThan() { var contract = new Contract() .Requires() .IsGreaterOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterOrEqualsThanNow, "DateTime") .IsGreaterOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterOrEqualsThanNow, "DateTime", "Custom message here") .IsGreaterOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterThanNow, "DateTime") .IsGreaterOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterThanNow, "DateTime", "Custom message here") .IsGreaterOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerThanNow, "DateTime") .IsGreaterOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerThanNow, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is lower than")] public void RequiresDateIsLowerThan() { var contract = new Contract() .Requires() .IsLowerThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerThanNow, "DateTime") .IsLowerThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerThanNow, "DateTime", "Custom message here") .IsLowerThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterThanNow, "DateTime") .IsLowerThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterThanNow, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is lower or equals than")] public void RequiresDateIsLowerOrEqualsThan() { var contract = new Contract() .Requires() .IsLowerOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerOrEqualsThanNow, "DateTime") .IsLowerOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerOrEqualsThanNow, "DateTime", "Custom message here") .IsLowerOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerThanNow, "DateTime") .IsLowerOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeLowerThanNow, "DateTime", "Custom message here") .IsLowerOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterThanNow, "DateTime") .IsLowerOrEqualsThan(SampleEntity.DateTimeSnapshot, _entity.DateTimeGreaterThanNow, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is not null")] public void RequiresDateIsNotNull() { var contract = new Contract() .Requires() .IsNotNull(SampleEntity.DateTimeSnapshot, "DateTime") .IsNotNull(SampleEntity.DateTimeSnapshot, "DateTime", "Custom message here") .IsNotNull(_entity.DateTimeNull, "DateTime") .IsNotNull(_entity.DateTimeNull, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is null")] public void RequiresDateIsNull() { var contract = new Contract() .Requires() .IsNull(SampleEntity.DateTimeSnapshot, "DateTime") .IsNull(SampleEntity.DateTimeSnapshot, "DateTime", "Custom message here") .IsNull(_entity.DateTimeNull, "DateTime") .IsNull(_entity.DateTimeNull, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is between")] public void RequiresDateIsBetween() { var contract = new Contract() .Requires() .IsBetween(_entity.DateTimeBetweenStartAndEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") .IsBetween(_entity.DateTimeBetweenStartAndEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime", "Custom message here") // DateTime = StartDate will be consider between .IsBetween(_entity.DateTimeStartDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") // DateTime = EndDate will be consider between .IsBetween(_entity.DateTimeEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") .IsBetween(_entity.DateTimeNotBetweenStartAndEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") .IsBetween(_entity.DateTimeNotBetweenStartAndEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is not between")] public void RequiresDateIsNotBetween() { var contract = new Contract() .Requires() .IsNotBetween(_entity.DateTimeNotBetweenStartAndEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") .IsNotBetween(_entity.DateTimeNotBetweenStartAndEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime", "Custom message here") // DateTime = StartDate will be consider not between .IsBetween(_entity.DateTimeStartDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") // DateTime = EndDate will be consider not between .IsBetween(_entity.DateTimeEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") .IsNotBetween(_entity.DateTimeBetweenStartAndEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") .IsNotBetween(_entity.DateTimeBetweenStartAndEndDate, _entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is min value")] public void RequiresDateHaveMinValue() { var contract = new Contract() .Requires() .IsMinValue(DateTime.MaxValue, "DateTime") .IsMinValue(DateTime.MaxValue, "DateTime", "Custom message here") .IsMinValue(DateTime.MinValue, "DateTime") .IsMinValue(DateTime.MinValue, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is not min value")] public void RequiresDateDoNotHaveMinValue() { var contract = new Contract() .Requires() .IsNotMinValue(DateTime.MaxValue, "DateTime") .IsNotMinValue(DateTime.MaxValue, "DateTime", "Custom message here") .IsNotMinValue(DateTime.MinValue, "DateTime") .IsNotMinValue(DateTime.MinValue, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is max value")] public void RequiresDateHaveMaxValue() { var contract = new Contract() .Requires() .IsMaxValue(DateTime.MaxValue, "DateTime") .IsMaxValue(DateTime.MaxValue, "DateTime", "Custom message here") .IsMaxValue(DateTime.MinValue, "DateTime") .IsMaxValue(DateTime.MinValue, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a date is not max value")] public void RequiresDateDoNotHaveMaxValue() { var contract = new Contract() .Requires() .IsNotMaxValue(DateTime.MaxValue, "DateTime") .IsNotMaxValue(DateTime.MaxValue, "DateTime", "Custom message here") .IsNotMaxValue(DateTime.MinValue, "DateTime") .IsNotMaxValue(DateTime.MinValue, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires two dates are equals")] public void RequiresDatesAreEquals() { var contract = new Contract() .Requires() .AreEquals(_entity.DateTimeStartDate, _entity.DateTimeStartDate, "DateTime") .AreEquals(_entity.DateTimeStartDate, _entity.DateTimeStartDate, "DateTime", "Custom message here") .AreEquals(_entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") .AreEquals(_entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires two dates are not equals")] public void RequiresDatesAreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals(_entity.DateTimeStartDate, _entity.DateTimeStartDate, "DateTime") .AreNotEquals(_entity.DateTimeStartDate, _entity.DateTimeStartDate, "DateTime", "Custom message here") .AreNotEquals(_entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime") .AreNotEquals(_entity.DateTimeStartDate, _entity.DateTimeEndDate, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a list contains a date")] public void RequiresListContainsDate() { var contract = new Contract() .Requires() .Contains(SampleEntity.DateTimeSnapshot, _entity.DateTimeList, "DateTime") .Contains(SampleEntity.DateTimeSnapshot, _entity.DateTimeList, "DateTime", "Custom message here") .Contains(_entity.DateTimeEndDate, _entity.DateTimeList, "DateTime") .Contains(_entity.DateTimeEndDate, _entity.DateTimeList, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("DateTime Validation")] [TestMethod("Requires a list not contains a date")] public void RequiresListNotContainsDate() { var contract = new Contract() .Requires() .NotContains(SampleEntity.DateTimeSnapshot, _entity.DateTimeList, "DateTime") .NotContains(SampleEntity.DateTimeSnapshot, _entity.DateTimeList, "DateTime", "Custom message here") .NotContains(_entity.DateTimeEndDate, _entity.DateTimeList, "DateTime") .NotContains(_entity.DateTimeEndDate, _entity.DateTimeList, "DateTime", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } } } ================================================ FILE: Flunt.Tests/DecimalValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class DecimalValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal is greater than")] public void RequiresDecimalIsGreaterThan() { var contract = new Contract() .Requires() .IsGreaterThan((decimal)0, (int)10, "Decimal") .IsGreaterThan((decimal)0, (int)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)10, (int)10, "Decimal") .IsGreaterThan((decimal)10, (int)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)20, (int)10, "Decimal") .IsGreaterThan((decimal)20, (int)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)0, (float)10, "Decimal") .IsGreaterThan((decimal)0, (float)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)10, (float)10, "Decimal") .IsGreaterThan((decimal)10, (float)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)20, (float)10, "Decimal") .IsGreaterThan((decimal)20, (float)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)0, (double)10, "Decimal") .IsGreaterThan((decimal)0, (double)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)10, (double)10, "Decimal") .IsGreaterThan((decimal)10, (double)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)20, (double)10, "Decimal") .IsGreaterThan((decimal)20, (double)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)0, (long)10, "Decimal") .IsGreaterThan((decimal)0, (long)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)10, (long)10, "Decimal") .IsGreaterThan((decimal)10, (long)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)20, (long)10, "Decimal") .IsGreaterThan((decimal)20, (long)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)0, (decimal)10, "Decimal") .IsGreaterThan((decimal)0, (decimal)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)10, (decimal)10, "Decimal") .IsGreaterThan((decimal)10, (decimal)10, "Decimal", "Custom message here") .IsGreaterThan((decimal)20, (decimal)10, "Decimal") .IsGreaterThan((decimal)20, (decimal)10, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal is greater or equals than")] public void RequiresDecimalIsGreaterOrEqualsThan() { var contract = new Contract() .Requires() .IsGreaterOrEqualsThan((decimal)0, (int)10, "Decimal") .IsGreaterOrEqualsThan((decimal)0, (int)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)10, (int)10, "Decimal") .IsGreaterOrEqualsThan((decimal)10, (int)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)20, (int)10, "Decimal") .IsGreaterOrEqualsThan((decimal)20, (int)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)0, (float)10, "Decimal") .IsGreaterOrEqualsThan((decimal)0, (float)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)10, (float)10, "Decimal") .IsGreaterOrEqualsThan((decimal)10, (float)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)20, (float)10, "Decimal") .IsGreaterOrEqualsThan((decimal)20, (float)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)0, (double)10, "Decimal") .IsGreaterOrEqualsThan((decimal)0, (double)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)10, (double)10, "Decimal") .IsGreaterOrEqualsThan((decimal)10, (double)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)20, (double)10, "Decimal") .IsGreaterOrEqualsThan((decimal)20, (double)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)0, (long)10, "Decimal") .IsGreaterOrEqualsThan((decimal)0, (long)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)10, (long)10, "Decimal") .IsGreaterOrEqualsThan((decimal)10, (long)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)20, (long)10, "Decimal") .IsGreaterOrEqualsThan((decimal)20, (long)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)0, (decimal)10, "Decimal") .IsGreaterOrEqualsThan((decimal)0, (decimal)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)10, (decimal)10, "Decimal") .IsGreaterOrEqualsThan((decimal)10, (decimal)10, "Decimal", "Custom message here") .IsGreaterOrEqualsThan((decimal)20, (decimal)10, "Decimal") .IsGreaterOrEqualsThan((decimal)20, (decimal)10, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal is lower than")] public void RequiresDecimalIsLowerThan() { var contract = new Contract() .Requires() .IsLowerThan((decimal)0, (int)0, "Decimal") .IsLowerThan((decimal)0, (int)0, "Decimal", "Custom message here") .IsLowerThan((decimal)-5, (int)0, "Decimal") .IsLowerThan((decimal)-5, (int)0, "Decimal", "Custom message here") .IsLowerThan((decimal)5, (int)0, "Decimal") .IsLowerThan((decimal)5, (int)0, "Decimal", "Custom message here") .IsLowerThan((decimal)0, (float)0, "Decimal") .IsLowerThan((decimal)0, (float)0, "Decimal", "Custom message here") .IsLowerThan((decimal)-5, (float)0, "Decimal") .IsLowerThan((decimal)-5, (float)0, "Decimal", "Custom message here") .IsLowerThan((decimal)5, (float)0, "Decimal") .IsLowerThan((decimal)5, (float)0, "Decimal", "Custom message here") .IsLowerThan((decimal)0, (double)0, "Decimal") .IsLowerThan((decimal)0, (double)0, "Decimal", "Custom message here") .IsLowerThan((decimal)-5, (double)0, "Decimal") .IsLowerThan((decimal)-5, (double)0, "Decimal", "Custom message here") .IsLowerThan((decimal)5, (double)0, "Decimal") .IsLowerThan((decimal)5, (double)0, "Decimal", "Custom message here") .IsLowerThan((decimal)0, (long)0, "Decimal") .IsLowerThan((decimal)0, (long)0, "Decimal", "Custom message here") .IsLowerThan((decimal)-5, (long)0, "Decimal") .IsLowerThan((decimal)-5, (long)0, "Decimal", "Custom message here") .IsLowerThan((decimal)5, (long)0, "Decimal") .IsLowerThan((decimal)5, (long)0, "Decimal", "Custom message here") .IsLowerThan((decimal)0, (decimal)0, "Decimal") .IsLowerThan((decimal)0, (decimal)0, "Decimal", "Custom message here") .IsLowerThan((decimal)-5, (decimal)0, "Decimal") .IsLowerThan((decimal)-5, (decimal)0, "Decimal", "Custom message here") .IsLowerThan((decimal)5, (decimal)0, "Decimal") .IsLowerThan((decimal)5, (decimal)0, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal is lower or equals than")] public void RequiresDecimalIsLowerOrEqualsThan() { var contract = new Contract() .Requires() .IsLowerOrEqualsThan((decimal)0, (int)10, "Decimal") .IsLowerOrEqualsThan((decimal)0, (int)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)10, (int)10, "Decimal") .IsLowerOrEqualsThan((decimal)10, (int)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)20, (int)10, "Decimal") .IsLowerOrEqualsThan((decimal)20, (int)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)0, (float)10, "Decimal") .IsLowerOrEqualsThan((decimal)0, (float)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)10, (float)10, "Decimal") .IsLowerOrEqualsThan((decimal)10, (float)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)20, (float)10, "Decimal") .IsLowerOrEqualsThan((decimal)20, (float)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)0, (double)10, "Decimal") .IsLowerOrEqualsThan((decimal)0, (double)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)10, (double)10, "Decimal") .IsLowerOrEqualsThan((decimal)10, (double)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)20, (double)10, "Decimal") .IsLowerOrEqualsThan((decimal)20, (double)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)0, (long)10, "Decimal") .IsLowerOrEqualsThan((decimal)0, (long)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)10, (long)10, "Decimal") .IsLowerOrEqualsThan((decimal)10, (long)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)20, (long)10, "Decimal") .IsLowerOrEqualsThan((decimal)20, (long)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)0, (decimal)10, "Decimal") .IsLowerOrEqualsThan((decimal)0, (decimal)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)10, (decimal)10, "Decimal") .IsLowerOrEqualsThan((decimal)10, (decimal)10, "Decimal", "Custom message here") .IsLowerOrEqualsThan((decimal)20, (decimal)10, "Decimal") .IsLowerOrEqualsThan((decimal)20, (decimal)10, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal has its min value")] public void RequireDecimalHasItsMinValue() { var contract = new Contract() .Requires() .IsMinValue(decimal.MaxValue, "Decimal") .IsMinValue(decimal.MaxValue, "Decimal", "Custom message here") .IsMinValue(decimal.MinValue, "Decimal") .IsMinValue(decimal.MinValue, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal has not its min value")] public void RequireDecimalHasNotItsMinValue() { var contract = new Contract() .Requires() .IsNotMinValue(decimal.MaxValue, "Decimal") .IsNotMinValue(decimal.MaxValue, "Decimal", "Custom message here") .IsNotMinValue(decimal.MinValue, "Decimal") .IsNotMinValue(decimal.MinValue, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal has its max value")] public void RequireDecimalHasItsMaxValue() { var contract = new Contract() .Requires() .IsMaxValue(decimal.MaxValue, "Decimal") .IsMaxValue(decimal.MaxValue, "Decimal", "Custom message here") .IsMaxValue(decimal.MinValue, "Decimal") .IsMaxValue(decimal.MinValue, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal has not its max value")] public void RequireDecimalHasNotItsMaxValue() { var contract = new Contract() .Requires() .IsNotMaxValue(decimal.MaxValue, "Decimal") .IsNotMaxValue(decimal.MaxValue, "Decimal", "Custom message here") .IsNotMaxValue(decimal.MinValue, "Decimal") .IsNotMaxValue(decimal.MinValue, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Decimal Validation")] [TestMethod("Requires two decimals are equals")] public void RequireTwoDecimalsAreEquals() { var contract = new Contract() .Requires() .AreEquals((decimal)0, (int)0, "Decimal") .AreEquals((decimal)0, (int)0, "Decimal", "Custom message here") .AreEquals((decimal)0, (int)10, "Decimal") .AreEquals((decimal)0, (int)10, "Decimal", "Custom message here") .AreEquals((decimal)0, (float)0, "Decimal") .AreEquals((decimal)0, (float)0, "Decimal", "Custom message here") .AreEquals((decimal)0, (float)10, "Decimal") .AreEquals((decimal)0, (float)10, "Decimal", "Custom message here") .AreEquals((decimal)0, (double)0, "Decimal") .AreEquals((decimal)0, (double)0, "Decimal", "Custom message here") .AreEquals((decimal)0, (double)10, "Decimal") .AreEquals((decimal)0, (double)10, "Decimal", "Custom message here") .AreEquals((decimal)0, (long)0, "Decimal") .AreEquals((decimal)0, (long)0, "Decimal", "Custom message here") .AreEquals((decimal)0, (long)10, "Decimal") .AreEquals((decimal)0, (long)10, "Decimal", "Custom message here") .AreEquals((decimal)0, (decimal)0, "Decimal") .AreEquals((decimal)0, (decimal)0, "Decimal", "Custom message here") .AreEquals((decimal)0, (decimal)10, "Decimal") .AreEquals((decimal)0, (decimal)10, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Decimal Validation")] [TestMethod("Requires two decimals are not equals")] public void RequireTwoDecimalsAreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals((decimal)0, (int)0, "Decimal") .AreNotEquals((decimal)0, (int)0, "Decimal", "Custom message here") .AreNotEquals((decimal)0, (int)10, "Decimal") .AreNotEquals((decimal)0, (int)10, "Decimal", "Custom message here") .AreNotEquals((decimal)0, (float)0, "Decimal") .AreNotEquals((decimal)0, (float)0, "Decimal", "Custom message here") .AreNotEquals((decimal)0, (float)10, "Decimal") .AreNotEquals((decimal)0, (float)10, "Decimal", "Custom message here") .AreNotEquals((decimal)0, (double)0, "Decimal") .AreNotEquals((decimal)0, (double)0, "Decimal", "Custom message here") .AreNotEquals((decimal)0, (double)10, "Decimal") .AreNotEquals((decimal)0, (double)10, "Decimal", "Custom message here") .AreNotEquals((decimal)0, (long)0, "Decimal") .AreNotEquals((decimal)0, (long)0, "Decimal", "Custom message here") .AreNotEquals((decimal)0, (long)10, "Decimal") .AreNotEquals((decimal)0, (long)10, "Decimal", "Custom message here") .AreNotEquals((decimal)0, (decimal)0, "Decimal") .AreNotEquals((decimal)0, (decimal)0, "Decimal", "Custom message here") .AreNotEquals((decimal)0, (decimal)10, "Decimal") .AreNotEquals((decimal)0, (decimal)10, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal is null")] public void RequiresDecimalIsNull() { var contract = new Contract() .Requires() .IsNull(_entity.DecimalNull, "Decimal") .IsNull(_entity.DecimalNull, "Decimal", "Custom message here") .IsNull(_entity.DecimalStart, "Decimal") .IsNull(_entity.DecimalStart, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal is not null")] public void RequiresDecimalIsNotNull() { var contract = new Contract() .Requires() .IsNotNull(_entity.DecimalNull, "Decimal") .IsNotNull(_entity.DecimalNull, "Decimal", "Custom message here") .IsNotNull(_entity.DecimalStart, "Decimal") .IsNotNull(_entity.DecimalStart, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal is between")] public void RequiresDecimalIsBetween() { var contract = new Contract() .Requires() .IsBetween(_entity.DecimalBetweenStartAndEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalBetweenStartAndEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalStart, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalStart, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalBetweenStartAndEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalBetweenStartAndEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalStart, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalStart, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalBetweenStartAndEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalBetweenStartAndEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalStart, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalStart, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalBetweenStartAndEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalBetweenStartAndEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalStart, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalStart, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalBetweenStartAndEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalBetweenStartAndEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalStart, _entity.DecimalStart, _entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalStart, _entity.DecimalStart, _entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal", "Custom message here") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal") .IsBetween(_entity.DecimalNotBetweenStartAndEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Decimal Validation")] [TestMethod("Requires a decimal is not between")] public void RequiresDecimalIsNotBetween() { var contract = new Contract() .Requires() .IsNotBetween(_entity.DecimalBetweenStartAndEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalBetweenStartAndEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalStart, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalStart, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, (int)_entity.DecimalStart, (int)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalBetweenStartAndEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalBetweenStartAndEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalStart, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalStart, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, (double)_entity.DecimalStart, (double)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalBetweenStartAndEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalBetweenStartAndEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalStart, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalStart, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, (float)_entity.DecimalStart, (float)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalBetweenStartAndEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalBetweenStartAndEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalStart, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalStart, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, (long)_entity.DecimalStart, (long)_entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalBetweenStartAndEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalBetweenStartAndEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalStart, _entity.DecimalStart, _entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalStart, _entity.DecimalStart, _entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal", "Custom message here") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal") .IsNotBetween(_entity.DecimalNotBetweenStartAndEnd, _entity.DecimalStart, _entity.DecimalEnd, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 30); } [TestCategory("Decimal Validation")] [TestMethod("Requires a list contains a decimal")] public void RequiresListContainsDecimal() { var contract = new Contract() .Requires() .Contains((decimal)1, _entity.DecimalList, "Decimal") .Contains((decimal)1, _entity.DecimalList, "Decimal", "Custom message here") .Contains((decimal)3, _entity.DecimalList, "Decimal") .Contains((decimal)3, _entity.DecimalList, "Decimal", "Custom message here") .Contains((decimal)5, _entity.DecimalList, "Decimal") .Contains((decimal)5, _entity.DecimalList, "Decimal", "Custom message here") .Contains((decimal)7, _entity.DecimalList, "Decimal") .Contains((decimal)7, _entity.DecimalList, "Decimal", "Custom message here") .Contains((decimal)9, _entity.DecimalList, "Decimal") .Contains((decimal)9, _entity.DecimalList, "Decimal", "Custom message here") .Contains((decimal)11, _entity.DecimalList, "Decimal") .Contains((decimal)11, _entity.DecimalList, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Decimal Validation")] [TestMethod("Requires a list does not contains a decimal")] public void RequiresListNotContainsDecimal() { var contract = new Contract() .Requires() .NotContains((decimal)1, _entity.DecimalList, "Decimal") .NotContains((decimal)1, _entity.DecimalList, "Decimal", "Custom message here") .NotContains((decimal)3, _entity.DecimalList, "Decimal") .NotContains((decimal)3, _entity.DecimalList, "Decimal", "Custom message here") .NotContains((decimal)5, _entity.DecimalList, "Decimal") .NotContains((decimal)5, _entity.DecimalList, "Decimal", "Custom message here") .NotContains((decimal)7, _entity.DecimalList, "Decimal") .NotContains((decimal)7, _entity.DecimalList, "Decimal", "Custom message here") .NotContains((decimal)9, _entity.DecimalList, "Decimal") .NotContains((decimal)9, _entity.DecimalList, "Decimal", "Custom message here") .NotContains((decimal)11, _entity.DecimalList, "Decimal") .NotContains((decimal)11, _entity.DecimalList, "Decimal", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } } } ================================================ FILE: Flunt.Tests/DocumentValidationTests.cs ================================================ using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class DocumentValidationTests { [TestCategory("Document Validation")] [TestMethod("Requires a string is a passport number")] public void IsPassport() { var contract = new Contract() .Requires() // INVALID .IsPassport(null, "TEST 01") .IsPassport(null, "TEST 02", "Custom error message") // INVALID .IsPassport(string.Empty, "TEST 03") .IsPassport(string.Empty, "TEST 04", "Custom error message") // INVALID .IsPassport(" ", "TEST 05") .IsPassport(" ", "TEST 06", "Custom error message") // VALID .IsPassport("ABCDE", "TEST 07") .IsPassport("ABCDE", "TEST 08", "Custom error message") // VALID .IsPassport("1340", "TEST 09") .IsPassport("1340", "TEST 10", "Custom error message") // INVALID .IsPassport("587.461.400-18", "TEST 11") .IsPassport("587.461.400-18", "TEST 12", "Custom error message") // INVALID .IsPassport("774 451 480 78", "TEST 13") .IsPassport("774 451 480 78", "TEST 14", "Custom error message") // VALID .IsPassport("48042595034", "TEST 15") .IsPassport("48042595034", "TEST 16", "Custom error message") // VALID .IsPassport("48042595035", "TEST 15") .IsPassport("48042595035", "TEST 16", "Custom error message") // VALID .IsPassport("35245678901", "TEST 15") .IsPassport("35245678901", "TEST 16", "Custom error message") // INVALID .IsPassport("3524567890135245678901", "TEST 15") .IsPassport("3524567890135245678901", "TEST 16", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 12); } } } ================================================ FILE: Flunt.Tests/DoubleValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class DoubleValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("Double Validation")] [TestMethod("Requires a double is greater than")] public void RequiresDoubleIsGreaterThan() { var contract = new Contract() .Requires() .IsGreaterThan((double)0, (int)10, "Double") .IsGreaterThan((double)0, (int)10, "Double", "Custom message here") .IsGreaterThan((double)10, (int)10, "Double") .IsGreaterThan((double)10, (int)10, "Double", "Custom message here") .IsGreaterThan((double)20, (int)10, "Double") .IsGreaterThan((double)20, (int)10, "Double", "Custom message here") .IsGreaterThan((double)0, (float)10, "Double") .IsGreaterThan((double)0, (float)10, "Double", "Custom message here") .IsGreaterThan((double)10, (float)10, "Double") .IsGreaterThan((double)10, (float)10, "Double", "Custom message here") .IsGreaterThan((double)20, (float)10, "Double") .IsGreaterThan((double)20, (float)10, "Double", "Custom message here") .IsGreaterThan((double)0, (double)10, "Double") .IsGreaterThan((double)0, (double)10, "Double", "Custom message here") .IsGreaterThan((double)10, (double)10, "Double") .IsGreaterThan((double)10, (double)10, "Double", "Custom message here") .IsGreaterThan((double)20, (double)10, "Double") .IsGreaterThan((double)20, (double)10, "Double", "Custom message here") .IsGreaterThan((double)0, (long)10, "Double") .IsGreaterThan((double)0, (long)10, "Double", "Custom message here") .IsGreaterThan((double)10, (long)10, "Double") .IsGreaterThan((double)10, (long)10, "Double", "Custom message here") .IsGreaterThan((double)20, (long)10, "Double") .IsGreaterThan((double)20, (long)10, "Double", "Custom message here") .IsGreaterThan((double)0, (decimal)10, "Double") .IsGreaterThan((double)0, (decimal)10, "Double", "Custom message here") .IsGreaterThan((double)10, (decimal)10, "Double") .IsGreaterThan((double)10, (decimal)10, "Double", "Custom message here") .IsGreaterThan((double)20, (decimal)10, "Double") .IsGreaterThan((double)20, (decimal)10, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Double Validation")] [TestMethod("Requires a double is greater or equals than")] public void RequiresDoubleIsGreaterOrEqualsThan() { var contract = new Contract() .Requires() .IsGreaterOrEqualsThan((double)0, (int)10, "Double") .IsGreaterOrEqualsThan((double)0, (int)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)10, (int)10, "Double") .IsGreaterOrEqualsThan((double)10, (int)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)20, (int)10, "Double") .IsGreaterOrEqualsThan((double)20, (int)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)0, (float)10, "Double") .IsGreaterOrEqualsThan((double)0, (float)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)10, (float)10, "Double") .IsGreaterOrEqualsThan((double)10, (float)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)20, (float)10, "Double") .IsGreaterOrEqualsThan((double)20, (float)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)0, (double)10, "Double") .IsGreaterOrEqualsThan((double)0, (double)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)10, (double)10, "Double") .IsGreaterOrEqualsThan((double)10, (double)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)20, (double)10, "Double") .IsGreaterOrEqualsThan((double)20, (double)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)0, (long)10, "Double") .IsGreaterOrEqualsThan((double)0, (long)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)10, (long)10, "Double") .IsGreaterOrEqualsThan((double)10, (long)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)20, (long)10, "Double") .IsGreaterOrEqualsThan((double)20, (long)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)0, (decimal)10, "Double") .IsGreaterOrEqualsThan((double)0, (decimal)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)10, (decimal)10, "Double") .IsGreaterOrEqualsThan((double)10, (decimal)10, "Double", "Custom message here") .IsGreaterOrEqualsThan((double)20, (decimal)10, "Double") .IsGreaterOrEqualsThan((double)20, (decimal)10, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Double Validation")] [TestMethod("Requires a double is lower than")] public void RequiresDoubleIsLowerThan() { var contract = new Contract() .Requires() .IsLowerThan((double)0, (int)0, "Double") .IsLowerThan((double)0, (int)0, "Double", "Custom message here") .IsLowerThan((double)-5, (int)0, "Double") .IsLowerThan((double)-5, (int)0, "Double", "Custom message here") .IsLowerThan((double)5, (int)0, "Double") .IsLowerThan((double)5, (int)0, "Double", "Custom message here") .IsLowerThan((double)0, (float)0, "Double") .IsLowerThan((double)0, (float)0, "Double", "Custom message here") .IsLowerThan((double)-5, (float)0, "Double") .IsLowerThan((double)-5, (float)0, "Double", "Custom message here") .IsLowerThan((double)5, (float)0, "Double") .IsLowerThan((double)5, (float)0, "Double", "Custom message here") .IsLowerThan((double)0, (double)0, "Double") .IsLowerThan((double)0, (double)0, "Double", "Custom message here") .IsLowerThan((double)-5, (double)0, "Double") .IsLowerThan((double)-5, (double)0, "Double", "Custom message here") .IsLowerThan((double)5, (double)0, "Double") .IsLowerThan((double)5, (double)0, "Double", "Custom message here") .IsLowerThan((double)0, (long)0, "Double") .IsLowerThan((double)0, (long)0, "Double", "Custom message here") .IsLowerThan((double)-5, (long)0, "Double") .IsLowerThan((double)-5, (long)0, "Double", "Custom message here") .IsLowerThan((double)5, (long)0, "Double") .IsLowerThan((double)5, (long)0, "Double", "Custom message here") .IsLowerThan((double)0, (decimal)0, "Double") .IsLowerThan((double)0, (decimal)0, "Double", "Custom message here") .IsLowerThan((double)-5, (decimal)0, "Double") .IsLowerThan((double)-5, (decimal)0, "Double", "Custom message here") .IsLowerThan((double)5, (decimal)0, "Double") .IsLowerThan((double)5, (decimal)0, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Double Validation")] [TestMethod("Requires a double is lower or equals than")] public void RequiresDoubleIsLowerOrEqualsThan() { var contract = new Contract() .Requires() .IsLowerOrEqualsThan((double)0, (int)10, "Double") .IsLowerOrEqualsThan((double)0, (int)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)10, (int)10, "Double") .IsLowerOrEqualsThan((double)10, (int)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)20, (int)10, "Double") .IsLowerOrEqualsThan((double)20, (int)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)0, (float)10, "Double") .IsLowerOrEqualsThan((double)0, (float)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)10, (float)10, "Double") .IsLowerOrEqualsThan((double)10, (float)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)20, (float)10, "Double") .IsLowerOrEqualsThan((double)20, (float)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)0, (double)10, "Double") .IsLowerOrEqualsThan((double)0, (double)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)10, (double)10, "Double") .IsLowerOrEqualsThan((double)10, (double)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)20, (double)10, "Double") .IsLowerOrEqualsThan((double)20, (double)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)0, (long)10, "Double") .IsLowerOrEqualsThan((double)0, (long)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)10, (long)10, "Double") .IsLowerOrEqualsThan((double)10, (long)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)20, (long)10, "Double") .IsLowerOrEqualsThan((double)20, (long)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)0, (decimal)10, "Double") .IsLowerOrEqualsThan((double)0, (decimal)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)10, (decimal)10, "Double") .IsLowerOrEqualsThan((double)10, (decimal)10, "Double", "Custom message here") .IsLowerOrEqualsThan((double)20, (decimal)10, "Double") .IsLowerOrEqualsThan((double)20, (decimal)10, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Double Validation")] [TestMethod("Requires a double has its min value")] public void RequireDoubleHasItsMinValue() { var contract = new Contract() .Requires() .IsMinValue(double.MaxValue, "Double") .IsMinValue(double.MaxValue, "Double", "Custom message here") .IsMinValue(double.MinValue, "Double") .IsMinValue(double.MinValue, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Double Validation")] [TestMethod("Requires a double has not its min value")] public void RequireDoubleHasNotItsMinValue() { var contract = new Contract() .Requires() .IsNotMinValue(double.MaxValue, "Double") .IsNotMinValue(double.MaxValue, "Double", "Custom message here") .IsNotMinValue(double.MinValue, "Double") .IsNotMinValue(double.MinValue, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Double Validation")] [TestMethod("Requires a double has its max value")] public void RequireDoubleHasItsMaxValue() { var contract = new Contract() .Requires() .IsMaxValue(double.MaxValue, "Double") .IsMaxValue(double.MaxValue, "Double", "Custom message here") .IsMaxValue(double.MinValue, "Double") .IsMaxValue(double.MinValue, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Double Validation")] [TestMethod("Requires a double has not its max value")] public void RequireDoubleHasNotItsMaxValue() { var contract = new Contract() .Requires() .IsNotMaxValue(double.MaxValue, "Double") .IsNotMaxValue(double.MaxValue, "Double", "Custom message here") .IsNotMaxValue(double.MinValue, "Double") .IsNotMaxValue(double.MinValue, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Double Validation")] [TestMethod("Requires two doubles are equals")] public void RequireTwoDoublesAreEquals() { var contract = new Contract() .Requires() .AreEquals((double)0, (int)0, "Double") .AreEquals((double)0, (int)0, "Double", "Custom message here") .AreEquals((double)0, (int)10, "Double") .AreEquals((double)0, (int)10, "Double", "Custom message here") .AreEquals((double)0, (float)0, "Double") .AreEquals((double)0, (float)0, "Double", "Custom message here") .AreEquals((double)0, (float)10, "Double") .AreEquals((double)0, (float)10, "Double", "Custom message here") .AreEquals((double)0, (double)0, "Double") .AreEquals((double)0, (double)0, "Double", "Custom message here") .AreEquals((double)0, (double)10, "Double") .AreEquals((double)0, (double)10, "Double", "Custom message here") .AreEquals((double)0, (long)0, "Double") .AreEquals((double)0, (long)0, "Double", "Custom message here") .AreEquals((double)0, (long)10, "Double") .AreEquals((double)0, (long)10, "Double", "Custom message here") .AreEquals((double)0, (decimal)0, "Double") .AreEquals((double)0, (decimal)0, "Double", "Custom message here") .AreEquals((double)0, (decimal)10, "Double") .AreEquals((double)0, (decimal)10, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Double Validation")] [TestMethod("Requires two doubles are not equals")] public void RequireTwoDoublesAreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals((double)0, (int)0, "Double") .AreNotEquals((double)0, (int)0, "Double", "Custom message here") .AreNotEquals((double)0, (int)10, "Double") .AreNotEquals((double)0, (int)10, "Double", "Custom message here") .AreNotEquals((double)0, (float)0, "Double") .AreNotEquals((double)0, (float)0, "Double", "Custom message here") .AreNotEquals((double)0, (float)10, "Double") .AreNotEquals((double)0, (float)10, "Double", "Custom message here") .AreNotEquals((double)0, (double)0, "Double") .AreNotEquals((double)0, (double)0, "Double", "Custom message here") .AreNotEquals((double)0, (double)10, "Double") .AreNotEquals((double)0, (double)10, "Double", "Custom message here") .AreNotEquals((double)0, (long)0, "Double") .AreNotEquals((double)0, (long)0, "Double", "Custom message here") .AreNotEquals((double)0, (long)10, "Double") .AreNotEquals((double)0, (long)10, "Double", "Custom message here") .AreNotEquals((double)0, (decimal)0, "Double") .AreNotEquals((double)0, (decimal)0, "Double", "Custom message here") .AreNotEquals((double)0, (decimal)10, "Double") .AreNotEquals((double)0, (decimal)10, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Double Validation")] [TestMethod("Requires a double is null")] public void RequiresDoubleIsNull() { var contract = new Contract() .Requires() .IsNull(_entity.DoubleNull, "Double") .IsNull(_entity.DoubleNull, "Double", "Custom message here") .IsNull(_entity.DoubleStart, "Double") .IsNull(_entity.DoubleStart, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Double Validation")] [TestMethod("Requires a double is not null")] public void RequiresDoubleIsNotNull() { var contract = new Contract() .Requires() .IsNotNull(_entity.DoubleNull, "Double") .IsNotNull(_entity.DoubleNull, "Double", "Custom message here") .IsNotNull(_entity.DoubleStart, "Double") .IsNotNull(_entity.DoubleStart, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Double Validation")] [TestMethod("Requires a double is between")] public void RequiresDoubleIsBetween() { var contract = new Contract() .Requires() .IsBetween(_entity.DoubleBetweenStartAndEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleBetweenStartAndEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleStart, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleStart, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleBetweenStartAndEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleBetweenStartAndEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleStart, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleStart, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleBetweenStartAndEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleBetweenStartAndEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleStart, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleStart, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleBetweenStartAndEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleBetweenStartAndEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleStart, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleStart, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleBetweenStartAndEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleBetweenStartAndEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleStart, _entity.DoubleStart, _entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleStart, _entity.DoubleStart, _entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double", "Custom message here") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double") .IsBetween(_entity.DoubleNotBetweenStartAndEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Double Validation")] [TestMethod("Requires a double is not between")] public void RequiresDoubleIsNotBetween() { var contract = new Contract() .Requires() .IsNotBetween(_entity.DoubleBetweenStartAndEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleBetweenStartAndEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleStart, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleStart, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, (int)_entity.DoubleStart, (int)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleBetweenStartAndEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleBetweenStartAndEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleStart, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleStart, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, (double)_entity.DoubleStart, (double)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleBetweenStartAndEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleBetweenStartAndEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleStart, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleStart, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, (float)_entity.DoubleStart, (float)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleBetweenStartAndEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleBetweenStartAndEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleStart, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleStart, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, (long)_entity.DoubleStart, (long)_entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleBetweenStartAndEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleBetweenStartAndEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleStart, _entity.DoubleStart, _entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleStart, _entity.DoubleStart, _entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double", "Custom message here") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double") .IsNotBetween(_entity.DoubleNotBetweenStartAndEnd, _entity.DoubleStart, _entity.DoubleEnd, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 30); } [TestCategory("Double Validation")] [TestMethod("Requires a list contains a double")] public void RequiresListContainsDouble() { var contract = new Contract() .Requires() .Contains((double)1, _entity.DoubleList, "Double") .Contains((double)1, _entity.DoubleList, "Double", "Custom message here") .Contains((double)3, _entity.DoubleList, "Double") .Contains((double)3, _entity.DoubleList, "Double", "Custom message here") .Contains((double)5, _entity.DoubleList, "Double") .Contains((double)5, _entity.DoubleList, "Double", "Custom message here") .Contains((double)7, _entity.DoubleList, "Double") .Contains((double)7, _entity.DoubleList, "Double", "Custom message here") .Contains((double)9, _entity.DoubleList, "Double") .Contains((double)9, _entity.DoubleList, "Double", "Custom message here") .Contains((double)11, _entity.DoubleList, "Double") .Contains((double)11, _entity.DoubleList, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Double Validation")] [TestMethod("Requires a list does not contains a double")] public void RequiresListNotContainsDouble() { var contract = new Contract() .Requires() .NotContains((double)1, _entity.DoubleList, "Double") .NotContains((double)1, _entity.DoubleList, "Double", "Custom message here") .NotContains((double)3, _entity.DoubleList, "Double") .NotContains((double)3, _entity.DoubleList, "Double", "Custom message here") .NotContains((double)5, _entity.DoubleList, "Double") .NotContains((double)5, _entity.DoubleList, "Double", "Custom message here") .NotContains((double)7, _entity.DoubleList, "Double") .NotContains((double)7, _entity.DoubleList, "Double", "Custom message here") .NotContains((double)9, _entity.DoubleList, "Double") .NotContains((double)9, _entity.DoubleList, "Double", "Custom message here") .NotContains((double)11, _entity.DoubleList, "Double") .NotContains((double)11, _entity.DoubleList, "Double", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } } } ================================================ FILE: Flunt.Tests/EmailValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class EmailValidationTests { [TestCategory("Email Validation")] [TestMethod("Requires a string is an email")] public void IsEmail() { var contract = new Contract() .Requires() // Invalid .IsEmail("some string", "Email") .IsEmail("some@invalid", "Email", "Custom error message") .IsEmail("some string", "Email") .IsEmail("someinvalid.com", "Email", "Custom error message") // Valid .IsEmail("some@gmail.com", "Email") .IsEmail("some@hotmail.com", "Email", "Custom error message") .IsEmail("some@customdomain.com", "Email") .IsEmail("some@mydomain.com.br", "Email", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 4); } [TestCategory("Email Validation")] [TestMethod("Requires a string is an email or empty")] public void IsEmailOrEmpty() { var contract = new Contract() .Requires() // Invalid .IsEmailOrEmpty("some string", "Email") .IsEmailOrEmpty("some@invalid", "Email", "Custom error message") .IsEmailOrEmpty("some string", "Email") .IsEmailOrEmpty("someinvalid.com", "Email", "Custom error message") .IsEmailOrEmpty(" ", "Email") .IsEmailOrEmpty(" ", "Email", "Custom error message") // Valid .IsEmailOrEmpty("", "Email") .IsEmailOrEmpty("", "Email", "Custom error message") .IsEmailOrEmpty(null, "Email") .IsEmailOrEmpty(null, "Email", "Custom error message") .IsEmailOrEmpty("some@gmail.com", "Email") .IsEmailOrEmpty("some@hotmail.com", "Email", "Custom error message") .IsEmailOrEmpty("some@customdomain.com", "Email") .IsEmailOrEmpty("some@mydomain.com.br", "Email", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 6); } [TestCategory("Email Validation")] [TestMethod("Requires a string is not an email")] public void IsNotEmail() { var contract = new Contract() .Requires() // Valid .IsNotEmail("some string", "Email") .IsNotEmail("some@invalid", "Email", "Custom error message") .IsNotEmail("some string", "Email") .IsNotEmail("someinvalid.com", "Email", "Custom error message") // Invalid .IsNotEmail("some@gmail.com", "Email") .IsNotEmail("some@hotmail.com", "Email", "Custom error message") .IsNotEmail("some@customdomain.com", "Email") .IsNotEmail("some@mydomain.com.br", "Email", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 4); } } } ================================================ FILE: Flunt.Tests/Entities/SampleEntity.cs ================================================ using System; using System.Collections.Generic; using Flunt.Tests.Enums; namespace Flunt.Tests.Entities { public class SampleEntity { public bool BoolFalseProperty = false; public bool BoolTrueProperty = true; public bool? BoolNullProperty = null; public static DateTime DateTimeSnapshot = DateTime.Now; public DateTime DateTimeStartDate = DateTimeSnapshot.AddHours(-1); public DateTime DateTimeEndDate = DateTimeSnapshot.AddHours(+1); public DateTime DateTimeGreaterThanNow = DateTimeSnapshot.AddHours(1); public DateTime DateTimeGreaterOrEqualsThanNow = DateTimeSnapshot; public DateTime DateTimeLowerThanNow = DateTimeSnapshot.AddHours(-1); public DateTime DateTimeLowerOrEqualsThanNow = DateTimeSnapshot; public DateTime? DateTimeNull = null; public DateTime DateTimeBetweenStartAndEndDate = DateTimeSnapshot; public DateTime DateTimeNotBetweenStartAndEndDate = DateTimeSnapshot.AddHours(+5); public List DateTimeList = new List { DateTimeSnapshot }; public static TimeSpan TimeSpanSnapshot = DateTime.Now.TimeOfDay; public TimeSpan TimeSpanStartDate = TimeSpanSnapshot.Add(new TimeSpan(0, -1, 0, 0)); public TimeSpan TimeSpanEndDate = TimeSpanSnapshot.Add(new TimeSpan(0, 1, 0, 0)); public TimeSpan TimeSpanGreaterThanNow = TimeSpanSnapshot.Add(new TimeSpan(0, 1, 0, 0)); public TimeSpan TimeSpanGreaterOrEqualsThanNow = TimeSpanSnapshot; public TimeSpan TimeSpanLowerThanNow = TimeSpanSnapshot.Add(new TimeSpan(0, -1, 0, 0)); public TimeSpan TimeSpanLowerOrEqualsThanNow = TimeSpanSnapshot; public TimeSpan? TimeSpanNull = null; public TimeSpan TimeSpanBetweenStartAndEndDate = TimeSpanSnapshot; public TimeSpan TimeSpanNotBetweenStartAndEndDate = TimeSpanSnapshot.Add(new TimeSpan(0, 5, 0, 0)); public List TimeSpanList = new List { TimeSpanSnapshot }; public int IntStart = 0; public int IntEnd = 100; public int? IntNull = null; public int IntBetweenStartAndEnd = 5; public int IntNotBetweenStartAndEnd = -50; public List IntList = new List { 1, 3, 5, 7, 9 }; public long LongStart = 0; public long LongEnd = 100; public long? LongNull = null; public long LongBetweenStartAndEnd = 5; public long LongNotBetweenStartAndEnd = -50; public List LongList = new List { 1, 3, 5, 7, 9 }; public double DoubleStart = 0; public double DoubleEnd = 100; public double? DoubleNull = null; public double DoubleBetweenStartAndEnd = 5; public double DoubleNotBetweenStartAndEnd = -50; public List DoubleList = new List { 1, 3, 5, 7, 9 }; public float FloatStart = 0; public float FloatEnd = 100; public float? FloatNull = null; public float FloatBetweenStartAndEnd = 5; public float FloatNotBetweenStartAndEnd = -50; public List FloatList = new List { 1, 3, 5, 7, 9 }; public decimal DecimalStart = 0; public decimal DecimalEnd = 100; public decimal? DecimalNull = null; public decimal DecimalBetweenStartAndEnd = 5; public decimal DecimalNotBetweenStartAndEnd = -50; public List DecimalList = new List { 1, 3, 5, 7, 9 }; public Guid GuidEmpty = Guid.Empty; public Guid GuidNotEmpty = new Guid("f4ac2eab-8de5-430a-85b1-f0daa71df176"); public IList ListNull = null; public IList ListNotNull = new List { "Some item" }; public IList ListEmpty = new List(); public IList ListNotEmpty = new List { "Some item", "other item", "last item" }; public SampleEnum Enum = SampleEnum.Value; public SampleObject ObjectNull = null; public SampleObject ObjectToCompare = new SampleObject(1); public SampleObject ObjectAnotherToCompare = new SampleObject(1); public string StringNull = null; public string StringEmpty = string.Empty; public string StringNotEmpty = "some string"; public string StringWhiteSpace = " "; public string StringFiveCharsLong = "A2D3R"; public string StringNumbersOnly = "123456"; public string StringSpecialCharsOnly = "@#$%$#$$"; } public class SampleObject : IEquatable { public SampleObject(int id) { Id = id; } public int Id { get; set; } public bool Equals(SampleObject other) => Id == other?.Id; } } ================================================ FILE: Flunt.Tests/Enums/SampleEnum.cs ================================================ namespace Flunt.Tests.Enums { public enum SampleEnum { Value = 1, Other = 2, Sample = 3, OneMoreSample = 4 } } ================================================ FILE: Flunt.Tests/FloatValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class FloatValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("Float Validation")] [TestMethod("Requires a float is greater than")] public void RequiresFloatIsGreaterThan() { var contract = new Contract() .Requires() .IsGreaterThan((float)0, (int)10, "Float") .IsGreaterThan((float)0, (int)10, "Float", "Custom message here") .IsGreaterThan((float)10, (int)10, "Float") .IsGreaterThan((float)10, (int)10, "Float", "Custom message here") .IsGreaterThan((float)20, (int)10, "Float") .IsGreaterThan((float)20, (int)10, "Float", "Custom message here") .IsGreaterThan((float)0, (float)10, "Float") .IsGreaterThan((float)0, (float)10, "Float", "Custom message here") .IsGreaterThan((float)10, (float)10, "Float") .IsGreaterThan((float)10, (float)10, "Float", "Custom message here") .IsGreaterThan((float)20, (float)10, "Float") .IsGreaterThan((float)20, (float)10, "Float", "Custom message here") .IsGreaterThan((float)0, (double)10, "Float") .IsGreaterThan((float)0, (double)10, "Float", "Custom message here") .IsGreaterThan((float)10, (double)10, "Float") .IsGreaterThan((float)10, (double)10, "Float", "Custom message here") .IsGreaterThan((float)20, (double)10, "Float") .IsGreaterThan((float)20, (double)10, "Float", "Custom message here") .IsGreaterThan((float)0, (long)10, "Float") .IsGreaterThan((float)0, (long)10, "Float", "Custom message here") .IsGreaterThan((float)10, (long)10, "Float") .IsGreaterThan((float)10, (long)10, "Float", "Custom message here") .IsGreaterThan((float)20, (long)10, "Float") .IsGreaterThan((float)20, (long)10, "Float", "Custom message here") .IsGreaterThan((float)0, (decimal)10, "Float") .IsGreaterThan((float)0, (decimal)10, "Float", "Custom message here") .IsGreaterThan((float)10, (decimal)10, "Float") .IsGreaterThan((float)10, (decimal)10, "Float", "Custom message here") .IsGreaterThan((float)20, (decimal)10, "Float") .IsGreaterThan((float)20, (decimal)10, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Float Validation")] [TestMethod("Requires a float is greater or equals than")] public void RequiresFloatIsGreaterOrEqualsThan() { var contract = new Contract() .Requires() .IsGreaterOrEqualsThan((float)0, (int)10, "Float") .IsGreaterOrEqualsThan((float)0, (int)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)10, (int)10, "Float") .IsGreaterOrEqualsThan((float)10, (int)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)20, (int)10, "Float") .IsGreaterOrEqualsThan((float)20, (int)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)0, (float)10, "Float") .IsGreaterOrEqualsThan((float)0, (float)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)10, (float)10, "Float") .IsGreaterOrEqualsThan((float)10, (float)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)20, (float)10, "Float") .IsGreaterOrEqualsThan((float)20, (float)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)0, (double)10, "Float") .IsGreaterOrEqualsThan((float)0, (double)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)10, (double)10, "Float") .IsGreaterOrEqualsThan((float)10, (double)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)20, (double)10, "Float") .IsGreaterOrEqualsThan((float)20, (double)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)0, (long)10, "Float") .IsGreaterOrEqualsThan((float)0, (long)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)10, (long)10, "Float") .IsGreaterOrEqualsThan((float)10, (long)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)20, (long)10, "Float") .IsGreaterOrEqualsThan((float)20, (long)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)0, (decimal)10, "Float") .IsGreaterOrEqualsThan((float)0, (decimal)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)10, (decimal)10, "Float") .IsGreaterOrEqualsThan((float)10, (decimal)10, "Float", "Custom message here") .IsGreaterOrEqualsThan((float)20, (decimal)10, "Float") .IsGreaterOrEqualsThan((float)20, (decimal)10, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Float Validation")] [TestMethod("Requires a float is lower than")] public void RequiresFloatIsLowerThan() { var contract = new Contract() .Requires() .IsLowerThan((float)0, (int)0, "Float") .IsLowerThan((float)0, (int)0, "Float", "Custom message here") .IsLowerThan((float)-5, (int)0, "Float") .IsLowerThan((float)-5, (int)0, "Float", "Custom message here") .IsLowerThan((float)5, (int)0, "Float") .IsLowerThan((float)5, (int)0, "Float", "Custom message here") .IsLowerThan((float)0, (float)0, "Float") .IsLowerThan((float)0, (float)0, "Float", "Custom message here") .IsLowerThan((float)-5, (float)0, "Float") .IsLowerThan((float)-5, (float)0, "Float", "Custom message here") .IsLowerThan((float)5, (float)0, "Float") .IsLowerThan((float)5, (float)0, "Float", "Custom message here") .IsLowerThan((float)0, (double)0, "Float") .IsLowerThan((float)0, (double)0, "Float", "Custom message here") .IsLowerThan((float)-5, (double)0, "Float") .IsLowerThan((float)-5, (double)0, "Float", "Custom message here") .IsLowerThan((float)5, (double)0, "Float") .IsLowerThan((float)5, (double)0, "Float", "Custom message here") .IsLowerThan((float)0, (long)0, "Float") .IsLowerThan((float)0, (long)0, "Float", "Custom message here") .IsLowerThan((float)-5, (long)0, "Float") .IsLowerThan((float)-5, (long)0, "Float", "Custom message here") .IsLowerThan((float)5, (long)0, "Float") .IsLowerThan((float)5, (long)0, "Float", "Custom message here") .IsLowerThan((float)0, (decimal)0, "Float") .IsLowerThan((float)0, (decimal)0, "Float", "Custom message here") .IsLowerThan((float)-5, (decimal)0, "Float") .IsLowerThan((float)-5, (decimal)0, "Float", "Custom message here") .IsLowerThan((float)5, (decimal)0, "Float") .IsLowerThan((float)5, (decimal)0, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Float Validation")] [TestMethod("Requires a float is lower or equals than")] public void RequiresFloatIsLowerOrEqualsThan() { var contract = new Contract() .Requires() .IsLowerOrEqualsThan((float)0, (int)10, "Float") .IsLowerOrEqualsThan((float)0, (int)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)10, (int)10, "Float") .IsLowerOrEqualsThan((float)10, (int)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)20, (int)10, "Float") .IsLowerOrEqualsThan((float)20, (int)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)0, (float)10, "Float") .IsLowerOrEqualsThan((float)0, (float)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)10, (float)10, "Float") .IsLowerOrEqualsThan((float)10, (float)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)20, (float)10, "Float") .IsLowerOrEqualsThan((float)20, (float)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)0, (double)10, "Float") .IsLowerOrEqualsThan((float)0, (double)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)10, (double)10, "Float") .IsLowerOrEqualsThan((float)10, (double)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)20, (double)10, "Float") .IsLowerOrEqualsThan((float)20, (double)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)0, (long)10, "Float") .IsLowerOrEqualsThan((float)0, (long)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)10, (long)10, "Float") .IsLowerOrEqualsThan((float)10, (long)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)20, (long)10, "Float") .IsLowerOrEqualsThan((float)20, (long)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)0, (decimal)10, "Float") .IsLowerOrEqualsThan((float)0, (decimal)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)10, (decimal)10, "Float") .IsLowerOrEqualsThan((float)10, (decimal)10, "Float", "Custom message here") .IsLowerOrEqualsThan((float)20, (decimal)10, "Float") .IsLowerOrEqualsThan((float)20, (decimal)10, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Float Validation")] [TestMethod("Requires a float has its min value")] public void RequireFloatHasItsMinValue() { var contract = new Contract() .Requires() .IsMinValue(float.MaxValue, "Float") .IsMinValue(float.MaxValue, "Float", "Custom message here") .IsMinValue(float.MinValue, "Float") .IsMinValue(float.MinValue, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Float Validation")] [TestMethod("Requires a float has not its min value")] public void RequireFloatHasNotItsMinValue() { var contract = new Contract() .Requires() .IsNotMinValue(float.MaxValue, "Float") .IsNotMinValue(float.MaxValue, "Float", "Custom message here") .IsNotMinValue(float.MinValue, "Float") .IsNotMinValue(float.MinValue, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Float Validation")] [TestMethod("Requires a float has its max value")] public void RequireFloatHasItsMaxValue() { var contract = new Contract() .Requires() .IsMaxValue(float.MaxValue, "Float") .IsMaxValue(float.MaxValue, "Float", "Custom message here") .IsMaxValue(float.MinValue, "Float") .IsMaxValue(float.MinValue, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Float Validation")] [TestMethod("Requires a float has not its max value")] public void RequireFloatHasNotItsMaxValue() { var contract = new Contract() .Requires() .IsNotMaxValue(float.MaxValue, "Float") .IsNotMaxValue(float.MaxValue, "Float", "Custom message here") .IsNotMaxValue(float.MinValue, "Float") .IsNotMaxValue(float.MinValue, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Float Validation")] [TestMethod("Requires two floats are equals")] public void RequireTwoFloatsAreEquals() { var contract = new Contract() .Requires() .AreEquals((float)0, (int)0, "Float") .AreEquals((float)0, (int)0, "Float", "Custom message here") .AreEquals((float)0, (int)10, "Float") .AreEquals((float)0, (int)10, "Float", "Custom message here") .AreEquals((float)0, (float)0, "Float") .AreEquals((float)0, (float)0, "Float", "Custom message here") .AreEquals((float)0, (float)10, "Float") .AreEquals((float)0, (float)10, "Float", "Custom message here") .AreEquals((float)0, (double)0, "Float") .AreEquals((float)0, (double)0, "Float", "Custom message here") .AreEquals((float)0, (double)10, "Float") .AreEquals((float)0, (double)10, "Float", "Custom message here") .AreEquals((float)0, (long)0, "Float") .AreEquals((float)0, (long)0, "Float", "Custom message here") .AreEquals((float)0, (long)10, "Float") .AreEquals((float)0, (long)10, "Float", "Custom message here") .AreEquals((float)0, (decimal)0, "Float") .AreEquals((float)0, (decimal)0, "Float", "Custom message here") .AreEquals((float)0, (decimal)10, "Float") .AreEquals((float)0, (decimal)10, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Float Validation")] [TestMethod("Requires two floats are not equals")] public void RequireTwoFloatsAreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals((float)0, (int)0, "Float") .AreNotEquals((float)0, (int)0, "Float", "Custom message here") .AreNotEquals((float)0, (int)10, "Float") .AreNotEquals((float)0, (int)10, "Float", "Custom message here") .AreNotEquals((float)0, (float)0, "Float") .AreNotEquals((float)0, (float)0, "Float", "Custom message here") .AreNotEquals((float)0, (float)10, "Float") .AreNotEquals((float)0, (float)10, "Float", "Custom message here") .AreNotEquals((float)0, (double)0, "Float") .AreNotEquals((float)0, (double)0, "Float", "Custom message here") .AreNotEquals((float)0, (double)10, "Float") .AreNotEquals((float)0, (double)10, "Float", "Custom message here") .AreNotEquals((float)0, (long)0, "Float") .AreNotEquals((float)0, (long)0, "Float", "Custom message here") .AreNotEquals((float)0, (long)10, "Float") .AreNotEquals((float)0, (long)10, "Float", "Custom message here") .AreNotEquals((float)0, (decimal)0, "Float") .AreNotEquals((float)0, (decimal)0, "Float", "Custom message here") .AreNotEquals((float)0, (decimal)10, "Float") .AreNotEquals((float)0, (decimal)10, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Float Validation")] [TestMethod("Requires a float is null")] public void RequiresFloatIsNull() { var contract = new Contract() .Requires() .IsNull(_entity.FloatNull, "Float") .IsNull(_entity.FloatNull, "Float", "Custom message here") .IsNull(_entity.FloatStart, "Float") .IsNull(_entity.FloatStart, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Float Validation")] [TestMethod("Requires a float is not null")] public void RequiresFloatIsNotNull() { var contract = new Contract() .Requires() .IsNotNull(_entity.FloatNull, "Float") .IsNotNull(_entity.FloatNull, "Float", "Custom message here") .IsNotNull(_entity.FloatStart, "Float") .IsNotNull(_entity.FloatStart, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Float Validation")] [TestMethod("Requires a float is between")] public void RequiresFloatIsBetween() { var contract = new Contract() .Requires() .IsBetween(_entity.FloatBetweenStartAndEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatBetweenStartAndEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatStart, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatStart, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatNotBetweenStartAndEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatNotBetweenStartAndEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatBetweenStartAndEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatBetweenStartAndEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatStart, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatStart, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatNotBetweenStartAndEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatNotBetweenStartAndEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatBetweenStartAndEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatBetweenStartAndEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatStart, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatStart, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatNotBetweenStartAndEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatNotBetweenStartAndEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatBetweenStartAndEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatBetweenStartAndEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatStart, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatStart, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatNotBetweenStartAndEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float") .IsBetween(_entity.FloatNotBetweenStartAndEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatBetweenStartAndEnd, _entity.FloatStart, _entity.FloatEnd, "Float") .IsBetween(_entity.FloatBetweenStartAndEnd, _entity.FloatStart, _entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatStart, _entity.FloatStart, _entity.FloatEnd, "Float") .IsBetween(_entity.FloatStart, _entity.FloatStart, _entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatEnd, _entity.FloatStart, _entity.FloatEnd, "Float") .IsBetween(_entity.FloatEnd, _entity.FloatStart, _entity.FloatEnd, "Float", "Custom message here") .IsBetween(_entity.FloatNotBetweenStartAndEnd, _entity.FloatStart, _entity.FloatEnd, "Float") .IsBetween(_entity.FloatNotBetweenStartAndEnd, _entity.FloatStart, _entity.FloatEnd, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Float Validation")] [TestMethod("Requires a float is not between")] public void RequiresFloatIsNotBetween() { var contract = new Contract() .Requires() .IsNotBetween(_entity.FloatBetweenStartAndEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatBetweenStartAndEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatStart, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatStart, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, (int)_entity.FloatStart, (int)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatBetweenStartAndEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatBetweenStartAndEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatStart, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatStart, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, (double)_entity.FloatStart, (double)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatBetweenStartAndEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatBetweenStartAndEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatStart, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatStart, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, (float)_entity.FloatStart, (float)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatBetweenStartAndEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatBetweenStartAndEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatStart, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatStart, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, (long)_entity.FloatStart, (long)_entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatBetweenStartAndEnd, _entity.FloatStart, _entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatBetweenStartAndEnd, _entity.FloatStart, _entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatStart, _entity.FloatStart, _entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatStart, _entity.FloatStart, _entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatEnd, _entity.FloatStart, _entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatEnd, _entity.FloatStart, _entity.FloatEnd, "Float", "Custom message here") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, _entity.FloatStart, _entity.FloatEnd, "Float") .IsNotBetween(_entity.FloatNotBetweenStartAndEnd, _entity.FloatStart, _entity.FloatEnd, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 30); } [TestCategory("Float Validation")] [TestMethod("Requires a list contains a float")] public void RequiresListContainsDouble() { var contract = new Contract() .Requires() .Contains((float)1, _entity.FloatList, "Float") .Contains((float)1, _entity.FloatList, "Float", "Custom message here") .Contains((float)3, _entity.FloatList, "Float") .Contains((float)3, _entity.FloatList, "Float", "Custom message here") .Contains((float)5, _entity.FloatList, "Float") .Contains((float)5, _entity.FloatList, "Float", "Custom message here") .Contains((float)7, _entity.FloatList, "Float") .Contains((float)7, _entity.FloatList, "Float", "Custom message here") .Contains((float)9, _entity.FloatList, "Float") .Contains((float)9, _entity.FloatList, "Float", "Custom message here") .Contains((float)11, _entity.FloatList, "Float") .Contains((float)11, _entity.FloatList, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Float Validation")] [TestMethod("Requires a list does not contains a float")] public void RequiresListNotContainsDouble() { var contract = new Contract() .Requires() .NotContains((float)1, _entity.FloatList, "Float") .NotContains((float)1, _entity.FloatList, "Float", "Custom message here") .NotContains((float)3, _entity.FloatList, "Float") .NotContains((float)3, _entity.FloatList, "Float", "Custom message here") .NotContains((float)5, _entity.FloatList, "Float") .NotContains((float)5, _entity.FloatList, "Float", "Custom message here") .NotContains((float)7, _entity.FloatList, "Float") .NotContains((float)7, _entity.FloatList, "Float", "Custom message here") .NotContains((float)9, _entity.FloatList, "Float") .NotContains((float)9, _entity.FloatList, "Float", "Custom message here") .NotContains((float)11, _entity.FloatList, "Float") .NotContains((float)11, _entity.FloatList, "Float", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } } } ================================================ FILE: Flunt.Tests/Flunt.Tests.csproj ================================================ net6.0 false all runtime; build; native; contentfiles; analyzers; buildtransitive ================================================ FILE: Flunt.Tests/GuidValidationTests.cs ================================================ using System; using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class GuidValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("Guid Validation")] [TestMethod("Requires two GUIDs are equals")] public void RequiresAreEquals() { var contract = new Contract() .Requires() .AreEquals(_entity.GuidNotEmpty, _entity.GuidNotEmpty, "Guid") .AreEquals(_entity.GuidNotEmpty, _entity.GuidNotEmpty, "Guid", "Custom message here") .AreEquals(_entity.GuidNotEmpty, Guid.NewGuid(), "Guid") .AreEquals(_entity.GuidNotEmpty, Guid.NewGuid(), "Guid", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Guid Validation")] [TestMethod("Requires two GUIDs are not equals")] public void RequiresAreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals(_entity.GuidNotEmpty, _entity.GuidNotEmpty, "Guid") .AreNotEquals(_entity.GuidNotEmpty, _entity.GuidNotEmpty, "Guid", "Custom message here") .AreNotEquals(_entity.GuidNotEmpty, Guid.NewGuid(), "Guid") .AreNotEquals(_entity.GuidNotEmpty, Guid.NewGuid(), "Guid", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Guid Validation")] [TestMethod("Requires GUID is empty")] public void RequiresIsEmpty() { var contract = new Contract() .Requires() .IsEmpty(_entity.GuidNotEmpty, "Guid") .IsEmpty(_entity.GuidNotEmpty, "Guid", "Custom message here") .IsEmpty(_entity.GuidEmpty, "Guid") .IsEmpty(_entity.GuidEmpty, "Guid", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Guid Validation")] [TestMethod("Requires GUID is not empty")] public void RequiresIsNotEmpty() { var contract = new Contract() .Requires() .IsNotEmpty(_entity.GuidNotEmpty, "Guid") .IsNotEmpty(_entity.GuidNotEmpty, "Guid", "Custom message here") .IsNotEmpty(_entity.GuidEmpty, "Guid") .IsNotEmpty(_entity.GuidEmpty, "Guid", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } } } ================================================ FILE: Flunt.Tests/IntValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class IntValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("Int Validation")] [TestMethod("Requires an int is greater than")] public void RequiresIntIsGreaterThan() { var contract = new Contract() .Requires() .IsGreaterThan((int)0, (int)10, "Int") .IsGreaterThan((int)0, (int)10, "Int", "Custom message here") .IsGreaterThan((int)10, (int)10, "Int") .IsGreaterThan((int)10, (int)10, "Int", "Custom message here") .IsGreaterThan((int)20, (int)10, "Int") .IsGreaterThan((int)20, (int)10, "Int", "Custom message here") .IsGreaterThan((int)0, (float)10, "Int") .IsGreaterThan((int)0, (float)10, "Int", "Custom message here") .IsGreaterThan((int)10, (float)10, "Int") .IsGreaterThan((int)10, (float)10, "Int", "Custom message here") .IsGreaterThan((int)20, (float)10, "Int") .IsGreaterThan((int)20, (float)10, "Int", "Custom message here") .IsGreaterThan((int)0, (double)10, "Int") .IsGreaterThan((int)0, (double)10, "Int", "Custom message here") .IsGreaterThan((int)10, (double)10, "Int") .IsGreaterThan((int)10, (double)10, "Int", "Custom message here") .IsGreaterThan((int)20, (double)10, "Int") .IsGreaterThan((int)20, (double)10, "Int", "Custom message here") .IsGreaterThan((int)0, (long)10, "Int") .IsGreaterThan((int)0, (long)10, "Int", "Custom message here") .IsGreaterThan((int)10, (long)10, "Int") .IsGreaterThan((int)10, (long)10, "Int", "Custom message here") .IsGreaterThan((int)20, (long)10, "Int") .IsGreaterThan((int)20, (long)10, "Int", "Custom message here") .IsGreaterThan((int)0, (decimal)10, "Int") .IsGreaterThan((int)0, (decimal)10, "Int", "Custom message here") .IsGreaterThan((int)10, (decimal)10, "Int") .IsGreaterThan((int)10, (decimal)10, "Int", "Custom message here") .IsGreaterThan((int)20, (decimal)10, "Int") .IsGreaterThan((int)20, (decimal)10, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Int Validation")] [TestMethod("Requires an int is greater or equals than")] public void RequiresIntIsGreaterOrEqualsThan() { var contract = new Contract() .Requires() .IsGreaterOrEqualsThan((int)0, (int)10, "Int") .IsGreaterOrEqualsThan((int)0, (int)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)10, (int)10, "Int") .IsGreaterOrEqualsThan((int)10, (int)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)20, (int)10, "Int") .IsGreaterOrEqualsThan((int)20, (int)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)0, (float)10, "Int") .IsGreaterOrEqualsThan((int)0, (float)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)10, (float)10, "Int") .IsGreaterOrEqualsThan((int)10, (float)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)20, (float)10, "Int") .IsGreaterOrEqualsThan((int)20, (float)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)0, (double)10, "Int") .IsGreaterOrEqualsThan((int)0, (double)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)10, (double)10, "Int") .IsGreaterOrEqualsThan((int)10, (double)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)20, (double)10, "Int") .IsGreaterOrEqualsThan((int)20, (double)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)0, (long)10, "Int") .IsGreaterOrEqualsThan((int)0, (long)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)10, (long)10, "Int") .IsGreaterOrEqualsThan((int)10, (long)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)20, (long)10, "Int") .IsGreaterOrEqualsThan((int)20, (long)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)0, (decimal)10, "Int") .IsGreaterOrEqualsThan((int)0, (decimal)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)10, (decimal)10, "Int") .IsGreaterOrEqualsThan((int)10, (decimal)10, "Int", "Custom message here") .IsGreaterOrEqualsThan((int)20, (decimal)10, "Int") .IsGreaterOrEqualsThan((int)20, (decimal)10, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Int Validation")] [TestMethod("Requires an int is lower than")] public void RequiresIntIsLowerThan() { var contract = new Contract() .Requires() .IsLowerThan((int)0, (int)0, "Int") .IsLowerThan((int)0, (int)0, "Int", "Custom message here") .IsLowerThan((int)-5, (int)0, "Int") .IsLowerThan((int)-5, (int)0, "Int", "Custom message here") .IsLowerThan((int)5, (int)0, "Int") .IsLowerThan((int)5, (int)0, "Int", "Custom message here") .IsLowerThan((int)0, (float)0, "Int") .IsLowerThan((int)0, (float)0, "Int", "Custom message here") .IsLowerThan((int)-5, (float)0, "Int") .IsLowerThan((int)-5, (float)0, "Int", "Custom message here") .IsLowerThan((int)5, (float)0, "Int") .IsLowerThan((int)5, (float)0, "Int", "Custom message here") .IsLowerThan((int)0, (double)0, "Int") .IsLowerThan((int)0, (double)0, "Int", "Custom message here") .IsLowerThan((int)-5, (double)0, "Int") .IsLowerThan((int)-5, (double)0, "Int", "Custom message here") .IsLowerThan((int)5, (double)0, "Int") .IsLowerThan((int)5, (double)0, "Int", "Custom message here") .IsLowerThan((int)0, (long)0, "Int") .IsLowerThan((int)0, (long)0, "Int", "Custom message here") .IsLowerThan((int)-5, (long)0, "Int") .IsLowerThan((int)-5, (long)0, "Int", "Custom message here") .IsLowerThan((int)5, (long)0, "Int") .IsLowerThan((int)5, (long)0, "Int", "Custom message here") .IsLowerThan((int)0, (decimal)0, "Int") .IsLowerThan((int)0, (decimal)0, "Int", "Custom message here") .IsLowerThan((int)-5, (decimal)0, "Int") .IsLowerThan((int)-5, (decimal)0, "Int", "Custom message here") .IsLowerThan((int)5, (decimal)0, "Int") .IsLowerThan((int)5, (decimal)0, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Int Validation")] [TestMethod("Requires an int is lower or equals than")] public void RequiresIntIsLowerOrEqualsThan() { var contract = new Contract() .Requires() .IsLowerOrEqualsThan((int)0, (int)10, "Int") .IsLowerOrEqualsThan((int)0, (int)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)10, (int)10, "Int") .IsLowerOrEqualsThan((int)10, (int)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)20, (int)10, "Int") .IsLowerOrEqualsThan((int)20, (int)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)0, (float)10, "Int") .IsLowerOrEqualsThan((int)0, (float)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)10, (float)10, "Int") .IsLowerOrEqualsThan((int)10, (float)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)20, (float)10, "Int") .IsLowerOrEqualsThan((int)20, (float)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)0, (double)10, "Int") .IsLowerOrEqualsThan((int)0, (double)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)10, (double)10, "Int") .IsLowerOrEqualsThan((int)10, (double)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)20, (double)10, "Int") .IsLowerOrEqualsThan((int)20, (double)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)0, (long)10, "Int") .IsLowerOrEqualsThan((int)0, (long)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)10, (long)10, "Int") .IsLowerOrEqualsThan((int)10, (long)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)20, (long)10, "Int") .IsLowerOrEqualsThan((int)20, (long)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)0, (decimal)10, "Int") .IsLowerOrEqualsThan((int)0, (decimal)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)10, (decimal)10, "Int") .IsLowerOrEqualsThan((int)10, (decimal)10, "Int", "Custom message here") .IsLowerOrEqualsThan((int)20, (decimal)10, "Int") .IsLowerOrEqualsThan((int)20, (decimal)10, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Int Validation")] [TestMethod("Requires an int has its min value")] public void RequireIntHasItsMinValue() { var contract = new Contract() .Requires() .IsMinValue(int.MaxValue, "Int") .IsMinValue(int.MaxValue, "Int", "Custom message here") .IsMinValue(int.MinValue, "Int") .IsMinValue(int.MinValue, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Int Validation")] [TestMethod("Requires an int has not its min value")] public void RequireIntHasNotItsMinValue() { var contract = new Contract() .Requires() .IsNotMinValue(int.MaxValue, "Int") .IsNotMinValue(int.MaxValue, "Int", "Custom message here") .IsNotMinValue(int.MinValue, "Int") .IsNotMinValue(int.MinValue, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Int Validation")] [TestMethod("Requires an int has its max value")] public void RequireIntHasItsMaxValue() { var contract = new Contract() .Requires() .IsMaxValue(int.MaxValue, "Int") .IsMaxValue(int.MaxValue, "Int", "Custom message here") .IsMaxValue(int.MinValue, "Int") .IsMaxValue(int.MinValue, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Int Validation")] [TestMethod("Requires an int has not its max value")] public void RequireIntHasNotItsMaxValue() { var contract = new Contract() .Requires() .IsNotMaxValue(int.MaxValue, "Int") .IsNotMaxValue(int.MaxValue, "Int", "Custom message here") .IsNotMaxValue(int.MinValue, "Int") .IsNotMaxValue(int.MinValue, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Int Validation")] [TestMethod("Requires two ints are equals")] public void RequireTwoIntsAreEquals() { var contract = new Contract() .Requires() .AreEquals((int)0, (int)0, "Int") .AreEquals((int)0, (int)0, "Int", "Custom message here") .AreEquals((int)0, (int)10, "Int") .AreEquals((int)0, (int)10, "Int", "Custom message here") .AreEquals((int)0, (float)0, "Int") .AreEquals((int)0, (float)0, "Int", "Custom message here") .AreEquals((int)0, (float)10, "Int") .AreEquals((int)0, (float)10, "Int", "Custom message here") .AreEquals((int)0, (double)0, "Int") .AreEquals((int)0, (double)0, "Int", "Custom message here") .AreEquals((int)0, (double)10, "Int") .AreEquals((int)0, (double)10, "Int", "Custom message here") .AreEquals((int)0, (long)0, "Int") .AreEquals((int)0, (long)0, "Int", "Custom message here") .AreEquals((int)0, (long)10, "Int") .AreEquals((int)0, (long)10, "Int", "Custom message here") .AreEquals((int)0, (decimal)0, "Int") .AreEquals((int)0, (decimal)0, "Int", "Custom message here") .AreEquals((int)0, (decimal)10, "Int") .AreEquals((int)0, (decimal)10, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Int Validation")] [TestMethod("Requires two ints are not equals")] public void RequireTwoIntsAreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals((int)0, (int)0, "Int") .AreNotEquals((int)0, (int)0, "Int", "Custom message here") .AreNotEquals((int)0, (int)10, "Int") .AreNotEquals((int)0, (int)10, "Int", "Custom message here") .AreNotEquals((int)0, (float)0, "Int") .AreNotEquals((int)0, (float)0, "Int", "Custom message here") .AreNotEquals((int)0, (float)10, "Int") .AreNotEquals((int)0, (float)10, "Int", "Custom message here") .AreNotEquals((int)0, (double)0, "Int") .AreNotEquals((int)0, (double)0, "Int", "Custom message here") .AreNotEquals((int)0, (double)10, "Int") .AreNotEquals((int)0, (double)10, "Int", "Custom message here") .AreNotEquals((int)0, (long)0, "Int") .AreNotEquals((int)0, (long)0, "Int", "Custom message here") .AreNotEquals((int)0, (long)10, "Int") .AreNotEquals((int)0, (long)10, "Int", "Custom message here") .AreNotEquals((int)0, (decimal)0, "Int") .AreNotEquals((int)0, (decimal)0, "Int", "Custom message here") .AreNotEquals((int)0, (decimal)10, "Int") .AreNotEquals((int)0, (decimal)10, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Int Validation")] [TestMethod("Requires an int is null")] public void RequiresIntIsNull() { var contract = new Contract() .Requires() .IsNull(_entity.IntNull, "Int") .IsNull(_entity.IntNull, "Int", "Custom message here") .IsNull(_entity.IntStart, "Int") .IsNull(_entity.IntStart, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Int Validation")] [TestMethod("Requires an int is not null")] public void RequiresIntIsNotNull() { var contract = new Contract() .Requires() .IsNotNull(_entity.IntNull, "Int") .IsNotNull(_entity.IntNull, "Int", "Custom message here") .IsNotNull(_entity.IntStart, "Int") .IsNotNull(_entity.IntStart, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Int Validation")] [TestMethod("Requires an int is between")] public void RequiresIntIsBetween() { var contract = new Contract() .Requires() .IsBetween(_entity.IntBetweenStartAndEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int") .IsBetween(_entity.IntBetweenStartAndEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntStart, (int)_entity.IntStart, (int)_entity.IntEnd, "Int") .IsBetween(_entity.IntStart, (int)_entity.IntStart, (int)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int") .IsBetween(_entity.IntEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntNotBetweenStartAndEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int") .IsBetween(_entity.IntNotBetweenStartAndEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntBetweenStartAndEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int") .IsBetween(_entity.IntBetweenStartAndEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntStart, (double)_entity.IntStart, (double)_entity.IntEnd, "Int") .IsBetween(_entity.IntStart, (double)_entity.IntStart, (double)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int") .IsBetween(_entity.IntEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntNotBetweenStartAndEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int") .IsBetween(_entity.IntNotBetweenStartAndEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntBetweenStartAndEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int") .IsBetween(_entity.IntBetweenStartAndEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntStart, (float)_entity.IntStart, (float)_entity.IntEnd, "Int") .IsBetween(_entity.IntStart, (float)_entity.IntStart, (float)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int") .IsBetween(_entity.IntEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntNotBetweenStartAndEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int") .IsBetween(_entity.IntNotBetweenStartAndEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntBetweenStartAndEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int") .IsBetween(_entity.IntBetweenStartAndEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntStart, (long)_entity.IntStart, (long)_entity.IntEnd, "Int") .IsBetween(_entity.IntStart, (long)_entity.IntStart, (long)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int") .IsBetween(_entity.IntEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntNotBetweenStartAndEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int") .IsBetween(_entity.IntNotBetweenStartAndEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntBetweenStartAndEnd, _entity.IntStart, _entity.IntEnd, "Int") .IsBetween(_entity.IntBetweenStartAndEnd, _entity.IntStart, _entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntStart, _entity.IntStart, _entity.IntEnd, "Int") .IsBetween(_entity.IntStart, _entity.IntStart, _entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntEnd, _entity.IntStart, _entity.IntEnd, "Int") .IsBetween(_entity.IntEnd, _entity.IntStart, _entity.IntEnd, "Int", "Custom message here") .IsBetween(_entity.IntNotBetweenStartAndEnd, _entity.IntStart, _entity.IntEnd, "Int") .IsBetween(_entity.IntNotBetweenStartAndEnd, _entity.IntStart, _entity.IntEnd, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Int Validation")] [TestMethod("Requires an int is not between")] public void RequiresIntIsNotBetween() { var contract = new Contract() .Requires() .IsNotBetween(_entity.IntBetweenStartAndEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntBetweenStartAndEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntStart, (int)_entity.IntStart, (int)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntStart, (int)_entity.IntStart, (int)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, (int)_entity.IntStart, (int)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntBetweenStartAndEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntBetweenStartAndEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntStart, (double)_entity.IntStart, (double)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntStart, (double)_entity.IntStart, (double)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, (double)_entity.IntStart, (double)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntBetweenStartAndEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntBetweenStartAndEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntStart, (float)_entity.IntStart, (float)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntStart, (float)_entity.IntStart, (float)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, (float)_entity.IntStart, (float)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntBetweenStartAndEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntBetweenStartAndEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntStart, (long)_entity.IntStart, (long)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntStart, (long)_entity.IntStart, (long)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, (long)_entity.IntStart, (long)_entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntBetweenStartAndEnd, _entity.IntStart, _entity.IntEnd, "Int") .IsNotBetween(_entity.IntBetweenStartAndEnd, _entity.IntStart, _entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntStart, _entity.IntStart, _entity.IntEnd, "Int") .IsNotBetween(_entity.IntStart, _entity.IntStart, _entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntEnd, _entity.IntStart, _entity.IntEnd, "Int") .IsNotBetween(_entity.IntEnd, _entity.IntStart, _entity.IntEnd, "Int", "Custom message here") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, _entity.IntStart, _entity.IntEnd, "Int") .IsNotBetween(_entity.IntNotBetweenStartAndEnd, _entity.IntStart, _entity.IntEnd, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 30); } [TestCategory("Int Validation")] [TestMethod("Requires a list contains an int")] public void RequiresListContainsDouble() { var contract = new Contract() .Requires() .Contains((int)1, _entity.IntList, "Int") .Contains((int)1, _entity.IntList, "Int", "Custom message here") .Contains((int)3, _entity.IntList, "Int") .Contains((int)3, _entity.IntList, "Int", "Custom message here") .Contains((int)5, _entity.IntList, "Int") .Contains((int)5, _entity.IntList, "Int", "Custom message here") .Contains((int)7, _entity.IntList, "Int") .Contains((int)7, _entity.IntList, "Int", "Custom message here") .Contains((int)9, _entity.IntList, "Int") .Contains((int)9, _entity.IntList, "Int", "Custom message here") .Contains((int)11, _entity.IntList, "Int") .Contains((int)11, _entity.IntList, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Int Validation")] [TestMethod("Requires a list does not contains an int")] public void RequiresListNotContainsDouble() { var contract = new Contract() .Requires() .NotContains((int)1, _entity.IntList, "Int") .NotContains((int)1, _entity.IntList, "Int", "Custom message here") .NotContains((int)3, _entity.IntList, "Int") .NotContains((int)3, _entity.IntList, "Int", "Custom message here") .NotContains((int)5, _entity.IntList, "Int") .NotContains((int)5, _entity.IntList, "Int", "Custom message here") .NotContains((int)7, _entity.IntList, "Int") .NotContains((int)7, _entity.IntList, "Int", "Custom message here") .NotContains((int)9, _entity.IntList, "Int") .NotContains((int)9, _entity.IntList, "Int", "Custom message here") .NotContains((int)11, _entity.IntList, "Int") .NotContains((int)11, _entity.IntList, "Int", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } } } ================================================ FILE: Flunt.Tests/ListValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class ListValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("List Validation")] [TestMethod("Requires a list is null")] public void RequiresIsNull() { var contract = new Contract() .Requires() .IsNull(_entity.ListNull, "List") .IsNull(_entity.ListNull, "List", "Custom message here") .IsNull(_entity.ListNotNull, "List") .IsNull(_entity.ListNotNull, "List", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("List Validation")] [TestMethod("Requires a list is not null")] public void RequiresIsNotNull() { var contract = new Contract() .Requires() .IsNotNull(_entity.ListNull, "List") .IsNotNull(_entity.ListNull, "List", "Custom message here") .IsNotNull(_entity.ListNotNull, "List") .IsNotNull(_entity.ListNotNull, "List", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("List Validation")] [TestMethod("Requires a list has no elements")] public void RequiresIsEmpty() { var contract = new Contract() .Requires() .IsEmpty(_entity.ListEmpty, "List") .IsEmpty(_entity.ListEmpty, "List", "Custom message here") .IsEmpty(_entity.ListNotEmpty, "List") .IsEmpty(_entity.ListNotEmpty, "List", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("List Validation")] [TestMethod("Requires a list has at least one element")] public void RequiresIsNotEmpty() { var contract = new Contract() .Requires() .IsNotEmpty(_entity.ListEmpty, "List") .IsNotEmpty(_entity.ListEmpty, "List", "Custom message here") .IsNotEmpty(_entity.ListNotEmpty, "List") .IsNotEmpty(_entity.ListNotEmpty, "List", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("List Validation")] [TestMethod("Requires a list count is greater than")] public void RequiresIsGreaterThan() { var contract = new Contract() .Requires() .IsGreaterThan(_entity.ListNotEmpty, 0, "List") .IsGreaterThan(_entity.ListNotEmpty, 1, "List") .IsGreaterThan(_entity.ListNotEmpty, 2, "List") .IsGreaterThan(_entity.ListNotEmpty, 3, "List") .IsGreaterThan(_entity.ListNotEmpty, 4, "List") .IsGreaterThan(_entity.ListNotEmpty, 0, "List", "Custom message here") .IsGreaterThan(_entity.ListNotEmpty, 1, "List", "Custom message here") .IsGreaterThan(_entity.ListNotEmpty, 2, "List", "Custom message here") .IsGreaterThan(_entity.ListNotEmpty, 3, "List", "Custom message here") .IsGreaterThan(_entity.ListNotEmpty, 4, "List", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 4); } [TestCategory("List Validation")] [TestMethod("Requires a list count is greater or equals than")] public void RequiresIsGreaterOrEqualsThan() { var contract = new Contract() .Requires() .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 0, "List") .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 1, "List") .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 2, "List") .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 3, "List") .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 4, "List") .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 0, "List", "Custom message here") .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 1, "List", "Custom message here") .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 2, "List", "Custom message here") .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 3, "List", "Custom message here") .IsGreaterOrEqualsThan(_entity.ListNotEmpty, 4, "List", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("List Validation")] [TestMethod("Requires a list count is lower than")] public void RequiresIsLowerThan() { var contract = new Contract() .Requires() .IsLowerThan(_entity.ListNotEmpty, 0, "List") .IsLowerThan(_entity.ListNotEmpty, 1, "List") .IsLowerThan(_entity.ListNotEmpty, 2, "List") .IsLowerThan(_entity.ListNotEmpty, 3, "List") .IsLowerThan(_entity.ListNotEmpty, 4, "List") .IsLowerThan(_entity.ListNotEmpty, 0, "List", "Custom message here") .IsLowerThan(_entity.ListNotEmpty, 1, "List", "Custom message here") .IsLowerThan(_entity.ListNotEmpty, 2, "List", "Custom message here") .IsLowerThan(_entity.ListNotEmpty, 3, "List", "Custom message here") .IsLowerThan(_entity.ListNotEmpty, 4, "List", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 8); } [TestCategory("List Validation")] [TestMethod("Requires a list count is lower or equals than")] public void RequiresIsLowerOrEqualsThan() { var contract = new Contract() .Requires() .IsLowerOrEqualsThan(_entity.ListNotEmpty, 0, "List") .IsLowerOrEqualsThan(_entity.ListNotEmpty, 1, "List") .IsLowerOrEqualsThan(_entity.ListNotEmpty, 2, "List") .IsLowerOrEqualsThan(_entity.ListNotEmpty, 3, "List") .IsLowerOrEqualsThan(_entity.ListNotEmpty, 4, "List") .IsLowerOrEqualsThan(_entity.ListNotEmpty, 0, "List", "Custom message here") .IsLowerOrEqualsThan(_entity.ListNotEmpty, 1, "List", "Custom message here") .IsLowerOrEqualsThan(_entity.ListNotEmpty, 2, "List", "Custom message here") .IsLowerOrEqualsThan(_entity.ListNotEmpty, 3, "List", "Custom message here") .IsLowerOrEqualsThan(_entity.ListNotEmpty, 4, "List", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 6); } } } ================================================ FILE: Flunt.Tests/LongValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class LongValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("Long Validation")] [TestMethod("Requires a long is greater than")] public void RequiresLongIsGreaterThan() { var contract = new Contract() .Requires() .IsGreaterThan((long)0, (int)10, "Long") .IsGreaterThan((long)0, (int)10, "Long", "Custom message here") .IsGreaterThan((long)10, (int)10, "Long") .IsGreaterThan((long)10, (int)10, "Long", "Custom message here") .IsGreaterThan((long)20, (int)10, "Long") .IsGreaterThan((long)20, (int)10, "Long", "Custom message here") .IsGreaterThan((long)0, (float)10, "Long") .IsGreaterThan((long)0, (float)10, "Long", "Custom message here") .IsGreaterThan((long)10, (float)10, "Long") .IsGreaterThan((long)10, (float)10, "Long", "Custom message here") .IsGreaterThan((long)20, (float)10, "Long") .IsGreaterThan((long)20, (float)10, "Long", "Custom message here") .IsGreaterThan((long)0, (double)10, "Long") .IsGreaterThan((long)0, (double)10, "Long", "Custom message here") .IsGreaterThan((long)10, (double)10, "Long") .IsGreaterThan((long)10, (double)10, "Long", "Custom message here") .IsGreaterThan((long)20, (double)10, "Long") .IsGreaterThan((long)20, (double)10, "Long", "Custom message here") .IsGreaterThan((long)0, (long)10, "Long") .IsGreaterThan((long)0, (long)10, "Long", "Custom message here") .IsGreaterThan((long)10, (long)10, "Long") .IsGreaterThan((long)10, (long)10, "Long", "Custom message here") .IsGreaterThan((long)20, (long)10, "Long") .IsGreaterThan((long)20, (long)10, "Long", "Custom message here") .IsGreaterThan((long)0, (decimal)10, "Long") .IsGreaterThan((long)0, (decimal)10, "Long", "Custom message here") .IsGreaterThan((long)10, (decimal)10, "Long") .IsGreaterThan((long)10, (decimal)10, "Long", "Custom message here") .IsGreaterThan((long)20, (decimal)10, "Long") .IsGreaterThan((long)20, (decimal)10, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Long Validation")] [TestMethod("Requires a long is greater or equals than")] public void RequiresLongIsGreaterOrEqualsThan() { var contract = new Contract() .Requires() .IsGreaterOrEqualsThan((long)0, (int)10, "Long") .IsGreaterOrEqualsThan((long)0, (int)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)10, (int)10, "Long") .IsGreaterOrEqualsThan((long)10, (int)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)20, (int)10, "Long") .IsGreaterOrEqualsThan((long)20, (int)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)0, (float)10, "Long") .IsGreaterOrEqualsThan((long)0, (float)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)10, (float)10, "Long") .IsGreaterOrEqualsThan((long)10, (float)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)20, (float)10, "Long") .IsGreaterOrEqualsThan((long)20, (float)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)0, (double)10, "Long") .IsGreaterOrEqualsThan((long)0, (double)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)10, (double)10, "Long") .IsGreaterOrEqualsThan((long)10, (double)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)20, (double)10, "Long") .IsGreaterOrEqualsThan((long)20, (double)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)0, (long)10, "Long") .IsGreaterOrEqualsThan((long)0, (long)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)10, (long)10, "Long") .IsGreaterOrEqualsThan((long)10, (long)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)20, (long)10, "Long") .IsGreaterOrEqualsThan((long)20, (long)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)0, (decimal)10, "Long") .IsGreaterOrEqualsThan((long)0, (decimal)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)10, (decimal)10, "Long") .IsGreaterOrEqualsThan((long)10, (decimal)10, "Long", "Custom message here") .IsGreaterOrEqualsThan((long)20, (decimal)10, "Long") .IsGreaterOrEqualsThan((long)20, (decimal)10, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Long Validation")] [TestMethod("Requires a long is lower than")] public void RequiresLongIsLowerThan() { var contract = new Contract() .Requires() .IsLowerThan((long)0, (int)0, "Long") .IsLowerThan((long)0, (int)0, "Long", "Custom message here") .IsLowerThan((long)-5, (int)0, "Long") .IsLowerThan((long)-5, (int)0, "Long", "Custom message here") .IsLowerThan((long)5, (int)0, "Long") .IsLowerThan((long)5, (int)0, "Long", "Custom message here") .IsLowerThan((long)0, (float)0, "Long") .IsLowerThan((long)0, (float)0, "Long", "Custom message here") .IsLowerThan((long)-5, (float)0, "Long") .IsLowerThan((long)-5, (float)0, "Long", "Custom message here") .IsLowerThan((long)5, (float)0, "Long") .IsLowerThan((long)5, (float)0, "Long", "Custom message here") .IsLowerThan((long)0, (double)0, "Long") .IsLowerThan((long)0, (double)0, "Long", "Custom message here") .IsLowerThan((long)-5, (double)0, "Long") .IsLowerThan((long)-5, (double)0, "Long", "Custom message here") .IsLowerThan((long)5, (double)0, "Long") .IsLowerThan((long)5, (double)0, "Long", "Custom message here") .IsLowerThan((long)0, (long)0, "Long") .IsLowerThan((long)0, (long)0, "Long", "Custom message here") .IsLowerThan((long)-5, (long)0, "Long") .IsLowerThan((long)-5, (long)0, "Long", "Custom message here") .IsLowerThan((long)5, (long)0, "Long") .IsLowerThan((long)5, (long)0, "Long", "Custom message here") .IsLowerThan((long)0, (decimal)0, "Long") .IsLowerThan((long)0, (decimal)0, "Long", "Custom message here") .IsLowerThan((long)-5, (decimal)0, "Long") .IsLowerThan((long)-5, (decimal)0, "Long", "Custom message here") .IsLowerThan((long)5, (decimal)0, "Long") .IsLowerThan((long)5, (decimal)0, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("Long Validation")] [TestMethod("Requires a long is lower or equals than")] public void RequiresLongIsLowerOrEqualsThan() { var contract = new Contract() .Requires() .IsLowerOrEqualsThan((long)0, (int)10, "Long") .IsLowerOrEqualsThan((long)0, (int)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)10, (int)10, "Long") .IsLowerOrEqualsThan((long)10, (int)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)20, (int)10, "Long") .IsLowerOrEqualsThan((long)20, (int)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)0, (float)10, "Long") .IsLowerOrEqualsThan((long)0, (float)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)10, (float)10, "Long") .IsLowerOrEqualsThan((long)10, (float)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)20, (float)10, "Long") .IsLowerOrEqualsThan((long)20, (float)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)0, (double)10, "Long") .IsLowerOrEqualsThan((long)0, (double)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)10, (double)10, "Long") .IsLowerOrEqualsThan((long)10, (double)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)20, (double)10, "Long") .IsLowerOrEqualsThan((long)20, (double)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)0, (long)10, "Long") .IsLowerOrEqualsThan((long)0, (long)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)10, (long)10, "Long") .IsLowerOrEqualsThan((long)10, (long)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)20, (long)10, "Long") .IsLowerOrEqualsThan((long)20, (long)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)0, (decimal)10, "Long") .IsLowerOrEqualsThan((long)0, (decimal)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)10, (decimal)10, "Long") .IsLowerOrEqualsThan((long)10, (decimal)10, "Long", "Custom message here") .IsLowerOrEqualsThan((long)20, (decimal)10, "Long") .IsLowerOrEqualsThan((long)20, (decimal)10, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Long Validation")] [TestMethod("Requires a long has its min value")] public void RequireLongHasItsMinValue() { var contract = new Contract() .Requires() .IsMinValue(long.MaxValue, "Long") .IsMinValue(long.MaxValue, "Long", "Custom message here") .IsMinValue(long.MinValue, "Long") .IsMinValue(long.MinValue, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Long Validation")] [TestMethod("Requires a long has not its min value")] public void RequireLongHasNotItsMinValue() { var contract = new Contract() .Requires() .IsNotMinValue(long.MaxValue, "Long") .IsNotMinValue(long.MaxValue, "Long", "Custom message here") .IsNotMinValue(long.MinValue, "Long") .IsNotMinValue(long.MinValue, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Long Validation")] [TestMethod("Requires a long has its max value")] public void RequireLongHasItsMaxValue() { var contract = new Contract() .Requires() .IsMaxValue(long.MaxValue, "Long") .IsMaxValue(long.MaxValue, "Long", "Custom message here") .IsMaxValue(long.MinValue, "Long") .IsMaxValue(long.MinValue, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Long Validation")] [TestMethod("Requires a long has not its max value")] public void RequireLongHasNotItsMaxValue() { var contract = new Contract() .Requires() .IsNotMaxValue(long.MaxValue, "Long") .IsNotMaxValue(long.MaxValue, "Long", "Custom message here") .IsNotMaxValue(long.MinValue, "Long") .IsNotMaxValue(long.MinValue, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Long Validation")] [TestMethod("Requires two longs are equals")] public void RequireTwoLongsAreEquals() { var contract = new Contract() .Requires() .AreEquals((long)0, (int)0, "Long") .AreEquals((long)0, (int)0, "Long", "Custom message here") .AreEquals((long)0, (int)10, "Long") .AreEquals((long)0, (int)10, "Long", "Custom message here") .AreEquals((long)0, (float)0, "Long") .AreEquals((long)0, (float)0, "Long", "Custom message here") .AreEquals((long)0, (float)10, "Long") .AreEquals((long)0, (float)10, "Long", "Custom message here") .AreEquals((long)0, (double)0, "Long") .AreEquals((long)0, (double)0, "Long", "Custom message here") .AreEquals((long)0, (double)10, "Long") .AreEquals((long)0, (double)10, "Long", "Custom message here") .AreEquals((long)0, (long)0, "Long") .AreEquals((long)0, (long)0, "Long", "Custom message here") .AreEquals((long)0, (long)10, "Long") .AreEquals((long)0, (long)10, "Long", "Custom message here") .AreEquals((long)0, (decimal)0, "Long") .AreEquals((long)0, (decimal)0, "Long", "Custom message here") .AreEquals((long)0, (decimal)10, "Long") .AreEquals((long)0, (decimal)10, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Long Validation")] [TestMethod("Requires two longs are not equals")] public void RequireTwoLongsAreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals((long)0, (int)0, "Long") .AreNotEquals((long)0, (int)0, "Long", "Custom message here") .AreNotEquals((long)0, (int)10, "Long") .AreNotEquals((long)0, (int)10, "Long", "Custom message here") .AreNotEquals((long)0, (float)0, "Long") .AreNotEquals((long)0, (float)0, "Long", "Custom message here") .AreNotEquals((long)0, (float)10, "Long") .AreNotEquals((long)0, (float)10, "Long", "Custom message here") .AreNotEquals((long)0, (double)0, "Long") .AreNotEquals((long)0, (double)0, "Long", "Custom message here") .AreNotEquals((long)0, (double)10, "Long") .AreNotEquals((long)0, (double)10, "Long", "Custom message here") .AreNotEquals((long)0, (long)0, "Long") .AreNotEquals((long)0, (long)0, "Long", "Custom message here") .AreNotEquals((long)0, (long)10, "Long") .AreNotEquals((long)0, (long)10, "Long", "Custom message here") .AreNotEquals((long)0, (decimal)0, "Long") .AreNotEquals((long)0, (decimal)0, "Long", "Custom message here") .AreNotEquals((long)0, (decimal)10, "Long") .AreNotEquals((long)0, (decimal)10, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Long Validation")] [TestMethod("Requires a long is null")] public void RequiresLongIsNull() { var contract = new Contract() .Requires() .IsNull(_entity.LongNull, "Long") .IsNull(_entity.LongNull, "Long", "Custom message here") .IsNull(_entity.LongStart, "Long") .IsNull(_entity.LongStart, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Long Validation")] [TestMethod("Requires a long is not null")] public void RequiresLongIsNotNull() { var contract = new Contract() .Requires() .IsNotNull(_entity.LongNull, "Long") .IsNotNull(_entity.LongNull, "Long", "Custom message here") .IsNotNull(_entity.LongStart, "Long") .IsNotNull(_entity.LongStart, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Long Validation")] [TestMethod("Requires a long is between")] public void RequiresLongIsBetween() { var contract = new Contract() .Requires() .IsBetween(_entity.LongBetweenStartAndEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long") .IsBetween(_entity.LongBetweenStartAndEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongStart, (int)_entity.LongStart, (int)_entity.LongEnd, "Long") .IsBetween(_entity.LongStart, (int)_entity.LongStart, (int)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long") .IsBetween(_entity.LongEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongNotBetweenStartAndEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long") .IsBetween(_entity.LongNotBetweenStartAndEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongBetweenStartAndEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long") .IsBetween(_entity.LongBetweenStartAndEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongStart, (double)_entity.LongStart, (double)_entity.LongEnd, "Long") .IsBetween(_entity.LongStart, (double)_entity.LongStart, (double)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long") .IsBetween(_entity.LongEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongNotBetweenStartAndEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long") .IsBetween(_entity.LongNotBetweenStartAndEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongBetweenStartAndEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long") .IsBetween(_entity.LongBetweenStartAndEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongStart, (float)_entity.LongStart, (float)_entity.LongEnd, "Long") .IsBetween(_entity.LongStart, (float)_entity.LongStart, (float)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long") .IsBetween(_entity.LongEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongNotBetweenStartAndEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long") .IsBetween(_entity.LongNotBetweenStartAndEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongBetweenStartAndEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long") .IsBetween(_entity.LongBetweenStartAndEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongStart, (long)_entity.LongStart, (long)_entity.LongEnd, "Long") .IsBetween(_entity.LongStart, (long)_entity.LongStart, (long)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long") .IsBetween(_entity.LongEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongNotBetweenStartAndEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long") .IsBetween(_entity.LongNotBetweenStartAndEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongBetweenStartAndEnd, _entity.LongStart, _entity.LongEnd, "Long") .IsBetween(_entity.LongBetweenStartAndEnd, _entity.LongStart, _entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongStart, _entity.LongStart, _entity.LongEnd, "Long") .IsBetween(_entity.LongStart, _entity.LongStart, _entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongEnd, _entity.LongStart, _entity.LongEnd, "Long") .IsBetween(_entity.LongEnd, _entity.LongStart, _entity.LongEnd, "Long", "Custom message here") .IsBetween(_entity.LongNotBetweenStartAndEnd, _entity.LongStart, _entity.LongEnd, "Long") .IsBetween(_entity.LongNotBetweenStartAndEnd, _entity.LongStart, _entity.LongEnd, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("Long Validation")] [TestMethod("Requires a long is not between")] public void RequiresLongIsNotBetween() { var contract = new Contract() .Requires() .IsNotBetween(_entity.LongBetweenStartAndEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongBetweenStartAndEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongStart, (int)_entity.LongStart, (int)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongStart, (int)_entity.LongStart, (int)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, (int)_entity.LongStart, (int)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongBetweenStartAndEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongBetweenStartAndEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongStart, (double)_entity.LongStart, (double)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongStart, (double)_entity.LongStart, (double)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, (double)_entity.LongStart, (double)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongBetweenStartAndEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongBetweenStartAndEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongStart, (float)_entity.LongStart, (float)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongStart, (float)_entity.LongStart, (float)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, (float)_entity.LongStart, (float)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongBetweenStartAndEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongBetweenStartAndEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongStart, (long)_entity.LongStart, (long)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongStart, (long)_entity.LongStart, (long)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, (long)_entity.LongStart, (long)_entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongBetweenStartAndEnd, _entity.LongStart, _entity.LongEnd, "Long") .IsNotBetween(_entity.LongBetweenStartAndEnd, _entity.LongStart, _entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongStart, _entity.LongStart, _entity.LongEnd, "Long") .IsNotBetween(_entity.LongStart, _entity.LongStart, _entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongEnd, _entity.LongStart, _entity.LongEnd, "Long") .IsNotBetween(_entity.LongEnd, _entity.LongStart, _entity.LongEnd, "Long", "Custom message here") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, _entity.LongStart, _entity.LongEnd, "Long") .IsNotBetween(_entity.LongNotBetweenStartAndEnd, _entity.LongStart, _entity.LongEnd, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 30); } [TestCategory("Long Validation")] [TestMethod("Requires a list contains a long")] public void RequiresListContainsLong() { var contract = new Contract() .Requires() .Contains((long)1, _entity.LongList, "Long") .Contains((long)1, _entity.LongList, "Long", "Custom message here") .Contains((long)3, _entity.LongList, "Long") .Contains((long)3, _entity.LongList, "Long", "Custom message here") .Contains((long)5, _entity.LongList, "Long") .Contains((long)5, _entity.LongList, "Long", "Custom message here") .Contains((long)7, _entity.LongList, "Long") .Contains((long)7, _entity.LongList, "Long", "Custom message here") .Contains((long)9, _entity.LongList, "Long") .Contains((long)9, _entity.LongList, "Long", "Custom message here") .Contains((long)11, _entity.LongList, "Long") .Contains((long)11, _entity.LongList, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Long Validation")] [TestMethod("Requires a list does not contains a long")] public void RequiresListNotContainsDouble() { var contract = new Contract() .Requires() .NotContains((long)1, _entity.LongList, "Long") .NotContains((long)1, _entity.LongList, "Long", "Custom message here") .NotContains((long)3, _entity.LongList, "Long") .NotContains((long)3, _entity.LongList, "Long", "Custom message here") .NotContains((long)5, _entity.LongList, "Long") .NotContains((long)5, _entity.LongList, "Long", "Custom message here") .NotContains((long)7, _entity.LongList, "Long") .NotContains((long)7, _entity.LongList, "Long", "Custom message here") .NotContains((long)9, _entity.LongList, "Long") .NotContains((long)9, _entity.LongList, "Long", "Custom message here") .NotContains((long)11, _entity.LongList, "Long") .NotContains((long)11, _entity.LongList, "Long", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } } } ================================================ FILE: Flunt.Tests/ObjectValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class ObjectValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("Object Validation")] [TestMethod("Requires an object is null")] public void IsNull() { var contract = new Contract() .Requires() .IsNull(_entity.ObjectNull, "Object") .IsNull(_entity.ObjectNull, "Object", "Custom error message") .IsNull(_entity.ObjectToCompare, "Object") .IsNull(_entity.ObjectToCompare, "Object", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Object Validation")] [TestMethod("Requires an object is not null")] public void IsNotNull() { var contract = new Contract() .Requires() .IsNotNull(_entity.ObjectNull, "Object") .IsNotNull(_entity.ObjectNull, "Object", "Custom error message") .IsNotNull(_entity.ObjectToCompare, "Object") .IsNotNull(_entity.ObjectToCompare, "Object", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Object Validation")] [TestMethod("Requires two objects are equals")] public void AreEquals() { var contract = new Contract() .Requires() .AreEquals(_entity.ObjectNull, _entity.ObjectToCompare, "Object") .AreEquals(_entity.ObjectNull, _entity.ObjectToCompare, "Object", "Custom error message") .AreEquals(_entity.ObjectToCompare, _entity.ObjectAnotherToCompare, "Object") .AreEquals(_entity.ObjectToCompare, _entity.ObjectAnotherToCompare, "Object", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Object Validation")] [TestMethod("Requires two objects are not equals")] public void AreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals(_entity.ObjectNull, _entity.ObjectToCompare, "Object") .AreNotEquals(_entity.ObjectNull, _entity.ObjectToCompare, "Object", "Custom error message") .AreNotEquals(_entity.ObjectToCompare, _entity.ObjectAnotherToCompare, "Object") .AreNotEquals(_entity.ObjectToCompare, _entity.ObjectAnotherToCompare, "Object", "Custom error message"); Assert.AreEqual(true, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 0); } } } ================================================ FILE: Flunt.Tests/RegexValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class RegexValidationTests { [TestCategory("Regex Validation")] [TestMethod("Requires a string matches a pattern")] public void Matches() { var contract = new Contract() .Requires() // Invalid .Matches("ABC012345", @"[^0-9]+", "Regex") .Matches("ABC012345", @"[^0-9]+", "Regex", "Custom error message") // VALID .Matches("012345", @"[^0-9]+", "Regex") .Matches("012345", @"[^0-9]+", "Regex", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("Regex Validation")] [TestMethod("Requires a string not matches a pattern")] public void NotMatches() { var contract = new Contract() .Requires() // VALID .NotMatches("ABC012345", @"[^0-9]+", "Regex") .NotMatches("ABC012345", @"[^0-9]+", "Regex", "Custom error message") // INVALID .NotMatches("012345", @"[^0-9]+", "Regex") .NotMatches("012345", @"[^0-9]+", "Regex", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } } } ================================================ FILE: Flunt.Tests/StringValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class StringValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("String Validation")] [TestMethod("Requires a string is null")] public void IsNull() { var contract = new Contract() .Requires() .IsNull(_entity.StringEmpty, "String") .IsNull(_entity.StringEmpty, "String", "Custom error message") .IsNull(_entity.StringNotEmpty, "String") .IsNull(_entity.StringNotEmpty, "String", "Custom error message") .IsNull(_entity.StringNull, "String") .IsNull(_entity.StringNull, "String", "Custom error message") .IsNull(_entity.StringWhiteSpace, "String") .IsNull(_entity.StringWhiteSpace, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 6); } [TestCategory("String Validation")] [TestMethod("Requires a string is not null")] public void IsNotNull() { var contract = new Contract() .Requires() .IsNotNull(_entity.StringEmpty, "String") .IsNotNull(_entity.StringEmpty, "String", "Custom error message") .IsNotNull(_entity.StringNotEmpty, "String") .IsNotNull(_entity.StringNotEmpty, "String", "Custom error message") .IsNotNull(_entity.StringNull, "String") .IsNotNull(_entity.StringNull, "String", "Custom error message") .IsNotNull(_entity.StringWhiteSpace, "String") .IsNotNull(_entity.StringWhiteSpace, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("String Validation")] [TestMethod("Requires a string is null or empty")] public void IsNullOrEmpty() { var contract = new Contract() .Requires() .IsNullOrEmpty(_entity.StringEmpty, "String") .IsNullOrEmpty(_entity.StringEmpty, "String", "Custom error message") .IsNullOrEmpty(_entity.StringNotEmpty, "String") .IsNullOrEmpty(_entity.StringNotEmpty, "String", "Custom error message") .IsNullOrEmpty(_entity.StringNull, "String") .IsNullOrEmpty(_entity.StringNull, "String", "Custom error message") .IsNullOrEmpty(_entity.StringWhiteSpace, "String") .IsNullOrEmpty(_entity.StringWhiteSpace, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 4); } [TestCategory("String Validation")] [TestMethod("Requires a string is not null or empty")] public void IsNotNullOrEmpty() { var contract = new Contract() .Requires() .IsNotNullOrEmpty(_entity.StringEmpty, "String") .IsNotNullOrEmpty(_entity.StringEmpty, "String", "Custom error message") .IsNotNullOrEmpty(_entity.StringNotEmpty, "String") .IsNotNullOrEmpty(_entity.StringNotEmpty, "String", "Custom error message") .IsNotNullOrEmpty(_entity.StringNull, "String") .IsNotNullOrEmpty(_entity.StringNull, "String", "Custom error message") .IsNotNullOrEmpty(_entity.StringWhiteSpace, "String") .IsNotNullOrEmpty(_entity.StringWhiteSpace, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 4); } [TestCategory("String Validation")] [TestMethod("Requires a string is null or white space")] public void IsNullOrWhiteSpace() { var contract = new Contract() .Requires() .IsNullOrWhiteSpace(_entity.StringEmpty, "String") .IsNullOrWhiteSpace(_entity.StringEmpty, "String", "Custom error message") .IsNullOrWhiteSpace(_entity.StringNotEmpty, "String") .IsNullOrWhiteSpace(_entity.StringNotEmpty, "String", "Custom error message") .IsNullOrWhiteSpace(_entity.StringNull, "String") .IsNullOrWhiteSpace(_entity.StringNull, "String", "Custom error message") .IsNullOrWhiteSpace(_entity.StringWhiteSpace, "String") .IsNullOrWhiteSpace(_entity.StringWhiteSpace, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("String Validation")] [TestMethod("Requires a string is not null or white space")] public void IsNotNullOrWhiteSpace() { var contract = new Contract() .Requires() .IsNotNullOrWhiteSpace(_entity.StringEmpty, "String") .IsNotNullOrWhiteSpace(_entity.StringEmpty, "String", "Custom error message") .IsNotNullOrWhiteSpace(_entity.StringNotEmpty, "String") .IsNotNullOrWhiteSpace(_entity.StringNotEmpty, "String", "Custom error message") .IsNotNullOrWhiteSpace(_entity.StringNull, "String") .IsNotNullOrWhiteSpace(_entity.StringNull, "String", "Custom error message") .IsNotNullOrWhiteSpace(_entity.StringWhiteSpace, "String") .IsNotNullOrWhiteSpace(_entity.StringWhiteSpace, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 6); } [TestCategory("String Validation")] [TestMethod("Requires two strings are equals")] public void AreEquals() { var contract = new Contract() .Requires() .AreEquals(_entity.StringEmpty, string.Empty, "String") .AreEquals(_entity.StringEmpty, string.Empty, "String", "Custom error message") .AreEquals(_entity.StringNotEmpty, "RandomString", "String") .AreEquals(_entity.StringNotEmpty, "RandomString", "String", "Custom error message") .AreEquals(_entity.StringNull, null, "String") .AreEquals(_entity.StringNull, null, "String", "Custom error message") .AreEquals(_entity.StringWhiteSpace, " ", "String") .AreEquals(_entity.StringWhiteSpace, " ", "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("String Validation")] [TestMethod("Requires two strings are not equals")] public void AreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals(_entity.StringEmpty, string.Empty, "String") .AreNotEquals(_entity.StringEmpty, string.Empty, "String", "Custom error message") .AreNotEquals(_entity.StringNotEmpty, "RandomString", "String") .AreNotEquals(_entity.StringNotEmpty, "RandomString", "String", "Custom error message") .AreNotEquals(_entity.StringNull, null, "String") .AreNotEquals(_entity.StringNull, null, "String", "Custom error message") .AreNotEquals(_entity.StringWhiteSpace, " ", "String") .AreNotEquals(_entity.StringWhiteSpace, " ", "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 6); } [TestCategory("String Validation")] [TestMethod("Requires a string contains a value")] public void Contains() { var contract = new Contract() .Requires() .Contains(_entity.StringEmpty, "value", "String") .Contains(_entity.StringEmpty, "value", "String", "Custom error message") .Contains(_entity.StringNotEmpty, "value", "String") .Contains(_entity.StringNotEmpty, "value", "String", "Custom error message") .Contains(_entity.StringNull, "value", "String") .Contains(_entity.StringNull, "value", "String", "Custom error message") .Contains(_entity.StringWhiteSpace, "value", "String") .Contains(_entity.StringWhiteSpace, "value", "String", "Custom error message") .Contains(_entity.StringNotEmpty, "some", "String") .Contains(_entity.StringNotEmpty, "some", "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 8); } [TestCategory("String Validation")] [TestMethod("Requires a string not contains a value")] public void NotContains() { var contract = new Contract() .Requires() .NotContains(_entity.StringEmpty, "value", "String") .NotContains(_entity.StringEmpty, "value", "String", "Custom error message") .NotContains(_entity.StringNotEmpty, "value", "String") .NotContains(_entity.StringNotEmpty, "value", "String", "Custom error message") .NotContains(_entity.StringNull, "value", "String") .NotContains(_entity.StringNull, "value", "String", "Custom error message") .NotContains(_entity.StringWhiteSpace, "value", "String") .NotContains(_entity.StringWhiteSpace, "value", "String", "Custom error message") .NotContains(_entity.StringNotEmpty, "some", "String") .NotContains(_entity.StringNotEmpty, "some", "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("String Validation")] [TestMethod("Requires a string len is greater than")] public void IsGreaterThan() { var contract = new Contract() .Requires() .IsGreaterThan(_entity.StringEmpty, 5, "String") .IsGreaterThan(_entity.StringEmpty, 5, "String", "Custom error message") .IsGreaterThan(_entity.StringFiveCharsLong, 5, "String") .IsGreaterThan(_entity.StringFiveCharsLong, 5, "String", "Custom error message") .IsGreaterThan(_entity.StringNull, 5, "String") .IsGreaterThan(_entity.StringNull, 5, "String", "Custom error message") .IsGreaterThan(_entity.StringWhiteSpace, 5, "String") .IsGreaterThan(_entity.StringWhiteSpace, 5, "String", "Custom error message") .IsGreaterThan(_entity.StringNotEmpty, 3, "String") .IsGreaterThan(_entity.StringNotEmpty, 3, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 6); } [TestCategory("String Validation")] [TestMethod("Requires a string len is greater or equals than")] public void IsGreaterOrEqualsThan() { var contract = new Contract() .Requires() .IsGreaterOrEqualsThan(_entity.StringEmpty, 5, "String") .IsGreaterOrEqualsThan(_entity.StringEmpty, 5, "String", "Custom error message") .IsGreaterOrEqualsThan(_entity.StringFiveCharsLong, 5, "String") .IsGreaterOrEqualsThan(_entity.StringFiveCharsLong, 5, "String", "Custom error message") .IsGreaterOrEqualsThan(_entity.StringNull, 5, "String") .IsGreaterOrEqualsThan(_entity.StringNull, 5, "String", "Custom error message") .IsGreaterOrEqualsThan(_entity.StringWhiteSpace, 5, "String") .IsGreaterOrEqualsThan(_entity.StringWhiteSpace, 5, "String", "Custom error message") .IsGreaterOrEqualsThan(_entity.StringNotEmpty, 3, "String") .IsGreaterOrEqualsThan(_entity.StringNotEmpty, 3, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 4); } [TestCategory("String Validation")] [TestMethod("Requires a string len is lower than")] public void IsLowerThan() { var contract = new Contract() .Requires() .IsLowerThan(_entity.StringEmpty, 5, "String") .IsLowerThan(_entity.StringEmpty, 5, "String", "Custom error message") .IsLowerThan(_entity.StringFiveCharsLong, 5, "String") .IsLowerThan(_entity.StringFiveCharsLong, 5, "String", "Custom error message") .IsLowerThan(_entity.StringNull, 5, "String") .IsLowerThan(_entity.StringNull, 5, "String", "Custom error message") .IsLowerThan(_entity.StringWhiteSpace, 5, "String") .IsLowerThan(_entity.StringWhiteSpace, 5, "String", "Custom error message") .IsLowerThan(_entity.StringNotEmpty, 3, "String") .IsLowerThan(_entity.StringNotEmpty, 3, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 4); } [TestCategory("String Validation")] [TestMethod("Requires a string len is lower or equals than")] public void IsLowerOrEqualsThan() { var contract = new Contract() .Requires() .IsLowerOrEqualsThan(_entity.StringEmpty, 5, "String") .IsLowerOrEqualsThan(_entity.StringEmpty, 5, "String", "Custom error message") .IsLowerOrEqualsThan(_entity.StringFiveCharsLong, 5, "String") .IsLowerOrEqualsThan(_entity.StringFiveCharsLong, 5, "String", "Custom error message") .IsLowerOrEqualsThan(_entity.StringNull, 5, "String") .IsLowerOrEqualsThan(_entity.StringNull, 5, "String", "Custom error message") .IsLowerOrEqualsThan(_entity.StringWhiteSpace, 5, "String") .IsLowerOrEqualsThan(_entity.StringWhiteSpace, 5, "String", "Custom error message") .IsLowerOrEqualsThan(_entity.StringNotEmpty, 3, "String") .IsLowerOrEqualsThan(_entity.StringNotEmpty, 3, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("String Validation")] [TestMethod("Requires a string have a specific len")] public void AreEqualsLen() { var contract = new Contract() .Requires() .AreEquals(_entity.StringEmpty, 5, "String") .AreEquals(_entity.StringEmpty, 5, "String", "Custom error message") .AreEquals(_entity.StringFiveCharsLong, 5, "String") .AreEquals(_entity.StringFiveCharsLong, 5, "String", "Custom error message") .AreEquals(_entity.StringNull, 5, "String") .AreEquals(_entity.StringNull, 5, "String", "Custom error message") .AreEquals(_entity.StringWhiteSpace, 5, "String") .AreEquals(_entity.StringWhiteSpace, 5, "String", "Custom error message") .AreEquals(_entity.StringNotEmpty, 3, "String") .AreEquals(_entity.StringNotEmpty, 3, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 6); } [TestCategory("String Validation")] [TestMethod("Requires a string do not have a specific len")] public void AreNotEqualsLen() { var contract = new Contract() .Requires() .AreNotEquals(_entity.StringEmpty, 5, "String") .AreNotEquals(_entity.StringEmpty, 5, "String", "Custom error message") .AreNotEquals(_entity.StringFiveCharsLong, 5, "String") .AreNotEquals(_entity.StringFiveCharsLong, 5, "String", "Custom error message") .AreNotEquals(_entity.StringNull, 5, "String") .AreNotEquals(_entity.StringNull, 5, "String", "Custom error message") .AreNotEquals(_entity.StringWhiteSpace, 5, "String") .AreNotEquals(_entity.StringWhiteSpace, 5, "String", "Custom error message") .AreNotEquals(_entity.StringNotEmpty, 3, "String") .AreNotEquals(_entity.StringNotEmpty, 3, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("String Validation")] [TestMethod("requires string len to be in a range")] public void IsBetween() { var contract = new Contract() .Requires() .IsBetween(_entity.StringEmpty, 5, 10, "String", "Custom error message") .IsBetween(_entity.StringFiveCharsLong, 6, 10, "String", "Custom error message") .IsBetween(_entity.StringNull, 5, 10, "String", "Custom error message") .IsBetween(_entity.StringWhiteSpace, 5, 10, "String", "Custom error message") .IsBetween(_entity.StringNotEmpty, 3, 10, "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } } } ================================================ FILE: Flunt.Tests/TimeSpanValidationTests.cs ================================================ using System; using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class TimeSpanValidationTests { private readonly SampleEntity _entity = new SampleEntity(); [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is greater than")] public void RequiresDateIsGreaterThan() { var contract = new Contract() .Requires() .IsGreaterThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterThanNow, "TimeSpan") .IsGreaterThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterThanNow, "TimeSpan", "Custom message here") .IsGreaterThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerThanNow, "TimeSpan") .IsGreaterThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerThanNow, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is greater or equals than")] public void RequiresDateIsGreaterOrEqualsThan() { var contract = new Contract() .Requires() .IsGreaterOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterOrEqualsThanNow, "TimeSpan") .IsGreaterOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterOrEqualsThanNow, "TimeSpan", "Custom message here") .IsGreaterOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterThanNow, "TimeSpan") .IsGreaterOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterThanNow, "TimeSpan", "Custom message here") .IsGreaterOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerThanNow, "TimeSpan") .IsGreaterOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerThanNow, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is lower than")] public void RequiresDateIsLowerThan() { var contract = new Contract() .Requires() .IsLowerThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerThanNow, "TimeSpan") .IsLowerThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerThanNow, "TimeSpan", "Custom message here") .IsLowerThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterThanNow, "TimeSpan") .IsLowerThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterThanNow, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is lower or equals than")] public void RequiresDateIsLowerOrEqualsThan() { var contract = new Contract() .Requires() .IsLowerOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerOrEqualsThanNow, "TimeSpan") .IsLowerOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerOrEqualsThanNow, "TimeSpan", "Custom message here") .IsLowerOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerThanNow, "TimeSpan") .IsLowerOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanLowerThanNow, "TimeSpan", "Custom message here") .IsLowerOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterThanNow, "TimeSpan") .IsLowerOrEqualsThan(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanGreaterThanNow, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is not null")] public void RequiresDateIsNotNull() { var contract = new Contract() .Requires() .IsNotNull(SampleEntity.TimeSpanSnapshot, "TimeSpan") .IsNotNull(SampleEntity.TimeSpanSnapshot, "TimeSpan", "Custom message here") .IsNotNull(_entity.TimeSpanNull, "TimeSpan") .IsNotNull(_entity.TimeSpanNull, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is null")] public void RequiresDateIsNull() { var contract = new Contract() .Requires() .IsNull(SampleEntity.TimeSpanSnapshot, "TimeSpan") .IsNull(SampleEntity.TimeSpanSnapshot, "TimeSpan", "Custom message here") .IsNull(_entity.TimeSpanNull, "TimeSpan") .IsNull(_entity.TimeSpanNull, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is between")] public void RequiresDateIsBetween() { var contract = new Contract() .Requires() .IsBetween(_entity.TimeSpanBetweenStartAndEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") .IsBetween(_entity.TimeSpanBetweenStartAndEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan", "Custom message here") // TimeSpan = StartDate will be consider between .IsBetween(_entity.TimeSpanStartDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") // TimeSpan = EndDate will be consider between .IsBetween(_entity.TimeSpanEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") .IsBetween(_entity.TimeSpanNotBetweenStartAndEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") .IsBetween(_entity.TimeSpanNotBetweenStartAndEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is not between")] public void RequiresDateIsNotBetween() { var contract = new Contract() .Requires() .IsNotBetween(_entity.TimeSpanNotBetweenStartAndEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") .IsNotBetween(_entity.TimeSpanNotBetweenStartAndEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan", "Custom message here") // TimeSpan = StartDate will be consider not between .IsBetween(_entity.TimeSpanStartDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") // TimeSpan = EndDate will be consider not between .IsBetween(_entity.TimeSpanEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") .IsNotBetween(_entity.TimeSpanBetweenStartAndEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") .IsNotBetween(_entity.TimeSpanBetweenStartAndEndDate, _entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is min value")] public void RequiresDateHaveMinValue() { var contract = new Contract() .Requires() .IsMinValue(TimeSpan.MaxValue, "TimeSpan") .IsMinValue(TimeSpan.MaxValue, "TimeSpan", "Custom message here") .IsMinValue(TimeSpan.MinValue, "TimeSpan") .IsMinValue(TimeSpan.MinValue, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is not min value")] public void RequiresDateDoNotHaveMinValue() { var contract = new Contract() .Requires() .IsNotMinValue(TimeSpan.MaxValue, "TimeSpan") .IsNotMinValue(TimeSpan.MaxValue, "TimeSpan", "Custom message here") .IsNotMinValue(TimeSpan.MinValue, "TimeSpan") .IsNotMinValue(TimeSpan.MinValue, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is max value")] public void RequiresDateHaveMaxValue() { var contract = new Contract() .Requires() .IsMaxValue(TimeSpan.MaxValue, "TimeSpan") .IsMaxValue(TimeSpan.MaxValue, "TimeSpan", "Custom message here") .IsMaxValue(TimeSpan.MinValue, "TimeSpan") .IsMaxValue(TimeSpan.MinValue, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a date is not max value")] public void RequiresDateDoNotHaveMaxValue() { var contract = new Contract() .Requires() .IsNotMaxValue(TimeSpan.MaxValue, "TimeSpan") .IsNotMaxValue(TimeSpan.MaxValue, "TimeSpan", "Custom message here") .IsNotMaxValue(TimeSpan.MinValue, "TimeSpan") .IsNotMaxValue(TimeSpan.MinValue, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires two dates are equals")] public void RequiresDatesAreEquals() { var contract = new Contract() .Requires() .AreEquals(_entity.TimeSpanStartDate, _entity.TimeSpanStartDate, "TimeSpan") .AreEquals(_entity.TimeSpanStartDate, _entity.TimeSpanStartDate, "TimeSpan", "Custom message here") .AreEquals(_entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") .AreEquals(_entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires two dates are not equals")] public void RequiresDatesAreNotEquals() { var contract = new Contract() .Requires() .AreNotEquals(_entity.TimeSpanStartDate, _entity.TimeSpanStartDate, "TimeSpan") .AreNotEquals(_entity.TimeSpanStartDate, _entity.TimeSpanStartDate, "TimeSpan", "Custom message here") .AreNotEquals(_entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan") .AreNotEquals(_entity.TimeSpanStartDate, _entity.TimeSpanEndDate, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a list contains a date")] public void RequiresListContainsDate() { var contract = new Contract() .Requires() .Contains(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanList, "TimeSpan") .Contains(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanList, "TimeSpan", "Custom message here") .Contains(_entity.TimeSpanEndDate, _entity.TimeSpanList, "TimeSpan") .Contains(_entity.TimeSpanEndDate, _entity.TimeSpanList, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } [TestCategory("TimeSpan Validation")] [TestMethod("Requires a list not contains a date")] public void RequiresListNotContainsDate() { var contract = new Contract() .Requires() .NotContains(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanList, "TimeSpan") .NotContains(SampleEntity.TimeSpanSnapshot, _entity.TimeSpanList, "TimeSpan", "Custom message here") .NotContains(_entity.TimeSpanEndDate, _entity.TimeSpanList, "TimeSpan") .NotContains(_entity.TimeSpanEndDate, _entity.TimeSpanList, "TimeSpan", "Custom message here"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 2); } } } ================================================ FILE: Flunt.Tests/UrlValidationTests.cs ================================================ using Flunt.Tests.Entities; using Flunt.Validations; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Flunt.Tests { [TestClass] public class UrlValidationTests { [TestCategory("URL Validation")] [TestMethod("Requires a string is an URL")] public void IsUrl() { var contract = new Contract() .Requires() .IsUrl("http://balta.io", "String") .IsUrl("http://balta.io", "String", "Custom error message") .IsUrl("https://balta.io", "String") .IsUrl("https://balta.io", "String", "Custom error message") .IsUrl("balta.io", "String") .IsUrl("balta.io", "String", "Custom error message") .IsUrl("none", "String") .IsUrl("none", "String", "Custom error message") .IsUrl(null, "String") .IsUrl(null, "String", "Custom error message") .IsUrl(string.Empty, "String") .IsUrl(string.Empty, "String", "Custom error message") .IsUrl(" ", "String") .IsUrl(" ", "String", "Custom error message") .IsUrl("http://localhost:1000", "String") .IsUrl("http://localhost:1000", "String", "Custom error message") .IsUrl("localhost:1000", "String") .IsUrl("localhost:1000", "String", "Custom error message") .IsUrl("https://127.0.0.1:10000", "String") .IsUrl("https://127.0.0.1:10000", "String", "Custom error message") .IsUrl("127.0.0.1:10000", "String") .IsUrl("127.0.0.1:10000", "String", "Custom error message") .IsUrl("https://127.0.256.1:10000", "String") .IsUrl("https://127.0.256.1:10000", "String", "Custom error message") .IsUrl("127.0.256.1:10000", "String") .IsUrl("127.0.256.1:10000", "String", "Custom error message") .IsUrl("http://127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String") .IsUrl("http://127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String", "Custom error message") .IsUrl("127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String") .IsUrl("127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 20); } [TestCategory("URL Validation")] [TestMethod("Requires a string is an URL or is empty")] public void IsUrlOrEmpty() { var contract = new Contract() .Requires() .IsUrlOrEmpty("http://balta.io", "String") .IsUrlOrEmpty("http://balta.io", "String", "Custom error message") .IsUrlOrEmpty("https://balta.io", "String") .IsUrlOrEmpty("https://balta.io", "String", "Custom error message") .IsUrlOrEmpty("balta.io", "String") .IsUrlOrEmpty("balta.io", "String", "Custom error message") .IsUrlOrEmpty("none", "String") .IsUrlOrEmpty("none", "String", "Custom error message") .IsUrlOrEmpty(null, "String") .IsUrlOrEmpty(null, "String", "Custom error message") .IsUrlOrEmpty(string.Empty, "String") .IsUrlOrEmpty(string.Empty, "String", "Custom error message") .IsUrlOrEmpty(" ", "String") .IsUrlOrEmpty(" ", "String", "Custom error message") .IsUrlOrEmpty("http://localhost:1000", "String") .IsUrlOrEmpty("http://localhost:1000", "String", "Custom error message") .IsUrlOrEmpty("localhost:1000", "String") .IsUrlOrEmpty("localhost:1000", "String", "Custom error message") .IsUrlOrEmpty("https://127.0.0.1:10000", "String") .IsUrlOrEmpty("https://127.0.0.1:10000", "String", "Custom error message") .IsUrlOrEmpty("127.0.0.1:10000", "String") .IsUrlOrEmpty("127.0.0.1:10000", "String", "Custom error message") .IsUrlOrEmpty("https://127.0.256.1:10000", "String") .IsUrlOrEmpty("https://127.0.256.1:10000", "String", "Custom error message") .IsUrlOrEmpty("127.0.256.1:10000", "String") .IsUrlOrEmpty("127.0.256.1:10000", "String", "Custom error message") .IsUrlOrEmpty("http://127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String") .IsUrlOrEmpty("http://127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String", "Custom error message") .IsUrlOrEmpty("127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String") .IsUrlOrEmpty("127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 16); } [TestCategory("URL Validation")] [TestMethod("Requires a string is not an URL")] public void IsNotUrl() { var contract = new Contract() .Requires() .IsNotUrl("http://balta.io", "String") .IsNotUrl("http://balta.io", "String", "Custom error message") .IsNotUrl("https://balta.io", "String") .IsNotUrl("https://balta.io", "String", "Custom error message") .IsNotUrl("balta.io", "String") .IsNotUrl("balta.io", "String", "Custom error message") .IsNotUrl("none", "String") .IsNotUrl("none", "String", "Custom error message") .IsNotUrl(null, "String") .IsNotUrl(null, "String", "Custom error message") .IsNotUrl(string.Empty, "String") .IsNotUrl(string.Empty, "String", "Custom error message") .IsNotUrl(" ", "String") .IsNotUrl(" ", "String", "Custom error message") .IsNotUrl("http://localhost:1000", "String") .IsNotUrl("http://localhost:1000", "String", "Custom error message") .IsNotUrl("localhost:1000", "String") .IsNotUrl("localhost:1000", "String", "Custom error message") .IsNotUrl("https://127.0.0.1:10000", "String") .IsNotUrl("https://127.0.0.1:10000", "String", "Custom error message") .IsNotUrl("127.0.0.1:10000", "String") .IsNotUrl("127.0.0.1:10000", "String", "Custom error message") .IsNotUrl("https://127.0.256.1:10000", "String") .IsNotUrl("https://127.0.256.1:10000", "String", "Custom error message") .IsNotUrl("127.0.256.1:10000", "String") .IsNotUrl("127.0.256.1:10000", "String", "Custom error message") .IsNotUrl("http://127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String") .IsNotUrl("http://127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String", "Custom error message") .IsNotUrl("127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String") .IsNotUrl("127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } [TestCategory("URL Validation")] [TestMethod("Requires a string is not an URL or is empty")] public void IsNotUrlOrEmpty() { var contract = new Contract() .Requires() .IsNotUrlOrEmpty("http://balta.io", "String") .IsNotUrlOrEmpty("http://balta.io", "String", "Custom error message") .IsNotUrlOrEmpty("https://balta.io", "String") .IsNotUrlOrEmpty("https://balta.io", "String", "Custom error message") .IsNotUrlOrEmpty("balta.io", "String") .IsNotUrlOrEmpty("balta.io", "String", "Custom error message") .IsNotUrlOrEmpty("none", "String") .IsNotUrlOrEmpty("none", "String", "Custom error message") .IsNotUrlOrEmpty(null, "String") .IsNotUrlOrEmpty(null, "String", "Custom error message") .IsNotUrlOrEmpty(string.Empty, "String") .IsNotUrlOrEmpty(string.Empty, "String", "Custom error message") .IsNotUrlOrEmpty(" ", "String") .IsNotUrlOrEmpty(" ", "String", "Custom error message") .IsNotUrlOrEmpty("http://localhost:1000", "String") .IsNotUrlOrEmpty("http://localhost:1000", "String", "Custom error message") .IsNotUrlOrEmpty("localhost:1000", "String") .IsNotUrlOrEmpty("localhost:1000", "String", "Custom error message") .IsNotUrlOrEmpty("https://127.0.0.1:10000", "String") .IsNotUrlOrEmpty("https://127.0.0.1:10000", "String", "Custom error message") .IsNotUrlOrEmpty("127.0.0.1:10000", "String") .IsNotUrlOrEmpty("127.0.0.1:10000", "String", "Custom error message") .IsNotUrlOrEmpty("https://127.0.256.1:10000", "String") .IsNotUrlOrEmpty("https://127.0.256.1:10000", "String", "Custom error message") .IsNotUrlOrEmpty("127.0.256.1:10000", "String") .IsNotUrlOrEmpty("127.0.256.1:10000", "String", "Custom error message") .IsNotUrlOrEmpty("http://127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String") .IsNotUrlOrEmpty("http://127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String", "Custom error message") .IsNotUrlOrEmpty("127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String") .IsNotUrlOrEmpty("127.0.0.1:10000/devstoreaccount1/publicacao-storage/7d9cd2c9-4b0d-4b29-b0a5-c6e6c5c2562b.png", "String", "Custom error message"); Assert.AreEqual(false, contract.IsValid); Assert.AreEqual(contract.Notifications.Count, 10); } } } ================================================ FILE: Flunt.sln ================================================  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30907.101 MinimumVisualStudioVersion = 15.0.26124.0 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flunt", "Flunt\Flunt.csproj", "{8BC195E8-08FC-403B-8E67-261928C7C539}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flunt.Tests", "Flunt.Tests\Flunt.Tests.csproj", "{C6AD8DB5-7A43-478C-A5F5-34673357838C}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flunt.Samples", "Flunt.Samples\Flunt.Samples.csproj", "{679D0442-90D1-409F-9947-98C402F11752}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {8BC195E8-08FC-403B-8E67-261928C7C539}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Debug|Any CPU.Build.0 = Debug|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Debug|x64.ActiveCfg = Debug|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Debug|x64.Build.0 = Debug|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Debug|x86.ActiveCfg = Debug|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Debug|x86.Build.0 = Debug|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Release|Any CPU.ActiveCfg = Release|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Release|Any CPU.Build.0 = Release|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Release|x64.ActiveCfg = Release|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Release|x64.Build.0 = Release|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Release|x86.ActiveCfg = Release|Any CPU {8BC195E8-08FC-403B-8E67-261928C7C539}.Release|x86.Build.0 = Release|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Debug|x64.ActiveCfg = Debug|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Debug|x64.Build.0 = Debug|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Debug|x86.ActiveCfg = Debug|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Debug|x86.Build.0 = Debug|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Release|Any CPU.Build.0 = Release|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Release|x64.ActiveCfg = Release|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Release|x64.Build.0 = Release|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Release|x86.ActiveCfg = Release|Any CPU {C6AD8DB5-7A43-478C-A5F5-34673357838C}.Release|x86.Build.0 = Release|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Debug|Any CPU.Build.0 = Debug|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Debug|x64.ActiveCfg = Debug|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Debug|x64.Build.0 = Debug|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Debug|x86.ActiveCfg = Debug|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Debug|x86.Build.0 = Debug|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Release|Any CPU.ActiveCfg = Release|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Release|Any CPU.Build.0 = Release|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Release|x64.ActiveCfg = Release|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Release|x64.Build.0 = Release|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Release|x86.ActiveCfg = Release|Any CPU {679D0442-90D1-409F-9947-98C402F11752}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {380C6B7B-4776-4F25-B010-8B382145B48C} EndGlobalSection EndGlobal ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2021 Andre Baltieri Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Flunt Flunt is a fluent way to use Notification Pattern with your entities, concentrating every change you made and easy accessing it when you need. | Package | Version | Downloads | | ------- | ----- | ----- | | `Flunt` | [![NuGet](https://img.shields.io/nuget/v/Flunt.svg)](https://nuget.org/packages/Flunt) | [![Nuget](https://img.shields.io/nuget/dt/Flunt.svg)](https://nuget.org/packages/Flunt) | ### Dependencies .NET Standard 2.0 You can check supported frameworks here: https://docs.microsoft.com/pt-br/dotnet/standard/net-standard ### Instalation This package is available through Nuget Packages: https://www.nuget.org/packages/Flunt **Nuget** ``` Install-Package Flunt ``` **.NET CLI** ``` dotnet add package Flunt ``` ## How to use ```csharp public class Customer : Notifiable { ... } var customer = new Customer(); customer.AddNotification("Name", "Invalid name"); if(customer.IsValid) ... ``` Just check our [Wiki](https://github.com/andrebaltieri/Flunt/wiki) for more details and samples of how to use Flunt in your applications. ## Extensions * [Flunt.Extensions.Br](https://github.com/andrebaltieri/Flunt.Extensions.Br) * [Flunt.Extensions.AspNet](https://github.com/andrebaltieri/Flunt.Extensions.AspNet) ## Mods * [Flunt.Br](https://github.com/lira92/flunt.br) * [Flunt for Java](https://github.com/carlosbritojun/jflunt) * [Flunt for JavaScript](https://github.com/jhonesgoncal/flunt) * [Flunt for Python](https://github.com/Delatorrea/PyFlunt) * [Flunt for PHP](https://github.com/matheusbloise/flunt-php) ## About the Art All logo, icons, colors and fonts were provided with love by Gregory Buso