Exemple #1
0
		internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal<string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError)
		{
			string name;
			IEdmSchemaElement edmSchemaElement = item as IEdmSchemaElement;
			if (edmSchemaElement != null)
			{
				name = edmSchemaElement.FullName();
			}
			else
			{
				name = item.Name;
			}
			string str = name;
			if (memberNameList.Add(str))
			{
				return true;
			}
			else
			{
				if (!suppressError)
				{
					context.AddError(item.Location(), errorCode, errorString);
				}
				return false;
			}
		}
Exemple #2
0
        private void ValidateBindingWithExpectedErrors(string bindingText, EdmErrorCode errorCode, params string[] messages)
        {
            const string template  = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""Test"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityContainer Name=""Container"">
        <EntitySet Name=""EntitySet"" EntityType=""Test.EntityType"">
          {0}
        </EntitySet>
      </EntityContainer>
      <EntityType Name=""EntityType"">
        <Key>
          <PropertyRef Name=""ID""/>
        </Key>
        <Property Name=""ID"" Nullable=""false"" Type=""Edm.Int32""/>
        <NavigationProperty Name=""Navigation"" Type=""Collection(Test.EntityType)"" />
      </EntityType>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            string       modelText = string.Format(template, bindingText);

            IEdmModel model;
            IEnumerable <EdmError> errors;

            CsdlReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out errors).Should().BeTrue();

            model.Validate(out errors).Should().BeFalse();
            errors.Should().HaveCount(messages.Length);
            foreach (var message in messages)
            {
                errors.Should().Contain(e => e.ErrorCode == errorCode && e.ErrorMessage == message);
            }
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the EdmError class.
 /// </summary>
 /// <param name="errorLocation">The location where the error occurred.</param>
 /// <param name="errorCode">An integer code representing the error.</param>
 /// <param name="errorMessage">A human readable message describing the error.</param>
 /// <param name="severity">An enum value describing the error severity.</param>
 public EdmError(EdmLocation errorLocation, EdmErrorCode errorCode, string errorMessage, Severity severity)
 {
     this.ErrorLocation = errorLocation;
     this.ErrorCode     = errorCode;
     this.ErrorMessage  = errorMessage;
     this.Severity      = severity;
 }
        private static void ValidateError(IEdmModel model, EdmErrorCode expectedErrorCode, string expectedError)
        {
            var context = ExecuteDuplicateOperationValidator(model);
            var errors  = context.Errors.ToList();

            Assert.Single(errors);
            Assert.Equal(expectedErrorCode, errors[0].ErrorCode);
            Assert.Equal(expectedError, errors[0].ErrorMessage);
        }
        private static void ValidateError(IEdmModel model, EdmErrorCode expectedErrorCode, string expectedError)
        {
            var context = ExecuteDuplicateOperationValidator(model);
            var errors  = context.Errors.ToList();

            errors.Should().HaveCount(1);
            errors[0].ErrorCode.Should().Be(expectedErrorCode);
            errors[0].ErrorMessage.Should().Be(expectedError);
        }
Exemple #6
0
            public void Add(int?lineNumber, int?linePostion, EdmErrorCode edmErrorCode)
            {
                EdmLibTestCsdlLocation errorLocation = null;

                if (lineNumber != null && linePostion != null)
                {
                    errorLocation = new EdmLibTestCsdlLocation(lineNumber, linePostion);
                }
                base.Add(new EdmError(errorLocation, edmErrorCode, string.Empty));
            }
        private static void ValidateError(IEdmModel model, IEdmOperation operation, EdmErrorCode expectedErrorCode, string expectedError)
        {
            IEnumerable <EdmError> errorsFound        = null;
            IEdmOperationParameter operationParameter = null;
            IEnumerable <IEdmNavigationProperty> navigationProperties = null;
            IEdmEntityType entityType = null;

            operation.TryGetRelativeEntitySetPath(model, out operationParameter, out navigationProperties, out entityType, out errorsFound);
            errorsFound.Should().HaveCount(1);
            var errorsFoundList = errorsFound.ToList();

            errorsFoundList[0].ErrorCode.Should().Be(expectedErrorCode);
            errorsFoundList[0].ErrorMessage.Should().Be(expectedError);
        }
        internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal<string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError)
        {
            IEdmSchemaElement schemaElement = item as IEdmSchemaElement;
            string name = (schemaElement != null) ? schemaElement.FullName() : item.Name;
            if (!memberNameList.Add(name))
            {
                if (!suppressError)
                {
                    context.AddError(item.Location(), errorCode, errorString);
                }

                return false;
            }

            return true;
        }
