Moved analyzer tests to its own project

Also moves tests to `./test` which makes it possible
for all test projects to share the same .editorconfig
files and similar.
This commit is contained in:
Patrik Svensson
2021-06-23 22:47:12 +02:00
parent 721d73e9eb
commit c9b178ac96
307 changed files with 114 additions and 84 deletions

View File

@ -0,0 +1,29 @@
using System;
using Spectre.Console.Cli;
namespace Spectre.Console.Tests.Data
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public sealed class EvenNumberValidatorAttribute : ParameterValidationAttribute
{
public EvenNumberValidatorAttribute(string errorMessage)
: base(errorMessage)
{
}
public override ValidationResult Validate(CommandParameterContext context)
{
if (context.Value is int integer)
{
if (integer % 2 == 0)
{
return ValidationResult.Success();
}
return ValidationResult.Error($"Number is not even ({context.Parameter.PropertyName}).");
}
throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName}).");
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using Spectre.Console.Cli;
namespace Spectre.Console.Tests.Data
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public sealed class PositiveNumberValidatorAttribute : ParameterValidationAttribute
{
public PositiveNumberValidatorAttribute(string errorMessage)
: base(errorMessage)
{
}
public override ValidationResult Validate(CommandParameterContext context)
{
if (context.Value is int integer)
{
if (integer > 0)
{
return ValidationResult.Success();
}
return ValidationResult.Error($"Number is not greater than 0 ({context.Parameter.PropertyName}).");
}
throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName}).");
}
}
}