tests/DotNetCommon.Test/Validate/NumberValidTests.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using DotNetCommon.Validate;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using DotNetCommon.Extensions;

namespace DotNetCommon.Test.Validate
{
    [TestFixture]
    public class NumberValidTests
    {
        [Test]
        public void MustEqualToTest()
        {
            var model = new Model()
            {
                PInt = 1,
                PIntNull = null
            };

            var msg = ValidateModelHelper.ValidErrorMessage(model, ctx =>
              {
                  ctx.RuleFor(i => i.PInt).MustEqualTo(1);
                  ctx.RuleFor(i => i.PIntNull).MustEqualTo(null);
              });
            Assert.True(msg.IsNullOrEmptyOrWhiteSpace());
            model = new Model()
            {
                PFloat = 1.23f,
                PFloatNull = null
            };
            msg = ValidateModelHelper.ValidErrorMessage(model, ctx =>
            {
                ctx.RuleFor(i => i.PFloat).MustEqualTo(1.23f);
                ctx.RuleFor(i => i.PFloatNull).MustEqualTo(null);
            });
            Assert.True(msg.IsNullOrEmptyOrWhiteSpace());
        }

        [Test]
        public void MustGreaterThanTest()
        {
            var model = new Model()
            {
                PInt = 1,
                PIntNull = null,
                PFloat = 1.23f,
            };

            var msg = ValidateModelHelper.ValidErrorMessage(model, ctx =>
            {
                ctx.RuleFor(i => i.PInt).MustGreaterThan(0);
                ctx.RuleFor(i => i.PFloat).MustGreaterThan(0);
            });
            Assert.True(msg.IsNullOrEmptyOrWhiteSpace());
            model = new Model()
            {
                PIntNull = null
            };
后面还有 61 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。