如何编写需要.net页面请求的单元测试用例?

编程入门 行业动态 更新时间:2024-10-27 04:38:14
本文介绍了如何编写需要页面请求的单元测试用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

I have following asp PageContactand havingTestHandlerDemoClasswhich is having one method I want to write a unit test case for that method but when I tried it usingMSTest projectit throws exception likeRequest not available in this context

public partial class Contact : Page { } public class TestHandlerDemoClass { public void MyTestMethod(Page mypage) {

字符串 id = mypage . 请求 [ "EntityId" ] //在这里,我没有在Mypage内收到请求

string id= mypage.Request["EntityId"] //here I'm not getting Request inside mypage

My Test Project code -

[TestClass] public class UnitTest1 { [TestMethod] public void NullCheck() { try { Contact contactPage = new Contact(); TestHandlerDemoClass mydemo = new TestHandlerDemoClass(); mydemo.MyTestMethod(contactPage); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Id not found"); } } }

here in above ex I got message like{"Request is not available in this context"}

我只是想为方法` public void MyTestMethod ( 页面 mypage ) `,它将"Page mypage"作为参数.

I 'm just trying to write unit test cases for method ` public void MyTestMethod(Page mypage) ` which takes `Page mypage` as parameter.

怎么做?

SE

推荐答案

I have following asp PageContactand havingTestHandlerDemoClasswhich is having one method I want to write a unit test case for that method but when I tried it usingMSTest projectit throws exception likeRequest not available in this context

public partial class Contact : Page { } public class TestHandlerDemoClass { public void MyTestMethod(Page mypage) {

字符串id = mypage. Request [" EntityId";] //这里我没有在我的页面中获得请求

string id= mypage.Request["EntityId"] //here I'm not getting Request inside mypage

我的测试项目代码-

My Test Project code -

[TestClass] public class UnitTest1 { [TestMethod] public void NullCheck() { try { Contact contactPage = new Contact(); TestHandlerDemoClass mydemo = new TestHandlerDemoClass(); mydemo.MyTestMethod(contactPage); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Id not found"); } } }

在上面的ex中,我得到了如下消息: {"请求 在此上下文中不可用"}

here in above ex I got message like{"Request is not available in this context"}

更多推荐

如何编写需要.net页面请求的单元测试用例?

本文发布于:2023-11-26 14:17:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634110.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   页面   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!