Exemple #9
0
        private void ValidateBindingWithExpectedErrors(string bindingText, EdmErrorCode errorCode, params string[] messages)
        {
            string modelText = string.Format(navPropBindingtemplate, bindingText);

            IEdmModel model;
            IEnumerable <EdmError> errors;

            CsdlReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out errors).Should().BeTrue();

            model.Validate(out errors).Should().BeFalse();
            errors.Should().HaveCount(messages.Length);
            foreach (var message in messages)
            {
                errors.Should().Contain(e => e.ErrorCode == errorCode && e.ErrorMessage == message);
            }
        }
Exemple #10
0
        private void ValidateBindingWithExpectedErrors(string bindingText, EdmErrorCode errorCode, params string[] messages)
        {
            string modelText = string.Format(navPropBindingtemplate, bindingText);

            IEdmModel model;
            IEnumerable <EdmError> errors;

            Assert.True(CsdlReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out errors));

            Assert.False(model.Validate(out errors));
            Assert.Equal(messages.Length, errors.Count());
            foreach (var message in messages)
            {
                Assert.Contains(errors, e => e.ErrorCode == errorCode && e.ErrorMessage == message);
            }
        }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the EdmError class.
 /// </summary>
 /// <param name="errorLocation">The location where the error occurred.</param>
 /// <param name="errorCode">An integer code representing the error.</param>
 /// <param name="errorMessage">A human readable message describing the error.</param>
 public EdmError(EdmLocation errorLocation, EdmErrorCode errorCode, string errorMessage)
 {
     this.ErrorLocation = errorLocation;
     this.ErrorCode = errorCode;
     this.ErrorMessage = errorMessage;
 }
Exemple #12
0
 public void Add(EdmErrorCode edmErrorCode, string resourceKey, params string[] arguments)
 {
     base.Add(new ExpectedEdmError(edmErrorCode, resourceKey, arguments));
 }
Exemple #13
0
 protected void ReportError(CsdlLocation errorLocation, EdmErrorCode errorCode, string errorMessage)
 {
     this.errors.Add(new EdmError(errorLocation, errorCode, errorMessage));
     this.HasErrors = true;
 }
 /// <summary>
 /// Reports a certain parsing error.
 /// </summary>
 /// <param name="errorCode">The Edm Error Code.</param>
 /// <param name="errorMessage">The Error message.</param>
 public void ReportError(EdmErrorCode errorCode, string errorMessage)
 {
     Errors.Add(new EdmError(Location(), errorCode, errorMessage));
 }
Exemple #15
0
 /// <summary>
 /// Initializes a new instance of the EdmError class.
 /// </summary>
 /// <param name="errorLocation">The location where the error occurred.</param>
 /// <param name="errorCode">An integer code representing the error.</param>
 /// <param name="errorMessage">A human readable message describing the error.</param>
 public EdmError(EdmLocation errorLocation, EdmErrorCode errorCode, string errorMessage)
 {
     this.ErrorLocation = errorLocation;
     this.ErrorCode     = errorCode;
     this.ErrorMessage  = errorMessage;
 }
Exemple #16
0
 // TODO: add more interesting fields and potentially merge with the one used in semantic validation
 public ExpectedEdmError(EdmErrorCode errorCode, string messageResourceKey, params string[] messageArguments)
 {
     this.ErrorCode          = errorCode;
     this.MessageResourceKey = messageResourceKey;
     this.MessageArguments   = messageArguments.ToList();
 }
Exemple #17
0
 private void RaiseError(EdmErrorCode errorCode, string errorMessage)
 {
     this.errors.Add(new EdmError(this.Location(), errorCode, errorMessage));
 }
