unit tests for API (99% coverage)

This commit is contained in:
Volodymyr Smirnov
2020-10-29 12:17:09 +02:00
parent 7f2528eb1d
commit b2902c128a
20 changed files with 565 additions and 130 deletions

View File

@@ -6,14 +6,15 @@ namespace MalwareMultiScan.Api.Attributes
/// <summary>
/// Validate URI to be an absolute http(s) URL.
/// </summary>
internal class IsHttpUrlAttribute : ValidationAttribute
public class IsHttpUrlAttribute : ValidationAttribute
{
/// <inheritdoc />
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (!Uri.TryCreate((string)value, UriKind.Absolute, out var uri)
|| !uri.IsAbsoluteUri
|| uri.Scheme != "http" && uri.Scheme != "https")
|| uri.Scheme.ToLowerInvariant() != "http"
&& uri.Scheme.ToLowerInvariant() != "https")
return new ValidationResult("Only absolute http(s) URLs are supported");
return ValidationResult.Success;