예제 #1
0
        protected void ValidateArchetype(Archetype archetype)
        {
            this.Validate((AuthoredResource)archetype);

            Invariant(archetype.ArchetypeId != null, string.Format(
                          CommonStrings.XMustNotBeNull, "Archetype.ArchetypeId"));
            this.Validate(archetype.ArchetypeId);

            Invariant(archetype.Ontology.HasTermCode(archetype.Definition.NodeId),
                      AmValidationStrings.OntologyMissingDefinitionTerm);
            Invariant(archetype.Uid == null || !string.IsNullOrEmpty(archetype.Uid.Value),
                      string.Format(CommonStrings.IfXIsNotNullMustBeEmpty, "Archetype.Uid"));
            if (archetype.Uid != null)
            {
                this.Validate(archetype.Uid);
            }

            Invariant(!string.IsNullOrEmpty(archetype.Concept),
                      string.Format(CommonStrings.XMustNotBeNullOrEmpty, "Archetype.Concept"));

            if (archetype.ParentArchetypeId != null)
            {
                this.Validate(archetype.ParentArchetypeId);
            }

            Invariant(archetype.Version() != null, string.Format(CommonStrings.XMustNotBeNull, "Archetype.Version()"));
            Invariant(archetype.Version() == archetype.ArchetypeId.VersionId, AmValidationStrings.ArchetypeVersionNotEqual);

            Invariant(archetype.OriginalLanguage != null,
                      string.Format(CommonStrings.XMustNotBeNull, "Archetype.OriginalLanguage"));
            this.Validate(archetype.OriginalLanguage);

            Invariant(archetype.Description != null,
                      string.Format(CommonStrings.XMustNotBeNull, "Archetype.Description"));

            Invariant(archetype.Definition != null,
                      string.Format(CommonStrings.XMustNotBeNull, "Archetype.Definition"));
            this.Validate(archetype.Definition);

            Invariant(archetype.Ontology != null, "Archetype.Ontology must not be null.");
            this.Validate(archetype.Ontology);

            Invariant(!archetype.IsSpecialised() ^ (archetype.IsSpecialised() && archetype.SpecialisationDepth() > 0),
                      AmValidationStrings.ArchetypeSpecialisationInvariantFail);

            Invariant(archetype.Invariants == null || !archetype.Invariants.IsEmpty(),
                      string.Format(CommonStrings.IfXIsNotNullMustBeEmpty, "Archetype.Invariants"));
            if (archetype.Invariants != null)
            {
                foreach (Assertion eachInvariant in archetype.Invariants)
                {
                    this.Validate(eachInvariant);
                }
            }
        }