public void TestOrganisationUnitMutableCoreSetParentUnit(string parentUnit, bool hasParent)
        {
            var organisationScheme = new OrganisationUnitSchemeMutableCore() { Id = "TEST", AgencyId = "TEST", Version = "1.0" };
            organisationScheme.AddName("en", "Test organisation unit scheme");
            var unit = organisationScheme.CreateItem("TEST_UNIT1", "Test organisation unit");
            unit.ParentUnit = parentUnit;
            if (!string.IsNullOrWhiteSpace(parentUnit))
            {
                organisationScheme.CreateItem(parentUnit, parentUnit);
            }

            var immutable = organisationScheme.ImmutableInstance;
            var first = immutable.Items.First(organisationUnit => organisationUnit.Id.Equals(unit.Id));
            Assert.AreEqual(hasParent, first.HasParentUnit, first.ParentUnit);
            if (first.HasParentUnit)
            {
                Assert.AreEqual(parentUnit, first.ParentUnit);
            }
        }
        private IOrganisationUnitSchemeMutableObject GetOrganizationUnitschemeForm()
        {
            bool isInError = false;                 // Indicatore di errore
            string messagesGroup = string.Empty;    // Stringa di raggruppamento errori
            int errorCounter = 1;                   // Contatore errori

            #region ORGANIZATIONUNITSCHEME ID
            if (!ValidationUtils.CheckIdFormat(txtDSDID.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_id_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region ORGANIZATIONUNITSCHEME AGENCY
            if ( cmbAgencies.Text.Trim().Equals( string.Empty ) )
            {
                messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_agency_missing + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region ORGANIZATIONUNITSCHEME VERSION
            if (!ValidationUtils.CheckVersionFormat(txtVersion.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_version_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            /* URI NOT REQUIRED */
            #region ORGANIZATIONUNITSCHEME URI
            if ((txtDSDURI.Text != string.Empty) && !ValidationUtils.CheckUriFormat(txtDSDURI.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_uri_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region ORGANIZATIONUNITSCHEME NAMES
            if (AddTextName.TextObjectList == null || AddTextName.TextObjectList.Count == 0)
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_list_name_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region ORGANIZATIONUNITSCHEME START END DATE
            bool checkForDatesCombination = true;

            if (!txtValidFrom.Text.Trim().Equals(string.Empty) && !ValidationUtils.CheckDateFormat(txtValidFrom.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_date_from_format + "<br /><br />";
                errorCounter++;
                checkForDatesCombination = false;
                isInError = true;
            }

            if (!txtValidTo.Text.Trim().Equals(string.Empty) && !ValidationUtils.CheckDateFormat(txtValidTo.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_date_to_format + "<br /><br />";
                errorCounter++;
                checkForDatesCombination = false;
                isInError = true;
            }

            if (!txtValidFrom.Text.Trim().Equals(string.Empty) && !txtValidTo.Text.Trim().Equals(string.Empty))
            {
                // Controllo congruenza date
                if (checkForDatesCombination)
                {
                    if (!ValidationUtils.CheckDates(txtValidFrom.Text, txtValidTo.Text))
                    {
                        messagesGroup += Convert.ToString(errorCounter) + ")" + Resources.Messages.err_date_diff + "<br /><br />";
                        errorCounter++;
                        isInError = true;
                    }
                }
            }
            #endregion

            if (isInError)
            {
                Utils.ShowDialog(messagesGroup, 300);
                return null;
            }

            IOrganisationUnitSchemeMutableObject tmpOrganizationUnitscheme = new OrganisationUnitSchemeMutableCore();
            #region CREATE ORGANIZATIONUNITSCHEME FROM FORM

            tmpOrganizationUnitscheme.AgencyId = GetAgencyValue();
            tmpOrganizationUnitscheme.Id = txtDSDID.Text;
            tmpOrganizationUnitscheme.Version = txtVersion.Text;
            tmpOrganizationUnitscheme.FinalStructure = TertiaryBool.ParseBoolean(chkIsFinal.Checked);
            tmpOrganizationUnitscheme.Uri = (!txtDSDURI.Text.Trim().Equals( string.Empty ) && ValidationUtils.CheckUriFormat(txtDSDURI.Text)) ? new Uri(txtDSDURI.Text) : null;
            if (!txtValidFrom.Text.Trim().Equals(string.Empty))
            {
                tmpOrganizationUnitscheme.StartDate = DateTime.ParseExact(txtValidFrom.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            if (!txtValidTo.Text.Trim().Equals(string.Empty))
            {
                tmpOrganizationUnitscheme.EndDate = DateTime.ParseExact(txtValidTo.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            foreach (var tmpName in AddTextName.TextObjectList)
            {
                tmpOrganizationUnitscheme.AddName(tmpName.Locale, tmpName.Value);
            }
            if (AddTextDescription.TextObjectList != null)
                foreach (var tmpDescription in AddTextDescription.TextObjectList)
                {
                    tmpOrganizationUnitscheme.AddDescription(tmpDescription.Locale, tmpDescription.Value);
                }
            if (AnnotationGeneralControl.AnnotationObjectList != null)
                foreach (var annotation in AnnotationGeneralControl.AnnotationObjectList)
                {
                    tmpOrganizationUnitscheme.AddAnnotation(annotation);
                }

            #endregion

            return tmpOrganizationUnitscheme;
        }