小编Jen*_*r S的帖子

在VS2010中使用MS Test ClassInitialize()和TestInitialize()而不是NUnit

我已经在VS2008上使用了NUnit,现在我正在适应VS2010上的MSTest.我曾经能够在TestSetup()中创建一个对象并在TestCleanup()中处理它,并且每次在NUnit中运行测试方法时都会创建对象,从而阻止我在每个测试方法中复制代码.

这对MSTest来说不可能吗?我发现使用ClassInitialize和ClassCleanup以及TestInitialize和TestCleanup属性的示例仅显示如何写入控制台.没有显示这些属性的更详细用法.

nunit mstest

25
推荐指数
1
解决办法
3万
查看次数

How can I retrieve selected item's both Text and Value from DropDownList in MVC

Model:

public class SelectBillingSiteReportModel
{

    public IEnumerable<SelectListItem> Sites { get; set; }
    public string SelectedSiteName { get; set; }
    public string SelectedSiteKey { get; set; }
    [Required]
    [DataType(DataType.Date)]
    public DateTime FromDateTime { get; set; }
    [Required]
    [DataType(DataType.Date)]
    public DateTime ToDateTime { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

View:

@model MuseReport.Models.SelectBillingSiteReportModel
@{
    ViewBag.Title = "Select Site and Date Range";
}
    <div class="page-header">
    <h4>Select Site and Date Range for Ecg Billing Summary</h4>
</div>
<div class="row">
@using (Html.BeginForm("EcgBilling", "BillingRpt"))
{
    <div class ="form-horizontal" role="form">
        <div …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-5

3
推荐指数
1
解决办法
6222
查看次数

如何使用 Logback 更改 JSON 输出中的键名称?

这是我的日志配置。

<springProfile name="prod">
    <root level="info">
        <appender name="naki" class="ch.qos.logback.core.ConsoleAppender">
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>${logging_level}</level> <!-- setup via ENV variable log level -->
            </filter>
            <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
                <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
                    <timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSSX</timestampFormat>
                    <timestampFormatTimezoneId>Etc/UTC</timestampFormatTimezoneId>
                    <appendLineSeparator>true</appendLineSeparator> <!-- don't forget line break -->

                    <jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
                        <prettyPrint>false
                        </prettyPrint> <!-- in prod never pretty print, line breaks are considered as separate log entry -->
                    </jsonFormatter>
                </layout>
            </encoder>
        </appender>
    </root>
</springProfile>

<springProfile name="dev">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <root level="info">
        <appender-ref ref="CONSOLE"/>
    </root>
</springProfile>
Run Code Online (Sandbox Code Playgroud)

这是我得到的输出:

{"timestamp":"2020-01-13T13:38:38.001Z","level":"INFO","thread":"main","logger":"com.nakipower.identity.api.config.Application","message":"Started Application in 8.605 seconds (JVM running for 9.439)","context":"default"}
Run Code Online (Sandbox Code Playgroud)

如何将 JSON …

java logging spring logback slf4j

3
推荐指数
1
解决办法
2821
查看次数

Rxjs 映射和过滤器数组 - 返回单个对象而不是一个对象的数组?

我的服务中有一个方法可以获取所有模板,并返回模板对象的 Observable 数组。我正在尝试向我的服务添加一个新方法,该方法获取模板数组,但对其进行过滤以按名称获取数组中的特定模板。

有没有办法让它只返回单个可观察模板,而不是包含一个项目的可观察模板数组?我对 rxjs 语法还很陌生,我不明白如何使用像reduce这样的东西。

这是我获取所有模板的工作方法。

 getAllTemplates(): Observable<Template[]>{
    const uri = this.baseService.rootTemplatesUri;
    return this.http.get<Template[]>(uri)
      .pipe(
        catchError((error: HttpErrorResponse) => { return throwError(error); })
      );
  }

Run Code Online (Sandbox Code Playgroud)

这是我按名称过滤的尝试,如果存在匹配的名称,它将返回一个包含一个元素的数组:

getTemplateByName(name:string):Observable<Template[]>{
    const uri = this.baseService.rootTemplatesUri;
    return this.http.get<Template[]>(uri)
      .pipe(
        map(templates => {
          return templates.filter(template => {
            return template.Name === name;
          })
        }),
       catchError((error: HttpErrorResponse) => { return throwError(error); })
     );

  }
Run Code Online (Sandbox Code Playgroud)

有没有办法通过过滤返回单个 Observable?

javascript arrays filter rxjs angular

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

Angular Material 将初始焦点设置为表单控件,无需单击事件

我正在使用 Angular 9 和 Material。我有一个步进器,它将引导用户完成我们的工作流程的步骤。

我需要用户能够完全使用键盘完成这些步骤,而无需单击控件。我见过很多通过单击事件将焦点设置在控件上的示例。我不希望用户必须单击按钮才能将焦点设置在第一个文本区域。 当步进器初始化时,如何才能获得文本区域的初始焦点,而无需用户单击任何内容? 我尝试在 ngAfterViewInit 中使用元素引用,但它不起作用。谁能帮助我理解如何做到这一点?谢谢。

这是我的 HTML:

<pseudo-common-tool-header title="{{this.title}}"></pseudo-common-tool-header>
<div class="pseudo-content-manager-tool-area">
<mat-horizontal-stepper #stepper>
<mat-step [stepControl]="formGroup">
    <form [formGroup]="formGroup">
        <ng-template matStepLabel>Workstation Ids</ng-template>
        <div>
            <mat-form-field appearance="outline" class="eris-width-45" >
            <mat-label>List of Old/New Workstations to swap (one pair per line)</mat-label>
            <textarea #wkstns rows="8" #workstations matInput placeholder="Old Workstation, New Workstation" formControlName="workstations" required></textarea>
            </mat-form-field>
        </div>
        <div>
            <mat-form-field appearance="outline" >
                <mat-label>Soft Delete Date</mat-label>
                <input matInput #softDate [min]="minDate" [matDatepicker]="picker3" formControlName="removalDate">
                        <mat-datepicker-toggle matSuffix [for]="picker3"></mat-datepicker-toggle>
                        <mat-datepicker #picker3 color="primary"></mat-datepicker>
            </mat-form-field>
        </div>
        <div>
            <button color="primary" #step1next mat-raised-button matStepperNext>Next</button> …
Run Code Online (Sandbox Code Playgroud)

typescript angular-material angular angular-reactive-forms

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