tests/DotNetCommon.Test/Validate/DateTimeValidTests.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using DotNetCommon.Validate;
using Shouldly;
using System.Threading;
namespace DotNetCommon.Test.Validate
{
[TestFixture]
public class DateTimeValidTests
{
[Test]
public void DateTimeTest()
{
var person = new Person();
var msg = ValidateModelHelper.ValidErrorMessage(person, ctx =>
{
ctx.RuleFor(i => i.Birth).MustNotNull().MustGreaterThan(DateTime.Parse("1800-01-01"));
});
msg.ShouldContain("'Birth' 必须大于 '1800/1/1 0:00:00'!");
msg = ValidateModelHelper.ValidErrorMessage(person, ctx =>
{
ctx.RuleFor(i => i.Birth).MustNotNull().MustEqualTo(DateTime.Parse("0001-01-01"));
});
msg.ShouldBeNullOrEmpty();
msg = ValidateModelHelper.ValidErrorMessage(person, ctx =>
{
ctx.RuleFor(i => i.CreateTime).MustNotNull();
});
msg.ShouldContain("'CreateTime' 不能为空!");
person.CreateTime = DateTime.Now;
msg = ValidateModelHelper.ValidErrorMessage(person, ctx =>
{
ctx.RuleFor(i => i.CreateTime).MustNotNull();
});
msg.ShouldBeNullOrEmpty();
msg = ValidateModelHelper.ValidErrorMessage(person, ctx =>
{
ctx.RuleFor(i => i.CreateTime).MustLessThanOrEuqalTo(DateTime.Now);
});
msg.ShouldBeNullOrEmpty();
Thread.Sleep(500);
msg = ValidateModelHelper.ValidErrorMessage(person, ctx =>
{
ctx.RuleFor(i => i.CreateTime).MustGreaterThan(DateTime.Now);
});
msg.ShouldNotBeNullOrEmpty();
}
[Test]
public void DateTimeOffsetTest()
{
var person = new Person();
后面还有 60 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
