zoukankan      html  css  js  c++  java
  • VS2012 测试WebService

    测试本机webservice :

    要点说明:

    1.TestContext :使用 TestContext 类

    2.AspNetDevelopmentServer:AspNetDevelopmentServerAttribute 类

    3.TryUrlRedirection方法:WebServiceHelper.TryUrlRedirection

    测试:

    使用工具:VS2012

    首先新建一个服务项目WebService1,然后新建测试项目

    在测试项目里添加服务引用,在服务引用对话框里点高级,然后在兼容性下面点添加web引用,在弹出的添加web引用对话框里点击此解决方案中的web服务,选中服务,点击添加引用。

    实现代码:

    View Code
      public class UnitTest1
        {
            private TestContext testContextInstance;
            /// <summary>
            ///Gets or sets the test context which provides
            ///information about and functionality for the current test run.
            ///</summary>
            public TestContext TestContext
            {
                get
                {
                    return testContextInstance;
                }
                set
                {
                    testContextInstance = value;
                }
            }
    
            [TestMethod]
            [AspNetDevelopmentServer("HelloTest", @"E:\新建文件夹\WebService1\WebService1")]
            public void TestMethod1()
            {
                Service1 target = new Service1();
                
                Assert.IsTrue(
                   
                    WebServiceHelper.TryUrlRedirection(target, testContextInstance, "HelloTest"), "Web service redirection failed"
                    );
    
                string expected = "Hello World";
                string  actual = target.HelloWorld();
    
                Assert.AreEqual(expected, actual, "test");
    
            }
        }

    TestContext属性手动写进行就行了,系统会自动赋值;

    AspNetDevelopmentServer特性 第一个参数是 可以理解为服务器名称,第二个参数是 服务项目路径,第三个参数为虚拟路径

    TryUrlRedirection方法 第一个参数为service1 的对象,第二个参数为TestContext 类型的变量,第三个参数为 AspNetDevelopmentServer特性声明时的第一个参数即服务器名称。

  • 相关阅读:
    Win10 VirtualBox 安装 OpenWrt/LEDE
    在华为云、腾讯云服务器中部署 Hadoop 集群
    记一次部署Hadoop后遭受kthreaddi挖矿病毒
    四种基本编程命名法
    词云图制作
    在Ubuntu18.04lts下安装NS2(含nam)
    二叉树的建立与遍历
    国内pip镜像
    java高斯消元模板
    图的3种储存方式
  • 原文地址:https://www.cnblogs.com/CLR010/p/3045442.html
Copyright © 2011-2022 走看看