Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests reading an entity with a non-existent key #252

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public OkObjectResult GetString()
#if NETFRAMEWORK
public HttpResponseMessage GetGuid()
#elif NETSTANDARD
public OkObjectResult GetGuid()
public ActionResult GetGuid()
#endif
{
try
Expand All @@ -430,8 +430,18 @@ public OkObjectResult GetGuid()

var edmObj = GetEdmObject(_model.GetEdmEntityType(type), obj, 1, null, _dynamicView);
#if NETFRAMEWORK
if (obj == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}

return Request.CreateResponse(HttpStatusCode.OK, edmObj);
#elif NETSTANDARD
if (obj == null)
{
return NotFound(edmObj);
}

return Ok(edmObj);
#endif
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace NewPlatform.Flexberry.ORM.ODataService.Tests.CRUD.Read
{
using System;
using System.Net;
using System.Net.Http;

using ICSSoft.STORMNET;

using Xunit;

/// <summary>
/// Unit-test class for reading a non-existent data through OData service.
/// </summary>
public class GetByIdTest : BaseODataServiceIntegratedTest
{
#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public GetByIdTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
#endif

/// <summary>
/// Tests that a request with a non-existent key returns a 404 error.
/// </summary>
[Fact]
public void TestGetById()
{
ActODataService(args =>
{
string requestUrl = string.Format("http://localhost/odata/{0}({1})", args.Token.Model.GetEdmEntitySet(typeof(Страна)).Name, "8dcd3aa3-11c2-456d-902c-03323e1ae635");

using (HttpResponseMessage response = args.HttpClient.GetAsync(requestUrl).Result)
{
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
});
}
}
}