diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs index e904d023..8a7a98c8 100644 --- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs +++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs @@ -39,14 +39,29 @@ public class BaseODataServiceIntegratedTest : BaseIntegratedTest { protected IDataObjectEdmModelBuilder _builder; + /// + /// Arguments for test methods. + /// public class TestArgs { + /// + /// Unity container. + /// public IUnityContainer UnityContainer { get; set; } + /// + /// Management token. + /// public ManagementToken Token { get; set; } + /// + /// Data service. + /// public IDataService DataService { get; set; } + /// + /// Http client. + /// public HttpClient HttpClient { get; set; } } @@ -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(x => x.Pwd) != propertyInfo; - } - */ } } diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/FilterTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/FilterTest.cs index d6cdbb27..c41fc26b 100644 --- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/FilterTest.cs +++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/FilterTest.cs @@ -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; @@ -21,6 +21,7 @@ /// public class FilterTest : BaseODataServiceIntegratedTest { + #if NETCOREAPP /// /// Конструктор по-умолчанию. @@ -30,10 +31,16 @@ public class FilterTest : BaseODataServiceIntegratedTest public FilterTest(CustomWebApplicationFactory 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 => @@ -320,6 +327,54 @@ public void TestFilterNotStored() }); } + /// + /// Test FilteredProperty is absent in response. Filter is . + /// + [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 receivedDict = JsonConvert.DeserializeObject>(receivedStr); + + Assert.Equal(1, ((JArray)receivedDict["value"]).Count); + } + }); + } + + /// + /// Property filter for . + /// + /// Property info for checks. + /// Filter result. + protected virtual bool PropertyFilter(PropertyInfo propertyInfo) + { + return Information.ExtractPropertyInfo<Котенок>(x => x.Глупость) != propertyInfo; + } + /// /// Осуществляет проверку применения $filter на равенство дат в запросах OData. ///