- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 async Task
单元测试(MVC、c#、.NET 4.5.2)。它在 await
方法上执行 aysnc Task<ActionResult>
,而 await
方法又在异步方法上调用 Debug Selected Tests
。
如果我选择它们并从 Visual Studio 2017 的右键单击菜单中选择 Run Selected Tests
,测试和其他类似的测试将通过。
问题是当我选择 Run All
或 RedirectToRouteResult
时。届时,如果它们遵循开头提到的条件,许多测试将失败。任何只返回 ojit_code 而没有进行上述钻取的测试都将通过。
[TestMethod]
public async Task TestPartsController_GetPartInfo_ReturnsInfo()
{
//arrange
PartController pc = new PartController();
//act
var result = await pc.GetPartInfo("PC123456");
//assert
Assert.IsIntanceOfType(result, typeof(ViewResult));
Assert.AreEqual("Form", ((ViewResult)result).ViewName);
Assert.AreEqual("PC123456", result.Model.PartNum.ToUpper());
}
public async Task<ActionResult> GetPartInfo(string partNum)
{
if (string.IsNullOrEmpty(partNum)
{
return RedirectToAction("Index")
}
var response = await ServiceClient.GetJsonAsync("/part/partinfo", "?partNum=" + partNum;
response.EnsureSuccessStatusCode();
results = await response.Content.ReadAsAsync<Dto.PartNumInfo>();
...
return View("Form", model);
}
public async Task<HttpResponseMessage> GetAsync(Controllers controller, string criteria)
{
HttpClient client;
string service = GetService(controller, out client);
var response = await client.GetAsync(service + criteria);
return response;
}
解决方案一直使用 async/await 以及使用语句和 IDisposable。
public async Task<HttpResponseMessage> GetJsonAsync<T>(Controllers controller, T data)
{
HttpResponseMessage response;
using (var service = new MyService())
{
HttpClient http;
string serviceLoc = service.GetServiceClient(controller, out http);
response = await http.GetAsync(serviceLoc, data);
}
return response;
}
最佳答案
解决方案一直使用 async/await 以及 using statements 和 IDisposable。
public async Task<HttpResponseMessage> GetJsonAsync<T>(Controllers controller, T data)
{
HttpResponseMessage response;
using (var service = new MyService())
{
HttpClient http;
string serviceLoc = service.GetServiceClient(controller, out http);
response = await http.GetAsync(serviceLoc, data);
}
return response;
}
关于c# - MSUnit 测试异步 hell ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44120668/
不同的编程语言使用不同的打包系统。 Java 的 Maven 采用各种不同的方法。对我来说似乎是最好的选择,因为它在不同版本的文件夹中维护不同版本的 jar 文件,因此,没有办法最终导致库的版本冲突。
这个问题已经有答案了: force browsers to get latest js and css files in asp.net application (23 个回答) 已关闭 7 年前。
我目前正在将带有一些回调 hell 的构建过程转换为 promise hell ( hell 很可能是因为我是 promises 的新手并且我对 Bluebird 缺乏经验)。我正在努力通过 .all
在我的一个项目中,我使用了一个动态加载包装器 DLL(导出 C 风格函数)的 Delphi 应用程序,后者又静态链接到一堆第 3 方 DLL。 它在我的测试机器上工作正常,但在我的客户计算机上它无法初
昨晚我试图放一个简单的教程来使用堆栈构建应用程序 - Spring(2.5)+ JPA(1.0)+ Hibernate(第一次下载,所以不知道使用哪个版本)。不幸的是,我不想使用 Maven,因为目标
class Badge(SafeDeleteModel): owner = models.ForeignKey(settings.AUTH_USER_MODEL,
为什么这个查询: SELECT "hello" = " hello", "hello" = "hello ", "hello" <> "hello ", "hello"
我目前正在尝试从公共(public) API 获取有关一个国家及其邻国的数据,以在我的 html 上呈现。 renderCountry( ) 是一个函数,用于在我的 html 上实现我将收到的数据。
我的背景是 Python,在 Python 中,您将所有事物都视为鸭子,并且无需定义类型。我最近开始使用 Dart 编写代码,现在我遇到了这些类型转换问题。 下面的代码有什么问题? appendCsv
这是我的目录结构: ├── src │ ├── helpers │ │ ├── __init__.py │ │ ├── foo.py │ │ └── bar.py │
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 提供事实和引用来回答它. 2年前关闭。 Improve this
我正在尝试在 Haskell 项目中包含特定版本的库。该库是住宿加早餐型的(用于 martix 操作),但我需要特定的 0.4.3 版本,该版本修复了乘法实现的错误。 所以,我的 stack.yaml
我偶尔会遇到一个问题,即为设备配置开发版本的应用程序。错误消息通常是“找不到此可执行文件的有效配置文件”。 我已遵循所有 Apple 说明:我拥有有效的开发证书,开发人员配置文件包含相关设备的设备 I
我正在开发具有少数不同项目的 asp.net 核心解决方案,每个项目都使用某个版本库的 3rd 方 NuGet 包。这些版本,例如1.0.0 和 2.0.0,有重大变化。另外,这个库是由另一个项目团队
我正在尝试为我制作的自定义组件制作一个包。它基于多个库,包括 Graphics32、GraphicEx 和 CCR.Exif。 我创建了一个Package项目,编写了包括其Register过程的单元,
在研究 NodeJS 中的“回调 hell ”时,我得到了很多推荐相同内容的网站。浅层函数、模块化,以及一些工具,如 Promise、异步和生成器。 从技术上讲,我知道什么是回调,也知道为什么在 No
我使用Python构建了一个AI应用程序,其中涉及大量的Python库。此时,我想在Docker容器中运行我的应用程序以使AI App成为服务。 关于依赖项,我有哪些选择,以便自动下载所有必需的库?
谁能提供 SecurityDriven.Inferno AesCtrCryptoTransfom 的使用示例类(class) ? 该库似乎很有前途,但我无法找到任何使用它的代码,并且提供的详细信息对我
我有一个需要重复执行的任务,因此我尝试为其编写一个函数。我的函数几乎完成了,除了一个缺陷:我无法将公式作为参数传递,除非它是字符串的形式。 library(lme4) library(lazyeval
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 7 年前。 Improve this ques
我是一名优秀的程序员,十分优秀!