验证 ASP.NET Core SignalR 重构

已完成

在本单元中,你将运行已应用更改的代码,以此来验证重构是否成功。 现在你已在 signalr 分支上,并了解了各种重构所包含的内容,你应该会看到应用像以前一样正常运行。

重要

你可能已发现 signalr 分支中引入了额外的更改。 这些更改不在本模块的讨论范围内,它们有助于进一步模拟订购系统。

运行应用程序

现在你已熟悉重构的代码,并且已在 signalr 分支上,接下来可以再次构建并运行应用程序,验证它在功能上的等效性。 在 .NET CLI 中,使用 dotnet run 命令:

dotnet run --project ./BlazingPizza.Server/BlazingPizza.Server.csproj

此应用程序用于学习目的。 经过身份验证后,你可以注册任何电子邮件地址。 主动开发应用时,通过选择链接来确认帐户即可完成注册过程,而无需验证电子邮件地址。 有关详细信息,请参阅 Blazor Workshop:注册用户并登录

订购披萨

登录后,便可下单订购披萨。 选择披萨和馅料,然后将其添加到订单中。 例如,考虑下图:

Screenshot of the Blazing Pizza window for adding extra toppings to a pizza order.

在向订单添加额外的配料后,通过选择“订单”按钮进行下单。

Screenshot of the Blazing Pizza window for placing order.

创建订单后,应用将立即重定向到订单状态页。 此页面按顺序显示各种订单状态详细信息,从“备餐中”到“配送中”,再到最后的“已送达”。 当订单状态为“配送中”时,实时地图将通过逐步模拟送餐员的位置来进行更新。

请考虑下面的一系列图片,这些图片显示了实时地图上从起始位置到结束位置的进度:

备餐中Screenshot of the Blazing Pizza 'My Orders' window with an order status of 'Preparing'.

配送中 1Screenshot of the 'My Orders' window with an order status of 'Out for delivery'. The live map shows that the driver is just leaving.

配送中 2Screenshot of the 'My Orders' window with an order status of 'Out for delivery'. The live map shows that the driver has gone about a quarter of the way.

配送中 3Screenshot of the 'My Orders' window with an order status of 'Out for delivery'. The live map shows that the driver has gone about halfway.

配送中 4Screenshot of the 'My Orders' window with an order status of 'Out for delivery'. The live map shows that the driver has gone about three quarters of the way.

配送中 5Screenshot of the 'My Orders' window with an order status of 'Out for delivery'. The live map shows that the driver has arrived at the destination.

最后,订单状态页显示订单状态为“已送达”:

Screenshot of the 'My Orders' window with an order status of 'Delivered'. The live map shows that the driver has arrived at the delivery location.

停止应用程序

控制台应会输出各种日志,告知你应用已成功生成,并且正在 https://localhost:5001/ 提供内容。 若要停止应用程序,请关闭浏览器,然后在命令行会话中按 Ctrl+C

重构知识检查

1.

哪一项表述最能准确描述 OrderStatusHub 类?

2.

为何 SignalR 是客户端轮询的首选替代项?

3.

使用 SignalR 连接时,以下哪种说法是正确的?

4.

在重构过程中,必须更改代码的哪些部分?