From 1b6cf561dd19aab3f5bf94ff7057abfffe4aa6fb Mon Sep 17 00:00:00 2001 From: Bratchikov Igor Date: Thu, 14 Jan 2021 18:50:50 +0500 Subject: [PATCH 1/2] Add test for #205 --- .../BaseODataServiceIntegratedTest.cs | 27 ++++--- .../CRUD/Read/FilterTest.cs | 72 +++++++++++++++++-- 2 files changed, 86 insertions(+), 13 deletions(-) diff --git a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs index f66fc426..ac5e8e7b 100644 --- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs +++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs @@ -29,16 +29,34 @@ /// public class BaseODataServiceIntegratedTest : BaseIntegratedTest { - protected readonly IDataObjectEdmModelBuilder _builder; + /// + /// Edm model builder. + /// + 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; } } @@ -222,12 +240,5 @@ private string GetMethodAndUrl(DataObject dataObject, string url) throw new InvalidOperationException(); } } - - /* - 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 29b21969..708fdc7b 100644 --- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/FilterTest.cs +++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/FilterTest.cs @@ -3,12 +3,12 @@ using System; using System.Collections.Generic; using System.Net; - using System.Net.Http; - + using System.Net.Http; + using System.Reflection; using ICSSoft.STORMNET; using ICSSoft.STORMNET.UserDataTypes; - using ICSSoft.STORMNET.Windows.Forms; - + using ICSSoft.STORMNET.Windows.Forms; + using NewPlatform.Flexberry.ORM.ODataService.Model; using NewPlatform.Flexberry.ORM.ODataService.Tests.Extensions; using Newtonsoft.Json; @@ -20,7 +20,21 @@ /// Класс тестов для тестирования применения $filter в OData-сервисе. /// public class FilterTest : BaseODataServiceIntegratedTest - { + { + /// + /// Initialize new instance of . + /// + public FilterTest() + : base() + { + DataObjectsAssembliesNames = new[] + { + typeof(Car).Assembly + }; + + _builder = new DefaultDataObjectEdmModelBuilder(DataObjectsAssembliesNames, UseNamespaceInEntitySetName) { PropertyFilter = PropertyFilter }; + } + [Fact] public void TestFilterStringKey() { @@ -306,6 +320,54 @@ public void TestFilterNotStored() Assert.Equal(1, ((JArray)receivedDict["value"]).Count); } }); + } + + /// + /// Test FilteredProperty is absend 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; } } } From 1c9394ffe04a449a8871332ec31aa0df8f57420a Mon Sep 17 00:00:00 2001 From: Ilya Naydanov Date: Fri, 7 Apr 2023 14:18:16 +0500 Subject: [PATCH 2/2] fix test initialization --- .../CRUD/Read/FilterTest.cs | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) 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 78f1450a..c41fc26b 100644 --- a/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/FilterTest.cs +++ b/Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/CRUD/Read/FilterTest.cs @@ -21,19 +21,6 @@ /// public class FilterTest : BaseODataServiceIntegratedTest { - /// - /// Initialize new instance of . - /// - public FilterTest() - : base() - { - DataObjectsAssembliesNames = new[] - { - typeof(Car).Assembly - }; - - _builder = new DefaultDataObjectEdmModelBuilder(DataObjectsAssembliesNames, UseNamespaceInEntitySetName) { PropertyFilter = PropertyFilter }; - } #if NETCOREAPP /// @@ -44,6 +31,12 @@ public FilterTest() public FilterTest(CustomWebApplicationFactory factory, Xunit.Abstractions.ITestOutputHelper output) : base(factory, output) { + DataObjectsAssembliesNames = new[] + { + typeof(Car).Assembly + }; + + _builder = new DefaultDataObjectEdmModelBuilder(DataObjectsAssembliesNames, UseNamespaceInEntitySetName) { PropertyFilter = PropertyFilter }; } #endif @@ -335,7 +328,7 @@ public void TestFilterNotStored() } /// - /// Test FilteredProperty is absend in response. Filter is . + /// Test FilteredProperty is absent in response. Filter is . /// [Fact] public void TestFilteredProperty()