【问题标题】:Should I test pure CQRS Commands?我应该测试纯 CQRS 命令吗?
【发布时间】:2020-07-16 21:08:15
【问题描述】:

我正在使用 CQRS 编写应用程序。我有我的命令和我的 commandHandler。我确实测试了我的命令处理程序。但是......你应该推荐测试命令吗?最好的策略是什么?我应该测试所有的验证可能性吗?小伙伴们怎么样?

using System;
using Flunt.Notifications;
using Flunt.Validations;
using Todo.Domain.Commands.Contracts;

    namespace Todo.Domain.Commands
    {
        public class CreateTodoCommand : Notifiable, ICommand
        {
            public CreateTodoCommand() { }
    
            public CreateTodoCommand(string title, string user, DateTime date)
            {
                Title = title;
                User = user;
                Date = date;
            }
    
            public string Title { get; set; }
            public string User { get; set; }
            public DateTime Date { get; set; }
    
            public void Validate()
            {
                AddNotifications(
                    new Contract()
                        .Requires()
                        .HasMinLen(Title, 3, "Title", "Please, describe better your task!")
                        .HasMinLen(User, 6, "User", "Invalid User!")
                );
            }
        }
    }

【问题讨论】:

    标签: asp.net-mvc asp.net-core cqrs


    【解决方案1】:

    你应该推荐测试命令吗?

    • 您多久更改一次命令?
    • 您在更改命令时引入错误的可能性有多大?
    • 这个错误逃到一个版本中的代价是多大?
    • 测试费用有多高?

    命令在输入边界附近,我们在输入边界附近遇到的常见问题之一是parsing 一些通用数据结构,以确保它满足我们的定制约束。

    解析需要测试吗?嗯,这是逻辑(不止一种可能的结果),所以它肯定是一个值得考虑的候选者。

    很有可能:您对上述问题没有特别具体的答案。在这种情况下,我会在引入测试方面犯错:因为测试为您提供了一种收集数据的方法,随着时间的推移,这将改善您的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 2019-10-02
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2016-07-23
      相关资源
      最近更新 更多