开发者

unit testing using VSTS wcf service in c#

开发者 https://www.devze.com 2023-03-14 00:31 出处:网络
I am trying to test my wcf service using the test suite in TFS. I have a wcf servic开发者_C百科e in Solution called Inspector.
  • I am trying to test my wcf service using the test suite in TFS.

    • I have a wcf servic开发者_C百科e in Solution called Inspector.
    • In that the config file is in InspectorHost Project
    • There are helper Methods in MessageInspector project.
    • In this there is a method called CallIssService.
    • This IssService is the Service used by MessageInspector Project.
    • Though the service reference is in this project,the Config file is in InspectorHost project.
    • The test method generated for this method is CallIssServiceTest.cs.

    • Here is the porblem. When I try to run the test on this method the test fails and the error is "The URL to test is not specified. Tests configured to run in ASP.NET must specify a valid URL". The URL it is asking is the URL of the IssService the MessageInspector Project is using.

Here is the code for test method. `

    /// <summary>
    ///A test for CallIss
    ///</summary>
    [TestMethod()] 
    [DeploymentItem("Inspector.MessageInspector.dll")]
    public void CallIssServiceTest()
    {
        CustomUserNameValidator_Accessor target = new CustomUserNameValidator_Accessor();
        target._userName = "tempUserName";
        target._password = "temptemp";

        Identity expected = new Identity();
        expected.UserID = "tempUserName";
        expected.board = new Board();
        expected.board.Code = "013";

        Identity actual;
        actual = target.CallIAA();
        Assert.IsNotNull(actual);
        Assert.AreEqual(expected.UserID, actual.UserID);
        Assert.AreEqual(expected.board.Code, actual.board.Code);  
    }

`

Here is the class to be tested.

    using IssService;
    /// <summary>
    /// This calles the Iss Service to Authenticate the user
    /// </summary>
    /// <returns></returns>
    private Identity CallIssService()
    {
        Identity userIdentity = 
         new IssServiceClient().VerifyUser(_userName, _password, null);
        return userIdentity;
    }

Can some body please help me understand what is the mistake I am doing or is there anything more to be done in this context.

Thanks in advance for any help.

Regards, Chand.


Fix (this link helped me.)


1) In the LocalTestRun.testrunConfigfile/deployment the Web.Config file in host project is selected.Click Apply and save this.

2) A RenameWebConfig.bat file is added in the folder of test project with below one line of code indicating it to copy the Web.config file and rename it every time there is a new build.

rename web.config UAWebService.TestProject.dll.config

Hence the issue of Config settings not visible to the test project is defeated. Wonder why Microsoft skipped this aspect ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消