Skip to content

Commit 325b9a2

Browse files
committed
Simplify logic
1 parent addd302 commit 325b9a2

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/PublishedWithScheduledDateValidationAttribute.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ public sealed class PublishedWithScheduledDateValidationAttribute : ValidationAt
88
{
99
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
1010
{
11-
if (validationContext.ObjectInstance is CreateNewModel { IsPublished: true, ScheduledPublishDate: { } })
12-
{
13-
return new ValidationResult("Cannot have a scheduled publish date when the post is already published.");
14-
}
15-
16-
return ValidationResult.Success;
11+
return validationContext.ObjectInstance is CreateNewModel { IsPublished: true, ScheduledPublishDate: { } }
12+
? new ValidationResult("Cannot have a scheduled publish date when the post is already published.")
13+
: ValidationResult.Success;
1714
}
1815
}

tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/PublishedWithScheduledDateValidationAttributeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void GivenBlogPostIsPublishedAndHasScheduledDate_WhenValidating_ThenError
1616
ShortDescription = "Desc",
1717
Content = "Content",
1818
IsPublished = true,
19-
ScheduledPublishDate = DateTime.Now,
19+
ScheduledPublishDate = DateTime.MaxValue,
2020
PreviewImageUrl = "https://steven-giesel.com",
2121
};
2222
var validationContext = new ValidationContext(model);

0 commit comments

Comments
 (0)