예제 #1
0
        public void Code_first_ErrorInfo_initialized_correctly()
        {
            var edmxErrorInfo = 
                new ErrorInfo(ErrorInfo.Severity.WARNING, "test", @"c:\project\model.edmx" , 17, ErrorClass.None);

            Assert.Equal(0, edmxErrorInfo.GetLineNumber());
            Assert.Equal(0, edmxErrorInfo.GetColumnNumber());
            Assert.False(edmxErrorInfo.IsError());
            Assert.True(edmxErrorInfo.IsWarning());
            Assert.False(edmxErrorInfo.IsInfo());

            Assert.Equal(string.Format(Resources.Error_Message_With_Error_Code_Prefix, 17, "test"), edmxErrorInfo.Message);
            Assert.Same(null, edmxErrorInfo.Item);
            Assert.Equal(@"c:\project\model.edmx", edmxErrorInfo.ItemPath);
            Assert.Equal(17, edmxErrorInfo.ErrorCode);
            Assert.Equal(ErrorClass.None, edmxErrorInfo.ErrorClass);
        }
예제 #2
0
        public void Code_first_ErrorInfo_initialized_correctly()
        {
            var edmxErrorInfo =
                new ErrorInfo(ErrorInfo.Severity.WARNING, "test", @"c:\project\model.edmx", 17, ErrorClass.None);

            Assert.Equal(0, edmxErrorInfo.GetLineNumber());
            Assert.Equal(0, edmxErrorInfo.GetColumnNumber());
            Assert.False(edmxErrorInfo.IsError());
            Assert.True(edmxErrorInfo.IsWarning());
            Assert.False(edmxErrorInfo.IsInfo());

            Assert.Equal(string.Format(Resources.Error_Message_With_Error_Code_Prefix, 17, "test"), edmxErrorInfo.Message);
            Assert.Same(null, edmxErrorInfo.Item);
            Assert.Equal(@"c:\project\model.edmx", edmxErrorInfo.ItemPath);
            Assert.Equal(17, edmxErrorInfo.ErrorCode);
            Assert.Equal(ErrorClass.None, edmxErrorInfo.ErrorClass);
        }
예제 #3
0
        public void Edmx_ErrorInfo_initialized_correctly()
        {
            var mockEFObject = new Mock<EFObject>();
            mockEFObject.Setup(o => o.GetLineNumber()).Returns(76);
            mockEFObject.Setup(o => o.GetColumnNumber()).Returns(12);
            mockEFObject.Setup(o => o.Uri).Returns(new Uri(@"c:\project\model.edmx"));

            var edmxErrorInfo = 
                new ErrorInfo(ErrorInfo.Severity.ERROR, "test", mockEFObject.Object, 42, ErrorClass.Runtime_CSDL);

            Assert.Equal(76, edmxErrorInfo.GetLineNumber());
            Assert.Equal(12, edmxErrorInfo.GetColumnNumber());
            Assert.True(edmxErrorInfo.IsError());
            Assert.False(edmxErrorInfo.IsWarning());
            Assert.False(edmxErrorInfo.IsInfo());
            Assert.Equal(string.Format(Resources.Error_Message_With_Error_Code_Prefix, 42, "test"), edmxErrorInfo.Message);
            Assert.Same(mockEFObject.Object, edmxErrorInfo.Item);
            Assert.Equal(@"c:\project\model.edmx", edmxErrorInfo.ItemPath);
            Assert.Equal(42, edmxErrorInfo.ErrorCode);
            Assert.Equal(ErrorClass.Runtime_CSDL, edmxErrorInfo.ErrorClass);
        }
예제 #4
0
        public void Edmx_ErrorInfo_initialized_correctly()
        {
            var mockEFObject = new Mock <EFObject>();

            mockEFObject.Setup(o => o.GetLineNumber()).Returns(76);
            mockEFObject.Setup(o => o.GetColumnNumber()).Returns(12);
            mockEFObject.Setup(o => o.Uri).Returns(new Uri(@"c:\project\model.edmx"));

            var edmxErrorInfo =
                new ErrorInfo(ErrorInfo.Severity.ERROR, "test", mockEFObject.Object, 42, ErrorClass.Runtime_CSDL);

            Assert.Equal(76, edmxErrorInfo.GetLineNumber());
            Assert.Equal(12, edmxErrorInfo.GetColumnNumber());
            Assert.True(edmxErrorInfo.IsError());
            Assert.False(edmxErrorInfo.IsWarning());
            Assert.False(edmxErrorInfo.IsInfo());
            Assert.Equal(string.Format(Resources.Error_Message_With_Error_Code_Prefix, 42, "test"), edmxErrorInfo.Message);
            Assert.Same(mockEFObject.Object, edmxErrorInfo.Item);
            Assert.Equal(@"c:\project\model.edmx", edmxErrorInfo.ItemPath);
            Assert.Equal(42, edmxErrorInfo.ErrorCode);
            Assert.Equal(ErrorClass.Runtime_CSDL, edmxErrorInfo.ErrorClass);
        }
