public void TestProcessApplication()
        {
            string JSONFormData = "{'RegistrationOffice':'#REGISTRATIONOFFICE_VALUE'," +
                                  "'EventIdentifier':'#EVENTCODE','EventPartnerKey':'#EVENTPARTNERKEY'," +
                                  "'RegistrationCountryCode':'#CULTURECODE','EventPartnerKey':'#EVENTPARTNERKEY'," +
                                  "'Role':'#ROLE','FirstName':'#FIRSTNAME','LastName':'#LASTNAME'," +
                                  "'Street':'#STREET','Postcode':'#POSTCODE','City':'#CITY','Country':'#COUNTRY_VALUE'," +
                                  "'Phone':'#PHONE','Email':'#EMAIL','DateOfBirth':'#DATEOFBIRTH'," +
                                  "'Gender':'#GENDER','Vegetarian':'#VEGETARIAN','MedicalNeeds':'#MEDICALNEEDS','PaymentInfo':'#PAYMENTINFO'}";

            StringBuilder json = new StringBuilder(JSONFormData);

            Dictionary <string, string> values = new Dictionary <string, string>();

            values.Add("EventCode", EventCode);
            values.Add("EventPartnerKey", EventPartnerKey.ToString());

            string cultureCode = "de-DE";

            values.Add("RegistrationCountryCode", cultureCode);

            Int64  RegistrationOffice = 43000000;
            string CountryIsoCode     = "DE";

            DateTime DateOfBirth = new DateTime(1990, 12, 20);
            string   role        = "TS-SERVE";

            values.Add("RegistrationOffice_Value", RegistrationOffice.ToString());
            values.Add("Role", role);
            values.Add("FormsId", "\"");
            values.Add("culturecode", cultureCode);

            values.Add("FirstName", "Hans");
            values.Add("LastName", "Bambel");
            values.Add("Gender", "Male");
            values.Add("Vegetarian", "No");

            string EmailAddress = "*****@*****.**";

            values.Add("Email", EmailAddress);
            values.Add("Street", "Bahnhofstr. 1");
            values.Add("Postcode", "12345");
            values.Add("City", "Berlin");
            values.Add("Country_VALUE", CountryIsoCode);
            values.Add("MedicalNeeds", "test with \"quote\" in text");
            values.Add("PaymentInfo", "NONE");

            Catalog.Init("en-GB", cultureCode);
            values.Add("DateOfBirth", DateOfBirth.ToShortDateString()); // in the culture of the country code

            foreach (string key in values.Keys)
            {
                string value = values[key].ToString().Trim();

                json.Replace("#" + key.ToUpper(), value);
            }

            string result = TImportPartnerForm.DataImportFromForm("RegisterPerson", json.ToString(), false);

            Assert.AreEqual("{\"failure\":true, \"data\":{\"result\":\"We were not able to send the email to " + EmailAddress + "\"}}",
                            result,
                            "everything but sending the email should work");
        }
        /// <summary>
        /// generate the applications
        /// </summary>
        public static void GenerateApplications(string AApplicationCSVFile)
        {
            XmlDocument doc = TCsv2Xml.ParseCSV2Xml(AApplicationCSVFile, ",", Encoding.UTF8);

            XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild;

            // create registration offices
            GenerateRegistrationOffices("United Kingdom", 21000000, "GB");
            GenerateRegistrationOffices("France", 22000000, "FR");
            GenerateRegistrationOffices("Norway", 23000000, "NO");
            GenerateRegistrationOffices("USA", 24000000, "US");
            GenerateRegistrationOffices("Germany", 43000000, "DE");

            PUnitTable unitTable = new PUnitTable();
            // get a list of fields (all class UNIT, with unit type F)
            string sqlGetFieldPartnerKeys = "SELECT * FROM PUB_p_unit WHERE u_unit_type_code_c = 'F'";

            DBAccess.GDBAccessObj.SelectDT(unitTable, sqlGetFieldPartnerKeys, null, new OdbcParameter[0], 0, 0);

            PcConferenceTable conferenceTable   = PcConferenceAccess.LoadByPrimaryKey(1110198, null);
            DateTime          StartOfConference = conferenceTable[0].Start.Value;

            int counterApplicants = 0;

            while (RecordNode != null)
            {
                string JSONFormData = "{'RegistrationOffice':'#REGISTRATIONOFFICE_VALUE'," +
                                      "'EventIdentifier':'#EVENTCODE','EventPartnerKey':'#EVENTPARTNERKEY'," +
                                      "'RegistrationCountryCode':'#CULTURECODE','EventPartnerKey':'#EVENTPARTNERKEY'," +
                                      "'Role':'#ROLE','FirstName':'#FIRSTNAME','LastName':'#LASTNAME'," +
                                      "'Street':'#STREET','Postcode':'#POSTCODE','City':'#CITY','Country':'#COUNTRY_VALUE'," +
                                      "'Phone':'#PHONE','Email':'#EMAIL','DateOfBirth':'#DATEOFBIRTH','ImageID':'#IMAGEID'," +
                                      "'DateOfArrival':'#DATEOFARRIVAL','DateOfDeparture':'#DATEOFDEPARTURE'," +
                                      "'Gender':'#GENDER','Vegetarian':'#VEGETARIAN','MedicalNeeds':'#MEDICALNEEDS','PaymentInfo':'#PAYMENTINFO'}";

                StringBuilder json = new StringBuilder(JSONFormData);

                Dictionary <string, string> values = new Dictionary <string, string>();

                values.Add("EventCode", "SC001CNGRSS08");
                values.Add("EventPartnerKey", conferenceTable[0].ConferenceKey.ToString());

                string cultureCode = TXMLParser.GetAttribute(RecordNode, "RegistrationCountryCode");
                cultureCode = cultureCode.Substring(0, 2) + "-" + cultureCode.Substring(2, 2);
                values.Add("RegistrationCountryCode", cultureCode);

                Int64  RegistrationOffice = 43000000;
                string CountryIsoCode     = "DE";

                foreach (PUnitRow unitRow in unitTable.Rows)
                {
                    if (cultureCode.EndsWith(unitRow.CountryCode))
                    {
                        RegistrationOffice = unitRow.PartnerKey;
                        CountryIsoCode     = unitRow.CountryCode;
                    }
                }

                string role = TXMLParser.GetAttribute(RecordNode, "role");
                int    age  = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "age"));

                if (role == "TEEN")
                {
                    // make the age fit
                    age = 12 + age % 6;
                }
                else if (role == "CHILD")
                {
                    age = age % 11;
                }
                else
                {
                    age = 18 + age % 40;
                }

                DateTime DateOfBirth = Convert.ToDateTime(
                    TXMLParser.GetAttribute(RecordNode, "DateOfBirth"));
                int CurrentAge = StartOfConference.Year - DateOfBirth.Year;

                if (DateOfBirth > StartOfConference.AddYears(-age))
                {
                    CurrentAge--;
                }

                DateOfBirth = DateOfBirth.AddYears(CurrentAge - age);

                if (age <= 11)
                {
                    role = "TS-CHILD";
                }
                else if (age <= 15)
                {
                    role = "TS-TEEN-A";
                }
                else if (age <= 17)
                {
                    role = "TS-TEEN-O";
                }
                else
                {
                    role = "TS-" + TXMLParser.GetAttribute(RecordNode, "role");
                }

                values.Add("RegistrationOffice_Value", RegistrationOffice.ToString());
                values.Add("Role", role);
                values.Add("FormsId", "\"");
                values.Add("culturecode", cultureCode);

                values.Add("FirstName", TXMLParser.GetAttribute(RecordNode, "FirstName"));
                values.Add("LastName", TXMLParser.GetAttribute(RecordNode, "FamilyName"));
                values.Add("Gender",
                           (TXMLParser.GetAttribute(RecordNode, "Gender") == "MALE" ? "Male" : "Female"));
                values.Add("Vegetarian", "No");

                string EmailAddress = TXMLParser.GetAttribute(RecordNode, "Email");
                EmailAddress = EmailAddress.Substring(0, EmailAddress.IndexOf("@")) + "@sample.openpetra.org";

                values.Add("Email", EmailAddress);
                values.Add("Street", TXMLParser.GetAttribute(RecordNode, "Street"));
                values.Add("Postcode", TXMLParser.GetAttribute(RecordNode, "PostCode"));
                values.Add("City", TXMLParser.GetAttribute(RecordNode, "City"));
                values.Add("Country_VALUE", CountryIsoCode);
                values.Add("MedicalNeeds", "test with \"quote\" in text");
                values.Add("PaymentInfo", "NONE");

                Catalog.Init("en-GB", cultureCode);
                values.Add("DateOfBirth", DateOfBirth.ToShortDateString()); // in the culture of the country code
                values.Add("DateOfArrival", StartOfConference.ToShortDateString());
                values.Add("DateOfDeparture", StartOfConference.AddDays(5).ToShortDateString());

                values.Add("IMAGEID", "temp.jpg");

                // copy photo to the data/photos directory
                string photo = "469px-Ernest_Hemingway_1923_passport_photo.TIF.jpg";

                if (TXMLParser.GetAttribute(RecordNode, "Gender") == "FEMALE")
                {
                    photo = "388px-Droste-Hülshoff_2.jpg";
                }

                File.Copy(TAppSettingsManager.GetValue("Server.PathTemp") + "/../webserver/Samples/UploadDemo/" + photo,
                          TAppSettingsManager.GetValue("Server.PathTemp") + Path.DirectorySeparatorChar +
                          "temp.jpg", true);

                foreach (string key in values.Keys)
                {
                    string value = values[key].ToString().Trim();

                    json.Replace("#" + key.ToUpper(), value);
                }

                string result = TImportPartnerForm.DataImportFromForm("RegisterPerson", json.ToString(), false);

                if (TLogging.DebugLevel >= 10)
                {
                    TLogging.Log(result);
                }

                counterApplicants++;

                if (counterApplicants % 100 == 0)
                {
                    TLogging.Log("created " + counterApplicants.ToString() + " applicants");
                }

                RecordNode = RecordNode.NextSibling;
            }

            // TODO accept applications

            // TODO give permissions to Demo user. create one user for each registration office
        }