Skip to content

Commit

Permalink
Add test for #205
Browse files Browse the repository at this point in the history
  • Loading branch information
Bratchikov Igor committed Jan 14, 2021
1 parent 75d9b0c commit 1b6cf56
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,34 @@
/// </summary>
public class BaseODataServiceIntegratedTest : BaseIntegratedTest
{
protected readonly IDataObjectEdmModelBuilder _builder;
/// <summary>
/// Edm model builder.
/// </summary>
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 @@ -222,12 +240,5 @@ private string GetMethodAndUrl(DataObject dataObject, string url)
throw new InvalidOperationException();
}
}

/*
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 @@ -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;
Expand All @@ -20,7 +20,21 @@
/// Класс тестов для тестирования применения $filter в OData-сервисе.
/// </summary>
public class FilterTest : BaseODataServiceIntegratedTest
{
{
/// <summary>
/// Initialize new instance of <see cref="FilterTest"/>.
/// </summary>
public FilterTest()
: base()
{
DataObjectsAssembliesNames = new[]
{
typeof(Car).Assembly
};

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

[Fact]
public void TestFilterStringKey()
{
Expand Down Expand Up @@ -306,6 +320,54 @@ public void TestFilterNotStored()
Assert.Equal(1, ((JArray)receivedDict["value"]).Count);
}
});
}

/// <summary>
/// Test FilteredProperty is absend 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;
}
}
}

0 comments on commit 1b6cf56

Please sign in to comment.