Summary

Class:ProjectX.PublicApi.Filters.DateFromNowAttribute
Assembly:ProjectX.PublicApi
File(s):C:\private\projects\projectx\backend\src\ProjectX.PublicApi\Filters\DateFromNowAttribute.cs
Covered lines:7
Uncovered lines:3
Coverable lines:10
Total lines:34
Line coverage:70%
Branch coverage:75%

History

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
IsValid(...)347580

File(s)

C:\private\projects\projectx\backend\src\ProjectX.PublicApi\Filters\DateFromNowAttribute.cs

#LineLine coverage
 1using System;
 2using System.ComponentModel.DataAnnotations;
 3using ServiceBase;
 4
 5namespace ProjectX.PublicApi.Filters
 6{
 7    public class DateFromNowAttribute : ValidationAttribute
 8    {
 9        protected override ValidationResult IsValid(
 10            object value,
 11            ValidationContext validationContext)
 12        {
 413            var dateTimeAccessor = (IDateTimeAccessor)validationContext
 414                         .GetService(typeof(IDateTimeAccessor));
 15
 416            var dateFrom = dateTimeAccessor.UtcNow;
 417             if (value != null)
 18            {
 219                var dateTime = (DateTime)value;
 20
 21                // If date is in the past
 222                 if (dateTime < dateFrom)
 23                {
 024                    var message = $"The field {validationContext.MemberName}" +
 025                        $" must be grater than {dateFrom}";
 26
 027                    return new ValidationResult(message);
 28                }
 29            }
 30
 431            return ValidationResult.Success;
 32        }
 33    }
 34}