Meyn.TestLink.TestLink.addTestCaseToTestPlan C# (CSharp) Method

addTestCaseToTestPlan() public method

add a test case to a test plan (no way of removing one)
this testExternalid is a string and a concatenation of the test project prefix and the externalid that is reported in the test case creation.
public addTestCaseToTestPlan ( int testprojectid, int testplanid, string testcaseexternalid, int version, int platformid ) : int
testprojectid int
testplanid int
testcaseexternalid string the id that is displayed on the GUI
version int
platformid int
return int
        public int addTestCaseToTestPlan(int testprojectid, int testplanid, string testcaseexternalid, int version, int platformid = 0)
        {
            object o = null;
            stateIsValid();
            if (platformid == 0)
                o = proxy.addTestCaseToTestPlan(devkey, testprojectid, testplanid, testcaseexternalid, version);
            else
                o = proxy.addTestCaseToTestPlan(devkey, testprojectid, testplanid, testcaseexternalid, version, platformid);

            handleErrorMessage(o);
            if (o is XmlRpcStruct) {
                XmlRpcStruct data = o as XmlRpcStruct;
                if ((data != null) && (data.ContainsKey("feature_id"))) {
                    string val = (string)data["feature_id"];
                    int result;
                    bool good = int.TryParse(val, out result);
                    if (good)
                        return result;

                }
            }
            return 0;
        }
        /// <summary>

Usage Example

Example #1
0
        /// <summary>
        /// get a test case id. If the test case does not exist then create one
        /// </summary>
        /// <param name="testName"></param>
        /// <param name="testSuiteId"></param>
        /// <param name="authorId"></param>
        /// <param name="projectId"></param>
        /// <returns>a valid test case id or 0 in case of failure</returns>
        private int getTestCaseId(string testName, int testSuiteId, string authorId, int projectId, int testPlanId)
        {
            int TCaseId = getTestCaseByName(testName, testSuiteId);

            if (TCaseId == 0)
            {
                // need to create test case
                GeneralResult result = proxy.CreateTestCase(authorId, testSuiteId, testName, projectId,
                                                            "Automated TestCase", "", 0,
                                                            true, ActionOnDuplicatedName.Block, 2, 2);
                TCaseId = result.additionalInfo.id;
                int tcExternalId = result.additionalInfo.external_id;
                if (result.status == false)
                {
                    Console.Error.WriteLine("Failed to create TestCase for {0}", testName);
                    Console.Error.WriteLine(" Reason {0}", result.message);
                    return(0);
                }
                string externalId = string.Format("{0}-{1}", currentProject.prefix, tcExternalId);
                int    featureId  = proxy.addTestCaseToTestPlan(currentProject.id, testPlanId, externalId, result.additionalInfo.version_number);
                if (featureId == 0)
                {
                    Console.Error.WriteLine("Failed to assign TestCase {0} to testplan", testName);
                    return(0);
                }
            }
            return(TCaseId);
        }