ResourceCurrency

using System;  using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI;
using TestFramework;  namespace Tests.resource  { 	/// <summary>
	/// Summary description for ResourceCurrency.
	/// 
	/// this sample creates a currency and exchange range
	/// and then assigns the currency to a resource
	/// </summary>
	public class ResourceCurrency
	{
		// Constructor
		public ResourceCurrency(){}

		//All these variables are used in this sample
		public static String resourceName = "IBM_testABCDEF";
		public static String currencyName = "IBM_CURRENCYABCDEF";
		public static double rate = 50.00;

		//Session ID is use for all transaction and is get from the 
		//Authenticate.login function. The session ID will replace 
		// the User password while transacting
		public static String sessionid = "";

		public void sampleTest()
		{
			// start the communication with the api
			sessionid = APISetup.SetUp();

			// Declare the resource wich we are going to use
			Resource res = null;

			// create a resourceScope to keep track of the relation 
			// between the resource and the currency and rates
			ResourceScope rScope = new ResourceScope();

			// adjust the resource scope to keep the 
			// relations with currency
			rScope.currency = true;

			// create a currency
			Currency  currency = new Currency();

			// create a currency scope 
			CurrencyScope cScope = new CurrencyScope();

			// adjust the currency scope to save exchange ranges
			cScope.currencyExchangeRanges = true;

			// Find the resource in RPM using XPath.
			// Use the fullName to find the resource
			res = (Resource)APISetup.application.
				loadFromXpath(sessionid, 
				"/Resource[fullname='" + resourceName + "']", 
				rScope ).rpmObjectList[0];

			// initialise the currency
			currency.name = currencyName;

			// create an exchange range
			CurrencyExchangeRange exRange = 
				new CurrencyExchangeRange();

			// initialize the exchange range
			exRange.exchangeRate = rate;
			exRange.finishDate = new DateTime(2006, 11,10,10,10,10);
			exRange.startDate = new DateTime(2006, 10,10,10,10,10);
			exRange.parent = currency;

			// assign the exchange range to the currency
			currency.exchangeRanges = 
				new CurrencyExchangeRange[] {exRange};

			// save the currency into the RPM repository
			SaveResult save = APISetup.application.save(sessionid, 
				currency, cScope, ReloadType.ReloadResult );
			APISetup.checkForErrors( save );

			// it is necessary to save the currency 
			// and then assign it to a resource
			// load the currency
			currency = (Currency)APISetup.application.
				loadFromXpath(sessionid, 
				"/Currency[name='" + currencyName + "']", 
				cScope ).rpmObjectList[0];

			// assign the currency and exchange rate to the resource
			res.currency = currency;

			// save the resource in the RPM repository
			// use the sessionid acquired in the setUp
			// use the resource scope
			 save = APISetup.application.save(sessionid, 
				 res, rScope, ReloadType.ReloadResult  );
			APISetup.checkForErrors( save );


			// end the communication with the api.
			APISetup.CleanUp(sessionid);

		}

	}
}