diff --git a/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs b/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs index 6da1eabe..373b6113 100644 --- a/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs +++ b/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs @@ -417,7 +417,7 @@ public OkObjectResult GetString() #if NETFRAMEWORK public HttpResponseMessage GetGuid() #elif NETSTANDARD - public OkObjectResult GetGuid() + public ActionResult GetGuid() #endif { try @@ -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 } diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetByIdTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetByIdTest.cs new file mode 100644 index 00000000..560ead0c --- /dev/null +++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/GetByIdTest.cs @@ -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; + + /// + /// Unit-test class for reading a non-existent data through OData service. + /// + public class GetByIdTest : BaseODataServiceIntegratedTest + { +#if NETCOREAPP + /// + /// Конструктор по-умолчанию. + /// + /// Фабрика для приложения. + /// Вывод отладочной информации. + public GetByIdTest(CustomWebApplicationFactory factory, Xunit.Abstractions.ITestOutputHelper output) + : base(factory, output) + { + } +#endif + + /// + /// Tests that a request with a non-existent key returns a 404 error. + /// + [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); + } + }); + } + } +}