System.Web.Abstractions:它有什么用? [英] System.Web.Abstractions: what is it good for?

查看:30
本文介绍了System.Web.Abstractions:它有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

...完全没有?

它分别为 ASP.NET WebFormsASP.NET MVC 填补了哪一部分难题?

What part of the puzzle does it fill for ASP.NET WebForms and ASP.NET MVC respectively?

您能否以某种方式创建一个使用 System.Web.Abstractions 的 ASP.NET * 基础应用程序,以便它可以在两种 ASP.NET 网络应用程序中使用?

Can you somehow create a ASP.NET * base-application which uses System.Web.Abstractions so it can be used in both kinds of ASP.NET-web applications?

在那种情况下,他们是如何将 System.Web.Abstractions 中的类改回 ASP.NET WebForms 的?

In that case, how did they retro-fit the classes in System.Web.Abstractions back into ASP.NET WebForms?

你不能从命名空间中新建对象,所以它不能用于模拟,是吗?

You can't new up objects from the namespace, so it can't be used for mocking, can it?

更新:抱歉我不清楚我知道测试 HttpContext 和其他构建 ASP.NET 对象的问题.不过还是谢谢你的好解释.

Update: Sorry for not being clear on that I know the problem with testing of HttpContext and other build-it ASP.NET-objects. But thanks for good explanations anyway.

推荐答案

命名空间包含旨在包装 ASP.NET 核心类(例如 HttpSessionState)的类型.

The namespace contains types that are designed to wrap ASP.NET's core classes (such as HttpSessionState).

什么,你想知道为什么?

What, you want to know why?

这些核心 ASP.NET 类中有许多是密封的或静态的,因此无法打破它们与您的代码之间的依赖关系.这意味着您无法模拟这些核心依赖项,从而使测试 ASP.NET 代码变得更加困难.因此,不是直接在代码中直接操作 HttpResponse,而是通过 HttpResponseWrapper,在测试期间,您可以存根或模拟以控制 HttpResponse 对象的行为.

Many of these core ASP.NET classes are sealed or static, making it impossible to break dependencies between them and your code. THAT means you can't mock these core dependencies, making it much harder to test your ASP.NET code. So, instead of directly manipulating the HttpResponse directly in code, you manipulate it via the HttpResponseWrapper, which, during test time, you can stub or mock out to control how the HttpResponse object behaves.

如果您曾经想过创建这些包装器,或者之前已经实现了其中的一两个,您就会知道该命名空间中包含了很多工作,而我,首先,很高兴他们做到了.

If you've ever thought about creating these wrappers, or have implemented one or two of them before, you'd know that there's lots of work wrapped up in that namespace, and I, for one, am glad they did it.

这篇关于System.Web.Abstractions:它有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