Skip to Content
C#并发编程经典实例(第2版)
book

C#并发编程经典实例(第2版)

by Stephen Cleary
November 2020
Intermediate to advanced
226 pages
5h 34m
Chinese
Posts & Telecom Press
Content preview from C#并发编程经典实例(第2版)
86
7
[TestMethod]
public async
Task MyTimeoutClass_FailedGet_PropagatesFailure()
{
var
stub =
new
FailureHttpServiceStub();
var
my =
new
MyTimeoutClass(stub);
await
ThrowsAsync<HttpRequestException>(
async
() =>
{
await
my.GetStringWithTimeout(
"
http://exampleurl")
.SingleAsync();
});
}
讨论
Return
Throw
是创建可观察存根的极好选择,
SingleAsync
则是通过
async
单元测试来测
试可观察对象的便捷之道。可以将它们组合起来,这非常适合用于简单的可观察对象,但
一旦涉及时间,它们就不那么好用了。假如测试
MyTimeoutClass
的超时负荷,单元测试必
须等待对应的时长。然而这个办法很糟糕:由于引入了竞争条件,因此单元测试变得不可
靠,而且当添加更多单元测试后,其扩展性也不佳。
7.6
节探讨
System.Reactive
的一种特
殊用法,通过它能消除对时间的依赖。
参阅
7.1
节探讨对
async
方法进行单元测试,这与等待
SingleAsync
的单元测试非常相似。
7.6
节探讨对依赖时间的可观察序列进行单元测试。
7.6
 通过伪造调度对
System.Reactive
可观察对
象进行单元测试 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre

Publisher Resources

ISBN: 9787115550606