tests/DotNetCommon.Test/Validate/ListValidTests.cs

(开头部分) 5KB

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

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

namespace DotNetCommon.Test.Validate
{
    [TestFixture]
    public class ListValidTests
    {
        [Test]
        public void NotNullOrEmptyTest()
        {
            //PersonList
            var person = new PersonList()
            {
                Id = 1,
                Name = "小王",
                Books = null
            };
            var msg = ValidateModelHelper.ValidErrorMessage(person, ctx =>
              {
                  ctx.RuleFor(i => i.Books).MustNotNullOrEmpty();
              });
            msg.ShouldNotBeNullOrWhiteSpace();

            person.Books = new List<Book>();
            msg = ValidateModelHelper.ValidErrorMessage(person, ctx =>
            {
                ctx.RuleFor(i => i.Books).MustNotNullOrEmpty();
            });
            msg.ShouldNotBeNullOrWhiteSpace();

            person.Books = new List<Book>() { new Book() };
            msg = ValidateModelHelper.ValidErrorMessage(person, ctx =>
            {
                ctx.RuleFor(i => i.Books).MustNotNullOrEmpty();
            });
            msg.ShouldBeNullOrWhiteSpace();

            //PersonCollection
            var personCollection = new PersonCollection()
            {
                Id = 1,
                Name = "小王",
                Books = null
            };
            msg = ValidateModelHelper.ValidErrorMessage(personCollection, ctx =>
            {
                ctx.RuleFor(i => i.Books).MustNotNullOrEmpty();
            });
            msg.ShouldNotBeNullOrWhiteSpace();

            personCollection.Books = new List<Book>();
            msg = ValidateModelHelper.ValidErrorMessage(personCollection, ctx =>
            {
                ctx.RuleFor(i => i.Books).MustNotNullOrEmpty();
            });
后面还有 123 行代码,解锁后查看完整代码

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

AI 解读

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

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