Skip to content

Commit

Permalink
issue #21: Resentence RedingindNotSupported error message to include …
Browse files Browse the repository at this point in the history
…more information (#28)
  • Loading branch information
xuzhg authored Jun 9, 2022
1 parent a6b09a5 commit 4bf8455
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public virtual NavigationPropertyBindingConfiguration AddBinding(NavigationPrope
{
if (navigationPropertyBinding.TargetNavigationSource != targetNavigationSource)
{
throw Error.NotSupported(SRResources.RebindingNotSupported);
throw Error.NotSupported(SRResources.RebindingNotSupported, path, Name, targetNavigationSource.Name, navigationPropertyBinding.TargetNavigationSource.Name);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4377,7 +4377,7 @@
</member>
<member name="P:Microsoft.OData.ModelBuilder.SRResources.RebindingNotSupported">
<summary>
Looks up a localized string similar to Rebinding is not supported..
Looks up a localized string similar to Cannot bind the navigation property&apos;{0}&apos; from navigation source &apos;{1}&apos; to navigation source &apos;{2}&apos; because it has already been binded to navigation source &apos;{3}&apos;..
</summary>
</member>
<member name="P:Microsoft.OData.ModelBuilder.SRResources.ReferentialConstraintAlreadyConfigured">
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OData.ModelBuilder/SRResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Microsoft.OData.ModelBuilder/SRResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<value>Invalid bindingParameter type '{0}'. A bindingParameter must be either an EntityType or a Collection of EntityTypes.</value>
</data>
<data name="RebindingNotSupported" xml:space="preserve">
<value>Rebinding is not supported.</value>
<value>Cannot bind the navigation property'{0}' from navigation source '{1}' to navigation source '{2}' because it has already been binded to navigation source '{3}'.</value>
</data>
<data name="TypeCannotBeEntityWasComplex" xml:space="preserve">
<value>The type '{0}' cannot be configured as an EntityType. It was previously configured as a ComplexType.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ public void CreateModelWithTwoEntitySetsAndABinding()
Assert.Equal("Orders", customerOrders.Target.Name);
}

[Fact]
public void RebindSameNavigationPropertyOnSameNavigationSourceToDifferentNavigationSource_ThrowsNotSupportedException()
{
// Arrange
ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock();

var customer = builder.AddEntityType(typeof(Customer));
var order = builder.AddEntityType(typeof(Order));
var customers = builder.AddEntitySet("Customers", customer);
var navProperty = customer.AddNavigationProperty(typeof(Customer).GetProperty("Orders"), EdmMultiplicity.Many);

var orders1 = builder.AddEntitySet("Orders1", order);
var orders2 = builder.AddEntitySet("Orders2", order);
customers.AddBinding(navProperty, orders1);

// Act & Assert
ExceptionAssert.Throws<NotSupportedException>(() => customers.AddBinding(navProperty, orders2),
"Cannot bind the navigation property'Orders' from navigation source 'Customers' to navigation source 'Orders2' because it has already been binded to navigation source 'Orders1'.");
}

[Fact]
public void CanAddBinding_For_NavigationProperty()
{
Expand Down

0 comments on commit 4bf8455

Please sign in to comment.