public void ReferencedModelDuplicateTypeValidationTest()
        {
            var mainModel = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(ValidationTestModelBuilder.ReferenceBasicTestMainModel() as EdmModel);
            var referencedModel = ValidationTestModelBuilder.ReferenceBasicTestReferencedModel();

            var regionType = new EdmComplexType("NS1", "Region");
            regionType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            mainModel.WrappedModel.AddElement(regionType);

            var expectedErrors = new EdmLibTestErrors();
            IEnumerable<EdmError> edmErrors;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.WrappedModel.AddReferencedModel(referencedModel);
            expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.AlreadyDefined },
            };
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.RemoveReference(referencedModel);
            expectedErrors = null;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);
        }
        public void ReferencedModelUnresolvedTermValidationTest()
        {
            var mainModel = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(ValidationTestModelBuilder.ReferenceBasicTestMainModel() as EdmModel);
            var referencedModel = ValidationTestModelBuilder.ReferenceBasicTestReferencedModel();

            var valueAnnotation = new EdmAnnotation(
                mainModel.FindEntityType("NS1.Customer"),
                referencedModel.FindValueTerm("NS1.Title"),
                "q1",
                new EdmStringConstant("Hello world!"));
            mainModel.WrappedModel.AddVocabularyAnnotation(valueAnnotation);

            var expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.BadUnresolvedTerm},
            };
            IEnumerable<EdmError> edmErrors;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.WrappedModel.AddReferencedModel(referencedModel);
            expectedErrors = null;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.RemoveReference(referencedModel);
            expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.BadUnresolvedTerm},
            };
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);
        }
        public void ReferencedModelDuplicatePropertyValidationTest()
        {
            var mainModel = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(ValidationTestModelBuilder.ReferenceBasicTestMainModel() as EdmModel);
            var referencedModel = ValidationTestModelBuilder.ReferenceBasicTestReferencedModel();

            var partnerType = new EdmEntityType("NS1", "Partner", referencedModel.FindEntityType("NS1.Person"), false, true);
            var partnerId = partnerType.AddStructuralProperty("ID2", EdmCoreModel.Instance.GetString(false));
            EdmEntityType regionType = new EdmEntityType("NS1", "Region", null, false, true);
            var regionId = regionType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false));
            regionType.AddKeys(regionId);
            mainModel.WrappedModel.AddElement(partnerType);
            mainModel.WrappedModel.AddElement(regionType);

            var expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.BadUnresolvedType },
            };
            IEnumerable<EdmError> edmErrors;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.WrappedModel.AddReferencedModel(referencedModel);
            expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.AlreadyDefined },
            };
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.RemoveReference(referencedModel);
            expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.BadUnresolvedType },
            };
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);
        }
        public void ReferencedModelUnresolvedTypeValidationTest()
        {
            var mainModel = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(ValidationTestModelBuilder.ReferenceBasicTestMainModel() as EdmModel);
            var referencedModel = ValidationTestModelBuilder.ReferenceBasicTestReferencedModel();

            var partnerType = new EdmEntityType("NS1", "Partner", referencedModel.FindEntityType("NS1.Person"), false, true);
            partnerType.AddStructuralProperty("CustomerID", EdmCoreModel.Instance.GetString(false));
            partnerType.AddStructuralProperty("Region", new EdmComplexTypeReference(referencedModel.FindType("NS1.Region") as EdmComplexType, false));
            mainModel.WrappedModel.AddElement(partnerType);

            IEnumerable<EdmError> edmErrors;
            mainModel.Validate(out edmErrors);
            var expectedErrors = new EdmLibTestErrors()
            {
                { "(NS1.Partner)", EdmErrorCode.BadUnresolvedType},
                { "([NS1.Region Nullable=False])", EdmErrorCode.BadUnresolvedType},
            };
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.WrappedModel.AddReferencedModel(referencedModel);
            mainModel.Validate(out edmErrors);
            expectedErrors = null;
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.RemoveReference(referencedModel);
            mainModel.Validate(out edmErrors);
            expectedErrors = new EdmLibTestErrors()
            {
                { "(NS1.Partner)", EdmErrorCode.BadUnresolvedType},
                { "([NS1.Region Nullable=False])", EdmErrorCode.BadUnresolvedType},
            };
            this.CompareErrors(edmErrors, expectedErrors);
        }