Skip to content

Commit

Permalink
Merge pull request #246 from Flexberry/fix-245-before-get-count
Browse files Browse the repository at this point in the history
Add test for Count and BeforeGet
  • Loading branch information
Bratchikov Igor authored Feb 4, 2022
2 parents ecf87e9 + 7492dec commit 599362e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion NewPlatform.Flexberry.ORM.ODataService.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>NewPlatform.Flexberry.ORM.ODataService</id>
<version>5.2.0</version>
<version>5.2.1</version>
<title>Flexberry ORM ODataService</title>
<authors>New Platform Ltd.</authors>
<owners>New Platform Ltd.</owners>
Expand All @@ -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.
</releaseNotes>
<copyright>Copyright New Platform Ltd 2021</copyright>
<tags>Flexberry ORM OData ODataService</tags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -27,6 +31,16 @@ public bool BeforeGet(ref LoadingCustomizationStruct lcs)
return true;
}

/// <summary>
/// Блокирует получение объектов.
/// </summary>
/// <param name="lcs">LCS.</param>
/// <returns>false</returns>
public bool FalseBeforeGet(ref LoadingCustomizationStruct lcs)
{
return false;
}

/// <summary>
/// Осуществляет проверку того, что при POST запросах происходит вставка объекта,
/// зависимые объекты (мастера, детейлы) обрабатываются в зависимости от наличия в БД - вставляются или обновляются.
Expand Down Expand Up @@ -68,5 +82,34 @@ public void TestBeforeGet()
}
});
}

/// <summary>
/// Проверяет, что результат BeforeGet не игнорируется при параметре count=true.
/// </summary>
[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<string, object> receivedDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(receivedStr);
Assert.Empty((JArray)receivedDict["value"]);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
});
}
}
}

0 comments on commit 599362e

Please sign in to comment.