public void Create_uses_given_message_inner_exception_and_error_context_and_sets_up_serialization()
        {
            var innerException = new Exception("Ho Ho Ho");
            var exception      = EntitySqlException.Create(
                new ErrorContext
            {
                CommandText      = "select redHook\n from\n breweries",
                ErrorContextInfo = "Hubcap emotional barometer is peaking",
                InputPosition    = 22,
                UseContextInfoAsResourceIdentifier = false
            },
                "Why not use LINQ like everyone else?",
                innerException);

            Assert.Equal(
                "Why not use LINQ like everyone else? Near Hubcap emotional barometer is peaking, line 3, column 2.", exception.Message);
            Assert.Same(innerException, exception.InnerException);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("Hubcap emotional barometer is peaking, line 3, column 2", exception.ErrorContext);
            Assert.Equal("Why not use LINQ like everyone else?", exception.ErrorDescription);
            Assert.Equal(3, exception.Line);
            Assert.Equal(2, exception.Column);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal(
                "Why not use LINQ like everyone else? Near Hubcap emotional barometer is peaking, line 3, column 2.", exception.Message);
            Assert.Equal(innerException.Message, exception.InnerException.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("Hubcap emotional barometer is peaking, line 3, column 2", exception.ErrorContext);
            Assert.Equal("Why not use LINQ like everyone else?", exception.ErrorDescription);
            Assert.Equal(3, exception.Line);
            Assert.Equal(2, exception.Column);
        }
        public void Create_allows_all_state_to_be_set_and_sets_up_serialization()
        {
            var innerException = new Exception("Green Giant");
            var exception      = EntitySqlException.Create(
                commandText: "select brandy\n from\n spirits",
                errorDescription: "This isn't the vodka I ordered.",
                errorPosition: 17,
                errorContextInfo: "It's Polish plum brandy, dude!",
                loadErrorContextInfoFromResource: true,
                innerException: innerException);

            Assert.Equal("This isn't the vodka I ordered. Near line 2, column 4.", exception.Message);
            Assert.Same(innerException, exception.InnerException);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("line 2, column 4", exception.ErrorContext);
            Assert.Equal("This isn't the vodka I ordered.", exception.ErrorDescription);
            Assert.Equal(2, exception.Line);
            Assert.Equal(4, exception.Column);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal("This isn't the vodka I ordered. Near line 2, column 4.", exception.Message);
            Assert.Equal(innerException.Message, exception.InnerException.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("line 2, column 4", exception.ErrorContext);
            Assert.Equal("This isn't the vodka I ordered.", exception.ErrorDescription);
            Assert.Equal(2, exception.Line);
            Assert.Equal(4, exception.Column);
        }
 internal static EntitySqlException Create(
     System.Data.Entity.Core.Common.EntitySql.ErrorContext errCtx,
     string errorMessage,
     Exception innerException)
 {
     return(EntitySqlException.Create(errCtx.CommandText, errorMessage, errCtx.InputPosition, errCtx.ErrorContextInfo, errCtx.UseContextInfoAsResourceIdentifier, innerException));
 }
            public void CompleteDeserialization(object deserialized)
            {
                EntitySqlException entitySqlException = (EntitySqlException)deserialized;

                entitySqlException._state = this;
                entitySqlException.SubscribeToSerializeObjectState();
            }
        internal static string GetGenericErrorMessage(string commandText, int position)
        {
            int lineNumber   = 0;
            int columnNumber = 0;

            return(EntitySqlException.FormatErrorContext(commandText, position, "GenericSyntaxError", true, out lineNumber, out columnNumber));
        }
        internal static EntitySqlException Create(
            string commandText,
            string errorDescription,
            int errorPosition,
            string errorContextInfo,
            bool loadErrorContextInfoFromResource,
            Exception innerException)
        {
            int    lineNumber;
            int    columnNumber;
            string errorContext = EntitySqlException.FormatErrorContext(commandText, errorPosition, errorContextInfo, loadErrorContextInfoFromResource, out lineNumber, out columnNumber);

            return(new EntitySqlException(EntitySqlException.FormatQueryError(errorDescription, errorContext), errorDescription, errorContext, lineNumber, columnNumber, innerException));
        }
        public void Constructor_uses_given_message_and_sets_up_serialization()
        {
            var exception = new EntitySqlException("What is this eSQL of which you speak?");

            Assert.Equal("What is this eSQL of which you speak?", exception.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal("What is this eSQL of which you speak?", exception.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);
        }
        public void Parameterless_constructor_uses_general_message_and_sets_up_serialization()
        {
            var exception = new EntitySqlException();

            Assert.Equal(Strings.GeneralQueryError, exception.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal(Strings.GeneralQueryError, exception.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);
        }
        public void Constructor_uses_given_message_and_sets_up_serialization()
        {
            var exception = new EntitySqlException("What is this eSQL of which you speak?");

            Assert.Equal("What is this eSQL of which you speak?", exception.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal("What is this eSQL of which you speak?", exception.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);
        }
        public void Parameterless_constructor_uses_general_message_and_sets_up_serialization()
        {
            var exception = new EntitySqlException();

            Assert.Equal(Strings.GeneralQueryError, exception.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal(Strings.GeneralQueryError, exception.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);
        }
        public void Constructor_uses_given_message_and_inner_exception_and_sets_up_serialization()
        {
            var innerException = new Exception("I'm in here.");
            var exception      = new EntitySqlException("I knoweth not, good sir.", innerException);

            Assert.Equal("I knoweth not, good sir.", exception.Message);
            Assert.Same(innerException, exception.InnerException);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal("I knoweth not, good sir.", exception.Message);
            Assert.Equal(innerException.Message, exception.InnerException.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);
        }
        public void Constructor_uses_given_message_and_inner_exception_and_sets_up_serialization()
        {
            var innerException = new Exception("I'm in here.");
            var exception = new EntitySqlException("I knoweth not, good sir.", innerException);

            Assert.Equal("I knoweth not, good sir.", exception.Message);
            Assert.Same(innerException, exception.InnerException);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal("I knoweth not, good sir.", exception.Message);
            Assert.Equal(innerException.Message, exception.InnerException.Message);
            Assert.Equal(HResultInvalidQuery, GetHResult(exception));
            Assert.Equal("", exception.ErrorContext);
            Assert.Equal("", exception.ErrorDescription);
            Assert.Equal(0, exception.Line);
            Assert.Equal(0, exception.Column);
        }