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

Fix bug with PropertyFilter #211

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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 @@ -39,14 +39,29 @@ public class BaseODataServiceIntegratedTest : BaseIntegratedTest
{
protected IDataObjectEdmModelBuilder _builder;

/// <summary>
/// Arguments for test methods.
/// </summary>
public class TestArgs
{
/// <summary>
/// Unity container.
/// </summary>
public IUnityContainer UnityContainer { get; set; }

/// <summary>
/// Management token.
/// </summary>
public ManagementToken Token { get; set; }

/// <summary>
/// Data service.
/// </summary>
public IDataService DataService { get; set; }

/// <summary>
/// Http client.
/// </summary>
public HttpClient HttpClient { get; set; }
}

Expand Down Expand Up @@ -209,12 +224,5 @@ protected string CreateChangeset(string url, string body, DataObject dataObject)
{
return BatchHelper.CreateChangeset(url, body, dataObject);
}

/*
private bool PropertyFilter(PropertyInfo propertyInfo)
{
return Information.ExtractPropertyInfo<Agent>(x => x.Pwd) != propertyInfo;
}
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Http;

using System.Reflection;
using ICSSoft.STORMNET;
using ICSSoft.STORMNET.UserDataTypes;
using ICSSoft.STORMNET.Windows.Forms;

using NewPlatform.Flexberry.ORM.ODataService.Model;
using NewPlatform.Flexberry.ORM.ODataService.Tests.Extensions;

using Newtonsoft.Json;
Expand All @@ -21,6 +21,7 @@
/// </summary>
public class FilterTest : BaseODataServiceIntegratedTest
{

#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
Expand All @@ -30,10 +31,16 @@ public class FilterTest : BaseODataServiceIntegratedTest
public FilterTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
DataObjectsAssembliesNames = new[]
{
typeof(Car).Assembly
};

_builder = new DefaultDataObjectEdmModelBuilder(DataObjectsAssembliesNames, UseNamespaceInEntitySetName) { PropertyFilter = PropertyFilter };
}
#endif

[Fact]
[Fact]
public void TestFilterStringKey()
{
ActODataService(args =>
Expand Down Expand Up @@ -320,6 +327,54 @@ public void TestFilterNotStored()
});
}

/// <summary>
/// Test FilteredProperty is absent in response. Filter is <see cref="PropertyFilter"/>.
/// </summary>
[Fact]
public void TestFilteredProperty()
{
ActODataService(args =>
{
var breed = new Порода() { Название = "Хвостатая" };
var cat = new Кошка() { Порода = breed, Тип = ТипКошки.Домашняя };
var kitty = new Котенок() { КличкаКотенка = "Барсище", Глупость = 55, Кошка = cat };
var objs = new DataObject[] { kitty };
args.DataService.UpdateObjects(ref objs);

string requestUrl = string.Format(
"http://localhost/odata/{0}?$filter={1}",
args.Token.Model.GetEdmEntitySet(typeof(Котенок)).Name,
$"КличкаКотенка eq '{kitty.КличкаКотенка}'");

// Обращаемся к OData-сервису и обрабатываем ответ.
using (HttpResponseMessage response = args.HttpClient.GetAsync(requestUrl).Result)
{
// Убедимся, что запрос завершился успешно.
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

// Получим строку с ответом.
string receivedStr = response.Content.ReadAsStringAsync().Result.Beautify();

Assert.DoesNotContain(nameof(Котенок.Глупость), receivedStr);

// Преобразуем полученный объект в словарь.
Dictionary<string, object> receivedDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(receivedStr);

Assert.Equal(1, ((JArray)receivedDict["value"]).Count);
}
});
}

/// <summary>
/// Property filter for <see cref="TestFilteredProperty"/>.
/// </summary>
/// <param name="propertyInfo">Property info for checks.</param>
/// <returns>Filter result.</returns>
protected virtual bool PropertyFilter(PropertyInfo propertyInfo)
{
return Information.ExtractPropertyInfo<Котенок>(x => x.Глупость) != propertyInfo;
}

/// <summary>
/// Осуществляет проверку применения $filter на равенство дат в запросах OData.
/// </summary>
Expand Down