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页面请求的单元测试用例?
发布评论