Exemplo n.º 1
0
        /// <inheritdoc />
        public override void Validate(string errorLocaction, string propertyPath = "")
        {
            base.Validate(errorLocaction, propertyPath);
            var now = DateTimeOffset.Now;

            FulcrumValidate.IsTrue(RecordCreatedAt < now, errorLocaction, $"Expected {nameof(RecordCreatedAt)} ({RecordCreatedAt}) to have a value less than the current time ({now}).");
            FulcrumValidate.IsTrue(RecordUpdatedAt < now, errorLocaction, $"Expected {nameof(RecordUpdatedAt)} ({RecordUpdatedAt}) to have a value less than the current time ({now}).");
        }
 /// <inheritdoc/>
 public override void Validate(string errorLocaction, string propertyPath = "")
 {
     FulcrumValidate.IsGreaterThan(0, Id, nameof(Id), errorLocaction);
     FulcrumValidate.IsNotNullOrWhiteSpace(Name, nameof(Name), errorLocaction);
     FulcrumValidate.IsTrue(Regex.IsMatch(Name, "^[a-zA-Z]+$"), errorLocaction, $"Property {nameof(Name)} must only consist of upper or lower case a-z.");
     FulcrumValidate.IsNotNullOrWhiteSpace(Category, nameof(Category), errorLocaction);
     FulcrumValidate.IsTrue(Regex.IsMatch(Category, "^[a-zA-Z]+$"), errorLocaction, $"Property {nameof(Category)} must only consist of upper or lower case a-z.");
     FulcrumValidate.IsGreaterThanOrEqualTo(0.0, Price, nameof(Price), errorLocaction);
     FulcrumValidate.IsNotDefaultValue(DateAdded, nameof(DateAdded), errorLocaction);
     FulcrumValidate.IsLessThanOrEqualTo(DateTimeOffset.Now, DateAdded, nameof(DateAdded), errorLocaction);
 }
        /// <inheritdoc />
        public void Validate(string errorLocation, string propertyPath = "")
        {
            FulcrumValidate.IsNotNullOrWhiteSpace(Method, nameof(Method), errorLocation);
            FulcrumValidate.IsNotNullOrWhiteSpace(EncodedUrl, nameof(EncodedUrl), errorLocation);
            FulcrumValidate.IsTrue(IsValidUri(EncodedUrl), errorLocation, $"{propertyPath}.{nameof(EncodedUrl)} is not a valid URL.");
            FulcrumValidate.IsTrue(HttpMethodExists(), errorLocation, $"{Method} is not a valid HttpMethod");
            if (BodyAsString != null)
            {
                FulcrumValidate.IsTrue(JsonHelper.TryDeserializeObject(BodyAsString, out JToken _), errorLocation,
                                       $"{propertyPath}.{nameof(BodyAsString)} must be JSON.");
            }
            ValidateHeaders();

            bool HttpMethodExists()
            {
                var propertyInfo = typeof(System.Net.Http.HttpMethod).GetProperty(Method,
                                                                                  BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public);

                return(propertyInfo != null);
            }

            bool IsValidUri(string url)
            {
                var result = Uri.TryCreate(url, UriKind.Absolute, out var uri) &&
                             (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps);

                return(result);
            }

            void ValidateHeaders()
            {
                if (Headers != null && Headers.Any())
                {
                    var index = 0;
                    foreach (var header in Headers)
                    {
                        index++;
                        FulcrumValidate.IsNotNullOrWhiteSpace(header.Key, "ignore", errorLocation,
                                                              $"Header {index} in {propertyPath}.{nameof(Headers)} had an empty key.");
                        FulcrumValidate.IsTrue(!header.Key.StartsWith("Content-"), errorLocation,
                                               $"Header {header.Key} is not allowed, as it is a content header.");
                        FulcrumValidate.IsNotNullOrWhiteSpace(header.Value.ToString(), "ignore", errorLocation,
                                                              $"Header {header.Key} had an empty value.");
                        FulcrumValidate.IsTrue(header.Value.Any(), errorLocation,
                                               $"Header {header.Key} had no values.");
                        FulcrumValidate.IsTrue(!header.Value.Any(string.IsNullOrWhiteSpace), errorLocation,
                                               $"Header {header.Key} had an empty value.");
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public void Validate(string errorLocation, string propertyPath = "")
        {
            if (Type != null)
            {
                FulcrumValidate.IsTrue(Type == "private" || Type == "public", null, $"{nameof(Type)} must have one of the values \"private\" and \"public\".");
            }
            FulcrumValidate.IsGreaterThanOrEqualTo(0, Created, nameof(Created), errorLocation);
            var now = DateTimeOffset.Now;

            if (StartInclusive != null)
            {
                FulcrumValidate.IsLessThanOrEqualTo(now, StartInclusive.Value, nameof(StartInclusive), errorLocation);
            }
            if (EndExlusive != null)
            {
                FulcrumValidate.IsLessThanOrEqualTo(now, EndExlusive.Value, nameof(EndExlusive), errorLocation);
            }
        }
 /// <inheritdoc />
 public void Validate(string errorLocation, string propertyPath = "")
 {
     FulcrumValidate.IsNotNullOrWhiteSpace(ConceptName, nameof(ConceptName), errorLocation);
     FulcrumValidate.IsTrue(ClientName == null || ContextName == null, errorLocation, $"One of the properties {nameof(ContextName)} ({ContextName}) and {nameof(ClientName)} ({ClientName}) must be null.");
     FulcrumValidate.IsTrue(!string.IsNullOrWhiteSpace(ContextName) || !string.IsNullOrWhiteSpace(ClientName), errorLocation, $"One of the properties {nameof(ContextName)} ({ContextName}) and {nameof(ClientName)} ({ClientName}) must contain a name.");
 }
Exemplo n.º 6
0
 public void Validate(string errorLocation, string propertyPath = "")
 {
     FulcrumValidate.IsTrue(Value != TestItemBare.ValueToMakeValidationFail, errorLocation,
                            $"The value must not be {TestItemBare.ValueToMakeValidationFail}");
 }
Exemplo n.º 7
0
 /// <inheritdoc />
 public void Validate(string errorLocation, string propertyPath = "")
 {
     FulcrumValidate.IsNotNullOrWhiteSpace(Name, nameof(Name), errorLocation);
     FulcrumValidate.IsNotNullOrWhiteSpace(Type, nameof(Type), errorLocation);
     FulcrumValidate.IsTrue(Type == "int" || Type == "ext", errorLocation, $"Type must be either \"ext\" or \"int\", was \"{Type}\".");
 }