我有一个 API 请求,需要通过多次迭代在 Postman-Collection-Runner 中运行。API 请求使用变量。
我怎样才能让这个变量随着每次迭代自动增加(或者可能将迭代值设置为另一个变量)?
我正在使用 C#,我需要测试接受 System.Net.Http.Headers.HttpRequestHeaders 作为参数的方法之一。我们使用 FakeItEasy 进行测试。
但似乎 HttpResponseHeaders - 没有构造器(并且它是密封的),并且它使用 HttpHeader 作为基础。HttpHeader - 有构造函数,但 Header 属性只允许 get。
有没有办法构建虚拟/假的 HttpResponseHeaders 或 HttpResponseMessage 并在其中预设所需的标头值?
我在我的方法中使用了 try/catch。当然,如果发生异常,它会抛出异常(我的 UnitTest 部分需要这个异常),但不会返回值。
我想要的是 catch 部分同时执行:抛出异常并返回值。
有没有办法做到这一点?
这是我的示例代码(并且返回计数不应为“0”):
private int myCount;
public void DoSomethingMethod()
{
// Do Something Here
myCount++;
}
public int MyMethod ()
{
try
{
DoSomethingMethod()
return myCount;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
return myCount; // Do not expect this value to be '0'
}
}
Run Code Online (Sandbox Code Playgroud)
这是需要这两者的测试部分(异常和返回计数)。
[Test]
public void when_expected_count()
{
int count= 0;
Action act = () => count= MyMethod.GetResult();
act.Should().Throw<Exception>("The method should throw Exception.");
count.Should().Be(10);
}
Run Code Online (Sandbox Code Playgroud)