Exemple #18
0
 private void RaiseError(EdmErrorCode errorCode, string errorMessage)
 {
     this.errors.Add(new EdmError(this.Location(), errorCode, errorMessage));
 }
 private static void ValidateError(IEdmModel model, EdmErrorCode expectedErrorCode, string expectedError)
 {
     var context = ExecuteDuplicateOperationValidator(model);
     var errors = context.Errors.ToList();
     errors.Should().HaveCount(1);
     errors[0].ErrorCode.Should().Be(expectedErrorCode);
     errors[0].ErrorMessage.Should().Be(expectedError);
 }
        internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal <string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError)
        {
            string            name;
            IEdmSchemaElement edmSchemaElement = item as IEdmSchemaElement;

            if (edmSchemaElement != null)
            {
                name = edmSchemaElement.FullName();
            }
            else
            {
                name = item.Name;
            }
            string str = name;

            if (memberNameList.Add(str))
            {
                return(true);
            }
            else
            {
                if (!suppressError)
                {
                    context.AddError(item.Location(), errorCode, errorString);
                }
                return(false);
            }
        }
 private void ParseNavigationExpectedErrors(string navigationText, EdmErrorCode? errorCode = null, string message = null)
 {
     if (errorCode != null)
     {
         ParseNavigationExpectedErrors(navigationText, new[] { errorCode.Value }, new[] { message });   
     }
     else
     {
         ParseNavigationExpectedErrors(navigationText, new EdmErrorCode[0], new string[0]);   
     }
 }
        private void ParseNavigationExpectedErrors(string navigationText, EdmErrorCode[] errorCodes, string[] messages)
        {
            errorCodes.Length.Should().Be(messages.Length);
            const string template = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""Test"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityType Name=""EntityType"">
        <Key>
          <PropertyRef Name=""ID"" />
        </Key>
        <Property Name=""ID"" Type=""Edm.Int32"" Nullable=""false"" />
        {0}
      </EntityType>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            string modelText = string.Format(template, navigationText);

            IEdmModel model;
            IEnumerable<EdmError> errors;
           
            bool result = EdmxReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out errors);
            if (errorCodes.Length > 0)
            {
                result.Should().BeFalse();

                errors.Should().HaveCount(messages.Length);
                for (int i = 0; i < messages.Length; i++)
                {
                    errors.Should().Contain(e => e.ErrorCode == errorCodes[i] && e.ErrorMessage == messages[i]);
                }
            }
            else
            {
                result.Should().BeTrue();
                errors.Should().BeEmpty();
            }
        }
        private void ParseReferentialConstraintWithExpectedErrors(string referentialConstraintText, EdmErrorCode errorCode, params string[] messages)
        {
            const string template = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""Test"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityType Name=""EntityType"">
        <Key>
          <PropertyRef Name=""ID1"" />
          <PropertyRef Name=""ID2"" />
        </Key>
        <Property Name=""ID1"" Type=""Edm.Int32"" Nullable=""false"" />
        <Property Name=""ID2"" Type=""Edm.Int32"" Nullable=""false"" />
        <Property Name=""ForeignKeyId1"" Type=""Edm.Int32"" />
        <Property Name=""ForeignKeyId2"" Type=""Edm.Int32"" />
        <NavigationProperty Name=""Navigation"" Type=""Test.EntityType"" Nullable=""true"">
          {0}
        </NavigationProperty>
      </EntityType>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            string modelText = string.Format(template, referentialConstraintText);

            IEdmModel model;
            IEnumerable<EdmError> errors;
            EdmxReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out errors).Should().BeFalse();
            
            errors.Should().HaveCount(messages.Length);
            foreach (var message in messages)
            {
                errors.Should().Contain(e => e.ErrorCode == errorCode && e.ErrorMessage == message);
            }
        }
        private void ParseBindingWithExpectedErrors(string bindingText, EdmErrorCode errorCode, params string[] messages)
        {
            const string template = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""Test"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityContainer Name=""Container"">
        <EntitySet Name=""EntitySet"" EntityType=""Test.EntityType"">
          {0}
        </EntitySet>
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            string modelText = string.Format(template, bindingText);

            IEdmModel model;
            IEnumerable<EdmError> errors;
            EdmxReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out errors).Should().BeFalse();
            
            errors.Should().HaveCount(messages.Length);
            foreach (var message in messages)
            {
                errors.Should().Contain(e => e.ErrorCode == errorCode && e.ErrorMessage == message);
            }
        }
