ALM Open Test Architecture API Reference Version 12.55
C# Create a test with configurations
Example Title
Copy Code
/*
 * How to call:
     TestFactory tF = (TestFactory)tdConnection.TestFactory;
     TDFilter tFilter = tF.Filter;
     tFilter["TS_NAME"] = "test5";
     List tList = tFilter.NewList();
     Test tTest = (Test)tList[1];
     CheckoutEntity(tTest, "Hello", true);

     QCResourceFolderFactory qcResourceFolderF = tdConnection.QCResourceFolderFactory;
     TDFilter tFilterQC = qcResourceFolderF.Filter;
     tFilterQC["RFO_NAME"] = "test";
     List tLists = tFilterQC.NewList();

     QCResourceFolder qcResourceFolder = tLists[1];
     QCResourceFactory qcResourceF = (QCResourceFactory) qcResourceFolder.QCResourceFactory;//tdConnection.QCResourceFactory;
     TDFilter tf1 = qcResourceF.Filter;
     tf1["RSC_CREATED_BY"] = "sa";
     List tfLists = tf1.NewList();
    QCResource configResource = tfLists[2];
    QCResource testResource = tfLists[3];

    CreateTestWithConfigurations(tTest, qcResourceFolder, testResource, configResource);
 */
private bool CreateTestWithConfigurations(Test checkLoginTest, QCResourceFolder resourceRootFolder, QCResource testResource, QCResource configResource)
{
  try
  {
    QCResourceFactory resourceRootFolderFactory;
    IResourceStorage testResourceStorage;
    ISupportDataRelation testDataRelation;
    IResourceStorage configResourceStorage;
    ISupportDataRelation cDataRelation;

    TestConfigFactory cFact;
    TestConfig configVIP;

    String theDataMapping = String.Empty;
    String errmsg = String.Empty;

    //Check out the test. For code of CheckoutTest(), see example "Checking out a Test"
    VCS testVCS;
    bool checkInOutOK = true;

    testVCS = CheckoutTest(checkLoginTest, "Create Configurations", ref checkInOutOK);
    if (!checkInOutOK)
    {
      errmsg = "Error checking out checkLoginTest";
      return false;
    }
    
    resourceRootFolderFactory = resourceRootFolder.QCResourceFactory;
    //Create a resource to hold the parameter data at the test level
    errmsg = "Error creating resourceRootFolderFactory";
    testResource = resourceRootFolderFactory.AddItem("Test Data Resource");
    testResource.ResourceType = "Data table";
    testResource.FileName = "test.xml";
    testResource.Post();

    errmsg = "Error loading testResourceStorage";        
    testResourceStorage = (IResourceStorage)testResource;
    testResourceStorage.UploadResource(@"C:\temp", true);

    //Set the resource to be the data resource at the test level
    errmsg = "Error creating testDataRelation";        
    testDataRelation = (ISupportDataRelation)checkLoginTest;
    
    theDataMapping =
      @"<MappingData><MappingElement><ParameterName><![CDATA[FlightNo]]></ParameterName><MappedToName><![CDATA[flight_number]]></MappedToName></MappingElement></MappingData>";
    testDataRelation.CreateDataRelation(testResource.ID, theDataMapping);

    //Create a new configuration for the test
    errmsg = "Error creating configVIP";

    cFact = checkLoginTest.TestConfigFactory;
    configVIP = cFact.AddItem(DBNull.Value);
    configVIP["TSC_NAME"] = "Configuration for VIP user";
    configVIP["TSC_DESC"] = "Check login with VIP user";
    configVIP.Post();

    //Create a resource to hold the parameter data at the configuration level
    errmsg = "Error creating configResource";
    configResource = resourceRootFolderFactory.AddItem("Configuration Data Resource");
    configResource.ResourceType = "Data table";
    configResource.FileName = "config.xml";
    configResource.Post();

    errmsg = "Error loading configResource";       
    configResourceStorage = (IResourceStorage)configResource;
    configResourceStorage.UploadResource(@"C:\temp", true);

    //Set the resource to be the data resource at the configuration level
    errmsg = "Error creating cDataRelation";        
    cDataRelation = (ISupportDataRelation)configVIP;
    cDataRelation.CreateDataRelation(configResource.ID, "");

    //Set the configuration to use the data resource at the configuration level
    errmsg = "Error setting configVIP data state";
    configVIP["TSC_DATA_STATE"] = 2;
    configVIP.Post();

    //See example "Checking in a Test"
    //checkInOutOK = CheckinTest(testVCS, "Created configurations");
    if (!checkInOutOK)
    {
      errmsg = "Error checking in checkLoginTest";
      return false;
    }
    else
    {
      return true;
    }
  }
  catch (Exception)
  {
    return false;
  }
}