IDMEntityValidator 1.1.0
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package IDMEntityValidator --version 1.1.0
NuGet\Install-Package IDMEntityValidator -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IDMEntityValidator" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IDMEntityValidator --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: IDMEntityValidator, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install IDMEntityValidator as a Cake Addin
#addin nuget:?package=IDMEntityValidator&version=1.1.0
// Install IDMEntityValidator as a Cake Tool
#tool nuget:?package=IDMEntityValidator&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
IDM EntityValidator Getting started step-by-step
1. Create the objects to be validated.
public class Foo
{
public string Name { get; set; }
}
// In this case, the class Bar is a validated object.
public class Bar : IValidatable<Bar>
{
public int Count { get; set; }
public int[] Items { get; set; }
public Foo Foo { get; set; }
public bool Validate(IValidator<Bar> validator, out IEnumerable<ValidateResult> brokenRules)
{
return validator.IsValid(this, out brokenRules);
}
}
2. Create a validator class for the validated object.
// This attribute specifies the default validator, if there are several validators for this type.
// If the attribute is not set, then the first validator for this type is taken.
[DefaultValidatorForEntity]
public class BarValidator : Validator<Bar>
{
public BarValidator()
{
var s = Setup();
s.RegisterRequiredRule(x => x.Count, i => i > 0, "Count < 0");
s.RegisterRequiredRule(x => x.Items, items => items.Length == 3, "Items Length != 3");
s.RegisterRequiredRule(x => x.Items, items => items[0] == 1, "Items[0] != 1");
s.RegisterRequiredRule(x => x.Items, items => items != null && items.Any(), "Items is null or empty");
s.RegisterOptionalRule(x => x.Foo.IsNotNull(),
r =>
{
r.RegisterRequiredRule(y => y.Foo.Name,
name => !name.IsNullOrEmpty(),
"Foo Name is null or empty");
r.RegisterRequiredRule(y => y.Foo.Name,
name => Regex.IsMatch(name, "\\w+"),
"Foo Name only words");
r.RegisterOptionalRule(y => y.Foo.Name == "Foo",
r2 =>
{
r2.RegisterRequiredRule(z => z.Count, i => i < 10, "Count i >= 10 ");
r2.RegisterPostcondition("Count And Length",
bar => bar.Count == 1 && bar.Items.Length == 3,
"Count != 1 or Items.Length != 3");
});
});
s.RegisterOptionalRule(bar => bar.Foo.IsNotNull(),
r =>
{
r.RegisterRequiredRule(bar => bar.Foo.Name, name => name.StartsWith("F"),
"Foo Name start with not 'F'");
});
}
}
3. Use validator
[TestFixture]
public class ValidatorTests
{
// Without validators locator
[TestCase("Foo", 1, new[] { 1, 2, 3 }, true)]
[TestCase("", 3, new[] { 5, 2, 3 }, false)]
[TestCase("Foo", -1, new[] { 0, 2, 3, 4 }, false)]
[TestCase(null, null, new[] { 1, 2, 3 }, false)]
public void ValidatorValidTest(string name, int count, int[] items, bool result)
{
var foo = new Foo
{
Name = name
};
var bar = new Bar
{
Count = count,
Items = items,
Foo = foo
};
// Instance validator
var barValidator = new BarValidator();
var resultActual = bar.Validate(barValidator, out var results);
foreach (var validateResult in results)
{
Console.WriteLine($@"{validateResult}");
}
Assert.AreEqual(result, resultActual);
}
// With validators locator
[TestCase("Foo", 1, new[] { 1, 2, 3 }, true)]
[TestCase("", 3, new[] { 5, 2, 3 }, false)]
[TestCase("Foo", -1, new[] { 0, 2, 3, 4 }, false)]
[TestCase(null, null, new[] { 1, 2, 3 }, false)]
public void ValidatorValidWithLocatorTest(string name, int count, int[] items, bool result)
{
// Install ValidatorsLocator
ValidatorsLocator.Current.Install(Assembly.GetExecutingAssembly());
var foo = new Foo
{
Name = name
};
var bar = new Bar
{
Count = count,
Items = items,
Foo = foo
};
// Validate - Method Extensions
var resultActual = bar.Validate(out var results);
foreach (var validateResult in results)
{
Console.WriteLine($@"{validateResult}");
}
Assert.AreEqual(result, resultActual);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net47 is compatible. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.7
- CommonServiceLocator (>= 1.3.0)
- NLog (>= 4.4.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|