예제 #5
0
        /// <summary>
        ///     This method returns true if the passed-in error code is one that requires the document to be opened in the XML editor,
        ///     with no designer.
        /// </summary>
        internal static bool IsOpenInEditorError(ErrorInfo errorInfo, EFArtifact artifact)
        {
            if ((errorInfo.ErrorClass & ErrorClass.Runtime_All) == 0)
            {
                return(false);
            }

            var o = artifact.FindEFObjectForLineAndColumn(errorInfo.GetLineNumber(), errorInfo.GetColumnNumber());

            if (errorInfo.ErrorCode == (int)MappingErrorCode.XmlSchemaValidationError &&
                o is ModificationFunctionMapping)
            {
                // we don't trigger safe-mode for XSD errors on ModificationFunctionMapping, since these can be fixed in the designer
                return(false);
            }

            if (errorInfo.ErrorCode == (int)ErrorCode.XmlError &&
                o is ReferentialConstraintRole)
            {
                // we don't trigger safe-mode for XSD errors on referential constraint roles.  This is so we can leave the RC
                // and the Role, even if it has no properties.
                return(false);
            }

            if (errorInfo.ErrorCode == (int)MappingErrorCode.ConditionError &&
                o is Condition)
            {
                // don't trigger safe-mode for errors based around condition validation
                return(false);
            }

            if (errorInfo.ErrorCode == (int)ErrorCode.InvalidPropertyInRelationshipConstraint &&
                o is ReferentialConstraint)
            {
                // don't trigger safe-mode for error about Principal not being exactly identical to the EntityType key,
                // since we can run into this problem just by adding new key Property to the EntityType that is Principal Role for some Referential Constraint
                return(false);
            }

            if (errorInfo.ErrorCode == ErrorCodes.ESCHER_VALIDATOR_UNDEFINED_COMPLEX_PROPERTY_TYPE ||
                (errorInfo.ErrorCode == (int)ErrorCode.NotInNamespace && o is ComplexConceptualProperty))
            {
                // don't trigger safe-mode for underfined/deleted complex property types, the user should be able to fix the problem in the designer.
                return(false);
            }

            if (errorInfo.ErrorCode == (int)ErrorCode.XmlError)
            {
                var navigationProperty = o as NavigationProperty;
                if (navigationProperty != null)
                {
                    // we allow the user to have navigation properties not bound to any association via an AssociationEnd if the Name property is defined as it's still required.
                    return
                        (string.IsNullOrEmpty(navigationProperty.LocalName.Value) /* invalid name */ ||
                         navigationProperty.Relationship.Status != BindingStatus.Undefined ||
                         navigationProperty.ToRole.Status != BindingStatus.Undefined ||
                         navigationProperty.FromRole.Status != BindingStatus.Undefined);
                }
            }

            return
                (UnrecoverableRuntimeErrors.SchemaObjectModelErrorCodes.Any(c => c == (ErrorCode)errorInfo.ErrorCode) ||
                 UnrecoverableRuntimeErrors.StorageMappingErrorCodes.Any(c => c == (MappingErrorCode)errorInfo.ErrorCode));
        }
        /// <summary>
        ///     This method returns true if the passed-in error code is one that requires the document to be opened in the XML editor,
        ///     with no designer.
        /// </summary>
        internal static bool IsOpenInEditorError(ErrorInfo errorInfo, EFArtifact artifact)
        {
            if ((errorInfo.ErrorClass & ErrorClass.Runtime_All) == 0)
            {
                return false;
            }

            var o = artifact.FindEFObjectForLineAndColumn(errorInfo.GetLineNumber(), errorInfo.GetColumnNumber());

            if (errorInfo.ErrorCode == (int)MappingErrorCode.XmlSchemaValidationError
                && o is ModificationFunctionMapping)
            {
                // we don't trigger safe-mode for XSD errors on ModificationFunctionMapping, since these can be fixed in the designer
                return false;
            }

            if (errorInfo.ErrorCode == (int)ErrorCode.XmlError
                && o is ReferentialConstraintRole)
            {
                // we don't trigger safe-mode for XSD errors on referential constraint roles.  This is so we can leave the RC 
                // and the Role, even if it has no properties.
                return false;
            }

            if (errorInfo.ErrorCode == (int)MappingErrorCode.ConditionError
                && o is Condition)
            {
                // don't trigger safe-mode for errors based around condition validation
                return false;
            }

            if (errorInfo.ErrorCode == (int)ErrorCode.InvalidPropertyInRelationshipConstraint
                && o is ReferentialConstraint)
            {
                // don't trigger safe-mode for error about Principal not being exactly identical to the EntityType key,
                // since we can run into this problem just by adding new key Property to the EntityType that is Principal Role for some Referential Constraint
                return false;
            }

            if (errorInfo.ErrorCode == ErrorCodes.ESCHER_VALIDATOR_UNDEFINED_COMPLEX_PROPERTY_TYPE
                || (errorInfo.ErrorCode == (int)ErrorCode.NotInNamespace && o is ComplexConceptualProperty))
            {
                // don't trigger safe-mode for underfined/deleted complex property types, the user should be able to fix the problem in the designer.
                return false;
            }

            if (errorInfo.ErrorCode == (int)ErrorCode.XmlError)
            {
                var navigationProperty = o as NavigationProperty;
                if (navigationProperty != null)
                {
                    // we allow the user to have navigation properties not bound to any association via an AssociationEnd if the Name property is defined as it's still required.
                    return
                        string.IsNullOrEmpty(navigationProperty.LocalName.Value) /* invalid name */||
                        navigationProperty.Relationship.Status != BindingStatus.Undefined ||
                        navigationProperty.ToRole.Status != BindingStatus.Undefined ||
                        navigationProperty.FromRole.Status != BindingStatus.Undefined;
                }
            }

            return
                UnrecoverableRuntimeErrors.SchemaObjectModelErrorCodes.Any(c => c == (ErrorCode)errorInfo.ErrorCode) ||
                UnrecoverableRuntimeErrors.StorageMappingErrorCodes.Any(c => c == (MappingErrorCode)errorInfo.ErrorCode);
        }