diff --git a/CHANGELOG.md b/CHANGELOG.md index 9085eeb6..cbb258c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +## [5.2.1] - 2022.02.04 + +### Fixed + 1. CallbackBeforeGet with count equals true. + ## [5.2.0] - 2021.06.03 ### Added diff --git a/NewPlatform.Flexberry.ORM.ODataService.nuspec b/NewPlatform.Flexberry.ORM.ODataService.nuspec index 54c4d87e..e8b66b37 100644 --- a/NewPlatform.Flexberry.ORM.ODataService.nuspec +++ b/NewPlatform.Flexberry.ORM.ODataService.nuspec @@ -2,7 +2,7 @@ NewPlatform.Flexberry.ORM.ODataService - 5.2.0 + 5.2.1 Flexberry ORM ODataService New Platform Ltd. New Platform Ltd. @@ -25,6 +25,7 @@ 2. SafeLoadDetails for models with TypeUsage. 3. Batch update CallbackAfterCreate, CallbackAfterUpdate, CallbackAfterDelete call. 4. SafeLoadDetails for partial loaded agregator. + 5. BeforeGet when count equals true. Copyright New Platform Ltd 2021 Flexberry ORM OData ODataService diff --git a/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs b/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs index 07d07810..7d492806 100644 --- a/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs +++ b/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs @@ -974,7 +974,7 @@ private HttpResponseMessage ExecuteExpression() Count = count; } - if (!IncludeCount || count != 0) + if (!IncludeCount || count > 0) _objs = LoadObjects(_lcs, out count, callExecuteCallbackBeforeGet, false); NameValueCollection queryParams = Request.RequestUri.ParseQueryString(); diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/Events/BeforeGetTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/Events/BeforeGetTest.cs index 8462c7a5..db1a44e7 100644 --- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/Events/BeforeGetTest.cs +++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/Events/BeforeGetTest.cs @@ -1,11 +1,15 @@ namespace NewPlatform.Flexberry.ORM.ODataService.Tests.Events { - using System; + using System; + using System.Collections.Generic; using System.Net; using System.Net.Http; using ICSSoft.STORMNET; - using ICSSoft.STORMNET.Business; + using ICSSoft.STORMNET.Business; + using NewPlatform.Flexberry.ORM.ODataService.Tests.Extensions; + using Newtonsoft.Json; + using Newtonsoft.Json.Linq; using Xunit; @@ -27,6 +31,16 @@ public bool BeforeGet(ref LoadingCustomizationStruct lcs) return true; } + /// + /// Блокирует получение объектов. + /// + /// LCS. + /// false + public bool FalseBeforeGet(ref LoadingCustomizationStruct lcs) + { + return false; + } + /// /// Осуществляет проверку того, что при POST запросах происходит вставка объекта, /// зависимые объекты (мастера, детейлы) обрабатываются в зависимости от наличия в БД - вставляются или обновляются. @@ -68,5 +82,34 @@ public void TestBeforeGet() } }); } + + /// + /// Проверяет, что результат BeforeGet не игнорируется при параметре count=true. + /// + [Fact] + public void TestCountAndBeforeGet() + { + ActODataService(args => + { + // Arrange. + Медведь медведь1 = new Медведь() { ПорядковыйНомер = 1 }; + Медведь медведь2 = new Медведь() { ПорядковыйНомер = 2 }; + + DataObject[] newDataObjects = new DataObject[] { медведь1, медведь2 }; + + args.DataService.UpdateObjects(ref newDataObjects); + args.Token.Events.CallbackBeforeGet = FalseBeforeGet; + + string requestUrl = string.Format("http://localhost/odata/{0}?$count=true", args.Token.Model.GetEdmEntitySet(typeof(Медведь)).Name); + + using (var response = args.HttpClient.GetAsync(requestUrl).Result) + { + string receivedStr = response.Content.ReadAsStringAsync().Result.Beautify(); + Dictionary receivedDict = JsonConvert.DeserializeObject>(receivedStr); + Assert.Empty((JArray)receivedDict["value"]); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + }); + } } }