Exemple #25
0
 /// <summary>
 /// Initializes a new instance of the EdmError class.
 /// </summary>
 /// <param name="errorLocation">The location where the error occurred.</param>
 /// <param name="errorCode">An integer code representing the error.</param>
 /// <param name="errorMessage">A human readable message describing the error.</param>
 public EdmError(EdmLocation errorLocation, EdmErrorCode errorCode, string errorMessage)
     : this(errorLocation, errorCode, errorMessage, Severity.Undefined)
 {
 }
        private static void ValidateErrorInList(IEdmModel model, IEdmOperation operation, EdmErrorCode expectedErrorCode, string expectedError)
        {
            IEnumerable <EdmError> errorsFound        = null;
            IEdmOperationParameter operationParameter = null;
            IEnumerable <IEdmNavigationProperty> navigationProperties = null;
            IEdmEntityType entityType = null;

            operation.TryGetRelativeEntitySetPath(model, out operationParameter, out navigationProperties, out entityType, out errorsFound);
            var error = errorsFound.SingleOrDefault(e => e.ErrorCode == expectedErrorCode);

            error.Should().NotBeNull();
            error.ErrorMessage.Should().Be(expectedError);
        }
 internal static bool SignificantToSerialization(EdmError error)
 {
     if (!ValidationHelper.IsInterfaceCritical(error))
     {
         EdmErrorCode errorCode = error.ErrorCode;
         if (errorCode > EdmErrorCode.RowTypeMustNotHaveBaseType)
         {
             if (errorCode > EdmErrorCode.EnumMemberTypeMustMatchEnumUnderlyingType)
             {
                 if (errorCode != EdmErrorCode.ReferencedTypeMustHaveValidName)
                 {
                     if (errorCode == EdmErrorCode.InvalidFunctionImportParameterMode || errorCode == EdmErrorCode.TypeMustNotHaveKindOfNone || errorCode == EdmErrorCode.PrimitiveTypeMustNotHaveKindOfNone || errorCode == EdmErrorCode.PropertyMustNotHaveKindOfNone || errorCode == EdmErrorCode.TermMustNotHaveKindOfNone || errorCode == EdmErrorCode.SchemaElementMustNotHaveKindOfNone || errorCode == EdmErrorCode.EntityContainerElementMustNotHaveKindOfNone || errorCode == EdmErrorCode.BinaryValueCannotHaveEmptyValue)
                     {
                         return(true);
                     }
                     if (errorCode != EdmErrorCode.EnumMustHaveIntegerUnderlyingType)
                     {
                         return(false);
                     }
                 }
             }
             else
             {
                 if (errorCode == EdmErrorCode.OnlyInputParametersAllowedInFunctions || errorCode == EdmErrorCode.FunctionImportParameterIncorrectType)
                 {
                     return(true);
                 }
                 else if (errorCode == EdmErrorCode.ComplexTypeMustHaveProperties)
                 {
                     return(false);
                 }
                 if (errorCode == EdmErrorCode.EnumMemberTypeMustMatchEnumUnderlyingType)
                 {
                     return(true);
                 }
                 return(false);
             }
         }
         else
         {
             if (errorCode > EdmErrorCode.NameTooLong)
             {
                 if (errorCode != EdmErrorCode.FunctionImportEntitySetExpressionIsInvalid)
                 {
                     if (errorCode == EdmErrorCode.SystemNamespaceEncountered || errorCode == EdmErrorCode.InvalidNamespaceName)
                     {
                         return(true);
                     }
                     else if ((int)errorCode == 162)
                     {
                         return(false);
                     }
                     if (errorCode == EdmErrorCode.RowTypeMustNotHaveBaseType)
                     {
                         return(true);
                     }
                     return(false);
                 }
             }
             else
             {
                 if (errorCode == EdmErrorCode.InvalidName || errorCode == EdmErrorCode.NameTooLong)
                 {
                     return(true);
                 }
                 return(false);
             }
         }
         return(true);
     }
     else
     {
         return(true);
     }
 }
Exemple #28
0
 /// <summary>
 /// Register an error with the validation context.
 /// </summary>
 /// <param name="location">Location of the error.</param>
 /// <param name="errorCode">Value representing the error.</param>
 /// <param name="errorMessage">Message text discribing the error.</param>
 public void AddError(EdmLocation location, EdmErrorCode errorCode, string errorMessage)
 {
     this.AddError(new EdmError(location, errorCode, errorMessage));
 }
Exemple #29
0
        private void ValidateReferentialConstraintWithExpectedErrors(string referentialConstraintText, EdmErrorCode errorCode, params string[] messages)
        {
            const string template  = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
  <edmx:DataServices>
    <Schema Namespace=""Test"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
      <EntityType Name=""EntityType"">
        <Key>
          <PropertyRef Name=""ID1"" />
          <PropertyRef Name=""ID2"" />
        </Key>
        <Property Name=""ID1"" Type=""Edm.Int32"" Nullable=""false"" />
        <Property Name=""ID2"" Type=""Edm.Int32"" Nullable=""false"" />
        <Property Name=""ForeignKeyId1"" Type=""Edm.Int32"" />
        <Property Name=""ForeignKeyId2"" Type=""Edm.Int32"" />
        <NavigationProperty Name=""Navigation"" Type=""Test.EntityType"" Nullable=""true"">
          {0}
        </NavigationProperty>
      </EntityType>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>";
            string       modelText = string.Format(template, referentialConstraintText);

            IEdmModel model;
            IEnumerable <EdmError> errors;

            Assert.True(CsdlReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out errors));

            Assert.False(model.Validate(out errors));
            Assert.Equal(messages.Length, errors.Count());
            foreach (var message in messages)
            {
                Assert.Contains(errors, e => e.ErrorCode == errorCode && e.ErrorMessage == message);
            }
        }
