Skip to content

Commit

Permalink
Make operation return 404 if bound single entity does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
chinadragon0515 committed Jul 5, 2016
1 parent d6ec25f commit 4344c5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Threading.Tasks;
using Microsoft.OData.Edm;
using Microsoft.Restier.Core;
using Microsoft.Restier.Core.Exceptions;
using Microsoft.Restier.Core.Operation;
using Microsoft.Restier.Publishers.OData.Formatter.Deserialization;
using Microsoft.Restier.Publishers.OData.Properties;
Expand Down Expand Up @@ -91,7 +92,13 @@ private static object PrepareBindingParameter(Type bindingType, IQueryable bindi
// This means binding to a single entity
if (enumerableType == null)
{
return bindingParameterValue.SingleOrDefault();
var entity = bindingParameterValue.SingleOrDefault();
if (entity == null)
{
throw new ResourceNotFoundException(Resources.ResourceNotFound);
}

return entity;
}

// This means function is bound to an entity set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public void EntityBoundFunction()
"http://localhost:18384/api/Trippin/$metadata#Edm.Int32");
}

[Fact]
public void EntityBoundFunctionNonExist()
{
TestGetStatusCodeIs("People(111)/Microsoft.OData.Service.Sample.Trippin.Models.GetNumberOfFriends", 404);
}

[Fact]
public void EntitySetBoundFunctionIEnumerable()
{
Expand Down Expand Up @@ -360,6 +366,12 @@ public void AddressingBoundAction()
"http://localhost:18384/api/Trippin/$metadata#Trips/$entity");
}

[Fact]
public void AddressingBoundActionNonExist()
{
TestPostStatusCodeIs("Trips(111)/Microsoft.OData.Service.Sample.Trippin.Models.EndTrip", 404);
}

[Fact]
public void AddressingBoundActionWithParenthesis()
{
Expand Down

0 comments on commit 4344c5b

Please sign in to comment.