.Net中的Moq具有2个参数

我正在尝试创建一个模拟来运行我的测试,但是出现以下错误, “无效的回调。具有2个参数的方法上的设置无法调用具有不同数量的参数(1)的回调” 这是我的设置功能


        import React from 'react';
        import { withStyles } from '@material-ui/core/styles';
        import IconDownload from '@material-ui/icons/CloudDownloadTwoTone';

        const styles = theme => ({
          root: { 
          },});

        class AttachmentViewer extends React.PureComponent {
          static propTypes = {
            open: PropTypes.bool.isrequired,filename: PropTypes.string.isrequired,filePath: PropTypes.string.isrequired,};

          render() {
            const { filePath,filename } = this.props;
            return (
              <div>
                <a href={`${filePath}`} download={filename}>
                  <IconDownload />
                </a>
              </div>
            );
          }
        }

        export default withStyles(styles)(AttachmentViewer);

如果我仅在Factory中使用一个参数,它将正常工作。有人可以帮忙吗?

WAGXZ 回答:.Net中的Moq具有2个参数

Returns中使用的表达式需要与设置中使用的匹配器数量匹配

设置中有两个日期时间参数匹配器,因此在返回表达式中需要使用两个。

this.dataFactoryMock
    .Setup(factory => factory.Factory(It.IsAny<DateTime>(),It.IsAny<DateTime>()))
    .Returns((DateTime adjustedAnalysisDate,DateTime analysisDate) => 
        commonDataFactory.Factory(adjustedAnalysisDate,analysisDate)
    );
本文链接:https://www.f2er.com/3123420.html

大家都在问