jeudi 24 septembre 2015

Unit Testing Scenario

I have a method that takes the users ldap roles and evaluates each of his/her roles against a list called "ValidRoles" in the websites web.config file. We will assume that the users roles will remain the same accross different users for the purposes of this test.

Now I would like to trick the method into taking in a different list (rather than the one in my web.config) to compare against when I run my unit test. How can I do this ? I am new to unit testing. I appreciate any suggestions. The method I am testing, the ValidRoles from the web.config, and an existing unit test I have are shown below.

   private bool IsValidClaimStationRoles()
    {
        foreach (string role in RoleList)
        {
            if (role != null)
            {
                if (ValidRoleList.Contains(role.ToUpper()))
                {
                    return true;
                }
            }
        }
        return false;

//Valid roles from web.config

 <add key="ValidRoles" value="C-2,CP-1,CM-1,CIS-1,CID-1"/>

//Unit test

       [TestMethod()]
    [DeploymentItem("ClaimsDocMgmtLinkWeb.dll")]
    public void IsValidClaimStationRolesTest_Negative()
    {

        AuthenticateUser_Accessor target = new AuthenticateUser_Accessor(); // TODO: Initialize to an appropriate value
        target.CreateTicket();
        bool expected = false; 
        bool actual;



        actual = target.IsValidClaimStationRoles();
        Assert.AreEqual(expected, actual);

    }

Aucun commentaire:

Enregistrer un commentaire