move the error message to resource
This commit is contained in:
parent
095a1fc130
commit
95b6994c02
|
@ -10,6 +10,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using Microsoft.OData.Edm;
|
||||
using Microsoft.OpenApi.OData.Common;
|
||||
using Microsoft.OpenApi.OData.Properties;
|
||||
|
||||
namespace Microsoft.OpenApi.OData.Edm
|
||||
{
|
||||
|
@ -56,7 +57,7 @@ namespace Microsoft.OpenApi.OData.Edm
|
|||
{
|
||||
if (!Segments.Any())
|
||||
{
|
||||
throw Error.InvalidOperation("Pop a segment is invalid. The segments in the path is empty.");
|
||||
throw Error.InvalidOperation(SRResource.ODataPathPopInvalid);
|
||||
}
|
||||
|
||||
Segments.RemoveAt(Segments.Count - 1);
|
||||
|
|
|
@ -96,6 +96,15 @@ namespace Microsoft.OpenApi.OData.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Pop a segment is invalid. The segment list in the path is empty..
|
||||
/// </summary>
|
||||
internal static string ODataPathPopInvalid {
|
||||
get {
|
||||
return ResourceManager.GetString("ODataPathPopInvalid", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to An error occurred while processing the OData message..
|
||||
/// </summary>
|
||||
|
|
|
@ -129,6 +129,9 @@
|
|||
<data name="NotSupportedEdmTypeKind" xml:space="preserve">
|
||||
<value>Not supported {0} Edm type kind.</value>
|
||||
</data>
|
||||
<data name="ODataPathPopInvalid" xml:space="preserve">
|
||||
<value>Pop a segment is invalid. The segment list in the path is empty.</value>
|
||||
</data>
|
||||
<data name="OpenApiExceptionGeneralError" xml:space="preserve">
|
||||
<value>An error occurred while processing the OData message.</value>
|
||||
</data>
|
||||
|
|
|
@ -3,38 +3,54 @@
|
|||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using Microsoft.OData.Edm;
|
||||
using Microsoft.OpenApi.OData.Properties;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.OpenApi.OData.Edm.Tests
|
||||
{
|
||||
public class ODataPathTests
|
||||
{
|
||||
private IEdmEntityType _singleKeyEntityType;
|
||||
private IEdmEntitySet _singleKeyEntitySet;
|
||||
private IEdmEntityType _simpleKeyEntityType;
|
||||
private IEdmEntitySet _simpleKeyEntitySet;
|
||||
|
||||
private IEdmEntityType _multipleKeyEntityType;
|
||||
private IEdmEntitySet _multipleKeyEntitySet;
|
||||
private IEdmEntityType _compositeKeyEntityType;
|
||||
private IEdmEntitySet _compositeKeyEntitySet;
|
||||
|
||||
public ODataPathTests()
|
||||
{
|
||||
// Single key entity type
|
||||
EdmEntityType entityType = new EdmEntityType("NS", "Order");
|
||||
entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
|
||||
_singleKeyEntityType = entityType;
|
||||
_simpleKeyEntityType = entityType;
|
||||
|
||||
EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
|
||||
EdmEntitySet entitySet = new EdmEntitySet(container, "Orders", entityType);
|
||||
_singleKeyEntitySet = entitySet;
|
||||
_simpleKeyEntitySet = entitySet;
|
||||
|
||||
// Multiple keys entity type
|
||||
entityType = new EdmEntityType("NS", "Customer");
|
||||
entityType.AddKeys(entityType.AddStructuralProperty("FirstName", EdmPrimitiveTypeKind.String),
|
||||
entityType.AddStructuralProperty("LastName", EdmPrimitiveTypeKind.String));
|
||||
_multipleKeyEntityType = entityType;
|
||||
_compositeKeyEntityType = entityType;
|
||||
|
||||
entitySet = new EdmEntitySet(container, "Customers", entityType);
|
||||
_multipleKeyEntitySet = entitySet;
|
||||
_compositeKeyEntitySet = entitySet;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PopThrowsForEmptyPath()
|
||||
{
|
||||
// Arrange
|
||||
ODataPath path = new ODataPath();
|
||||
|
||||
// Act
|
||||
Action text = () => path.Pop();
|
||||
|
||||
// Assert
|
||||
var exception = Assert.Throws<InvalidOperationException>(text);
|
||||
Assert.Equal(SRResource.ODataPathPopInvalid, exception.Message);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
@ -43,8 +59,8 @@ namespace Microsoft.OpenApi.OData.Edm.Tests
|
|||
public void GetPathItemNameReturnsCorrectStringWithSingleKeySegment(bool keyAsSegment, string expected)
|
||||
{
|
||||
// Arrange
|
||||
ODataNavigationSourceSegment nsSegment = new ODataNavigationSourceSegment(_singleKeyEntitySet);
|
||||
ODataKeySegment keySegment = new ODataKeySegment(_singleKeyEntityType);
|
||||
ODataNavigationSourceSegment nsSegment = new ODataNavigationSourceSegment(_simpleKeyEntitySet);
|
||||
ODataKeySegment keySegment = new ODataKeySegment(_simpleKeyEntityType);
|
||||
ODataPath path = new ODataPath(nsSegment, keySegment);
|
||||
|
||||
// Act
|
||||
|
@ -60,8 +76,8 @@ namespace Microsoft.OpenApi.OData.Edm.Tests
|
|||
public void GetPathItemNameReturnsCorrectStringWithMultipleKeySegment(bool keyAsSegment)
|
||||
{
|
||||
// Arrange
|
||||
ODataNavigationSourceSegment nsSegment = new ODataNavigationSourceSegment(_multipleKeyEntitySet);
|
||||
ODataKeySegment keySegment = new ODataKeySegment(_multipleKeyEntityType);
|
||||
ODataNavigationSourceSegment nsSegment = new ODataNavigationSourceSegment(_compositeKeyEntitySet);
|
||||
ODataKeySegment keySegment = new ODataKeySegment(_compositeKeyEntityType);
|
||||
ODataPath path = new ODataPath(nsSegment, keySegment);
|
||||
|
||||
// Act
|
||||
|
|
Loading…
Reference in a new issue