Exemple #30
0
            public void Add(string typeName, EdmErrorCode edmErrorCode)
            {
                var errorLocation = new EdmLibTestObjectLocation(typeName);

                base.Add(new EdmError(errorLocation, edmErrorCode, string.Empty));
            }
        private static void ValidateError(IEdmModel model, IEdmOperation operation, EdmErrorCode expectedErrorCode, string expectedError)
        {
            IEnumerable<EdmError> errorsFound = null;
            IEdmOperationParameter operationParameter = null;
            IEnumerable<IEdmNavigationProperty> navigationProperties = null;
            IEdmEntityType entityType = null;

            operation.TryGetRelativeEntitySetPath(model, out operationParameter, out navigationProperties, out entityType, out errorsFound);
            errorsFound.Should().HaveCount(1);
            var errorsFoundList = errorsFound.ToList();
            errorsFoundList[0].ErrorCode.Should().Be(expectedErrorCode);
            errorsFoundList[0].ErrorMessage.Should().Be(expectedError);
        }
 // TODO: add more interesting fields and potentially merge with the one used in semantic validation
 public ExpectedEdmError(EdmErrorCode errorCode, string messageResourceKey, params string[] messageArguments)
 {
     this.ErrorCode = errorCode;
     this.MessageResourceKey = messageResourceKey;
     this.MessageArguments = messageArguments.ToList();
 }
        private static void ValidateErrorInList(IEdmModel model, IEdmOperation operation, EdmErrorCode expectedErrorCode, string expectedError)
        {
            IEnumerable<EdmError> errorsFound = null;
            IEdmOperationParameter operationParameter = null;
            IEnumerable<IEdmNavigationProperty> navigationProperties = null;
            IEdmEntityType entityType = null;

            operation.TryGetRelativeEntitySetPath(model, out operationParameter, out navigationProperties, out entityType, out errorsFound);
            var error = errorsFound.SingleOrDefault(e => e.ErrorCode == expectedErrorCode);
            error.Should().NotBeNull();
            error.ErrorMessage.Should().Be(expectedError);
        }
Exemple #34
0
 private void ParseReferentialConstraintWithExpectedErrors(string referentialConstraintText, EdmErrorCode errorCode, params string[] messages)
 {
     ParseReferentialConstraint(referentialConstraintText, errorCode, messages);
 }
 /// <summary>
 /// Register an error with the validation context.
 /// </summary>
 /// <param name="location">Location of the error.</param>
 /// <param name="errorCode">Value representing the error.</param>
 /// <param name="errorMessage">Message text discribing the error.</param>
 public void AddError(EdmLocation location, EdmErrorCode errorCode, string errorMessage)
 {
     this.AddError(new EdmError(location, errorCode, errorMessage));
 }
Exemple #36
0
        internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal <string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError)
        {
            IEdmSchemaElement schemaElement = item as IEdmSchemaElement;
            string            name          = (schemaElement != null) ? schemaElement.FullName() : item.Name;

            if (!memberNameList.Add(name))
            {
                if (!suppressError)
                {
                    context.AddError(item.Location(), errorCode, errorString);
                }

                return(false);
            }

            return(true);
        }
Exemple #37
0
        public void EdmErrorConstructorWithUndefinedSeverityAndNoLocationShouldOutputCorrectToString(EdmLocation errorLocation, EdmErrorCode errorCode, string errorMessage, Severity severity)
        {
            string   expectedString = errorCode.ToString() + " : " + errorMessage;
            EdmError edmError       = new EdmError(errorLocation, errorCode, errorMessage, severity);

            Assert.Equal(errorCode, edmError.ErrorCode);
            Assert.Equal(errorMessage, edmError.ErrorMessage);
            Assert.Equal(severity, edmError.Severity);
            Assert.Equal(expectedString, edmError.ToString());
        }