小编JCA*_*JCA的帖子

如何验证单元测试中的日志消息以通过测试?

我正在测试一个端点。我需要弄清楚如何让我的 loggerMock 测试通过。以下是我目前设置测试的方式:

public void GetExceptionReportSessionData_Returns200OK()
        {
            //Arrange 
            var response = new RetrieveExceptionReportSessionDatesResponse
            {
                RetrieveExceptionReportSessionDatesResult = string.Empty
            };
            var serviceClient = new Mock<WorkflowService.WorkflowService>();      
            serviceClient
                .Setup(x => x.RetrieveExceptionReportSessionDatesAsync(It.IsAny<RetrieveExceptionReportSessionDatesRequest>()))
               .ReturnsAsync(response);

            var loggerMock = new Mock<ILogger>();
            loggerMock.Setup(x => x.LogInfo(null));

            var controller = new ExceptionReportController(loggerMock.Object);

            var ctx = new ControllerContext() { HttpContext = new DefaultHttpContext() };
            ctx.HttpContext.Request.Headers["token"] = "fake_token_here"; //Set header
            controller.ControllerContext = ctx;

            //Act
            var result = controller.GetExceptionReportSessionData();

            //Assert
            var viewResult = Assert.IsType<OkObjectResult>(result);
            Assert.Equal(StatusCodes.Status200OK, viewResult.StatusCode);


        }
Run Code Online (Sandbox Code Playgroud)

以下是返回 200 时记录器在端点中的设置方式:

if (result != null …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing moq xunit asp.net-core

6
推荐指数
2
解决办法
2万
查看次数

*ngIf 带按钮,禁用或未禁用 Angular 9

我有两个下拉菜单,它们是Retrieve单击按钮时调用的函数的参数。我想要发生的是当两个下拉菜单都没有选择数据时,Retrieve按钮被禁用。如果两个下拉菜单都有数据,那么我希望按钮正常运行。这是我当前的 html:

<div class="dropdown">
  <div class="input-group">
    <h4 class="sessionText">Session: </h4>
    <select [(ngModel)]='sessionReportFilter.sessionName'
            class="custom-select form-control-sm"
            (change)='sessionDataChange($event)'
            id="inputGroupSelect01">
      <option [value]="null">Select session...</option>
      <option *ngFor="let session of sessionData" [value]='session.sessionName'>
        {{session.sessionName}}
      </option>
    </select>
  </div>

  <div class="input-group">
    <h4 class="reportText">Report Date: </h4>
    <select [(ngModel)]='sessionReportFilter.fileName' *ngIf='currentSession' class="custom-select form-control-sm" id="inputGroupSelect01">
      <option [value]="null">Select report...</option>
      <option *ngFor="let report of currentSession.reportFiles"
              [value]="report">
        {{report}}
      </option>
    </select>
    <select *ngIf="currentSession === null" class="custom-select form-control-sm" id="inputGroupSelect01"></select>
  </div>
  <div>
    <button type="button" class="btn btn-primary" disabled="disabled">Retrieve</button>
    <button type="button" class="btn btn-primary" (click)="orderExceptionReportData()">Retrieve</button>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我怎样才能达到预期的结果?

html angular-ng-if angular

2
推荐指数
1
解决办法
7159
查看次数

标签 统计

angular ×1

angular-ng-if ×1

asp.net-core ×1

c# ×1

html ×1

moq ×1

unit-testing ×1

xunit ×1