Specflow特征文件代码-数据定义c#

你也可以使用


扩展方法


像这样


public static long GetUserID(this ClaimsPrincipal User)

{

   return long.Parse(User.Claims.First(i => i.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value);

}

并像这样在您的控制器中实现


[HttpDelete("DeleteAddress")]

public async Task<IActionResult> DeleteAddress([FromQuery] long AddressID)

{

   try

   {

      long userID = this.User.GetUserID();

      await _addressService.Delete(userID, AddressID);

      return Ok();

   }

   catch (Exception err)

   {

      return Conflict(err.Message);

   }     

}

我希望它会帮助你


猛跑小猪
浏览 157回答 2
2回答

蝴蝶刀刀

通常最好将Givens 和Whens 分开,以便您的功能读起来更好。在您的情况下,最好的做法是使用 aScenario Outline而不是 a Scenario。这允许您使用标记化表来断言多个不同的结果,前提是相同的初始步骤:Scenario Outline: Batch execution works correctly&nbsp; &nbsp; Given&nbsp; Interface is generated&nbsp; &nbsp; When batch is executed&nbsp; &nbsp; Then <measure_type> is generatedExamples:&nbsp;&nbsp; &nbsp; | measure_type&nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; | transfer measure&nbsp; &nbsp;|&nbsp; &nbsp; | allocation measure |在您的步骤中,您将有单独的方法断言measure type已生成正确的方法:[Then(@"transfer measure is generated")]public void ThenTransferMeasureIsGenerated(){&nbsp; &nbsp; // your assertion logic here}

料青山看我应如是

对于你的例子生成给定接口批处理执行时然后生成转移测度生成给定接口批处理执行时然后生成分配度量您可以使用表格并按如下方式更改它:Given Interface is generated&nbsp; &nbsp;&nbsp;When batch is executed&nbsp; &nbsp;Then '<val>' measure is generated&nbsp; &nbsp;&nbsp;Examples:&nbsp; &nbsp;&nbsp;|val|&nbsp; &nbsp;&nbsp;|transfer|&nbsp; &nbsp;&nbsp;|allocation|这将生成单个 Then 步骤
打开App,查看更多内容
随时随地看视频慕课网APP