Skip to content

Commit

Permalink
Добавлена возможность указать Startup в тестах
Browse files Browse the repository at this point in the history
  • Loading branch information
turbcool committed Jan 25, 2024
1 parent c51df09 commit 68c60fe
Show file tree
Hide file tree
Showing 35 changed files with 253 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public abstract class BaseIntegratedTest : IDisposable
/// <summary>
/// Base class for integration tests.
/// </summary>
public abstract class BaseIntegratedTest : IClassFixture<CustomWebApplicationFactory<Startup>>, IDisposable
/// <typeparam name="TStartup">Startup class used for booting the application.</typeparam>
public abstract class BaseIntegratedTest<TStartup> : IClassFixture<CustomWebApplicationFactory<TStartup>>, IDisposable
where TStartup : class
{
protected readonly WebApplicationFactory<Startup> _factory;
protected readonly WebApplicationFactory<TStartup> _factory;
#endif
protected ITestOutputHelper _output;

Expand Down Expand Up @@ -139,7 +141,7 @@ protected BaseIntegratedTest(string tempDbNamePrefix, bool useGisDataService = f
/// <param name="output">Unit tests debug output.</param>
/// <param name="tempDbNamePrefix">Prefix for temp database name.</param>
/// <param name="useGisDataService">Use DataService with Gis support.</param>
protected BaseIntegratedTest(CustomWebApplicationFactory<Startup> factory, ITestOutputHelper output, string tempDbNamePrefix, bool useGisDataService = false)
protected BaseIntegratedTest(CustomWebApplicationFactory<TStartup> factory, ITestOutputHelper output, string tempDbNamePrefix, bool useGisDataService = false)
{
_factory = factory;
_output = output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
/// <summary>
/// Базовый класс для тестирования работы с данными через ODataService.
/// </summary>
#if NETFRAMEWORK
public class BaseODataServiceIntegratedTest : BaseIntegratedTest
#endif
#if NETCOREAPP
public class BaseODataServiceIntegratedTest<TStartup> : BaseIntegratedTest<TStartup>
where TStartup : class
#endif
{
protected IDataObjectEdmModelBuilder _builder;

Expand Down Expand Up @@ -72,7 +78,7 @@ public BaseODataServiceIntegratedTest(
}
#endif
#if NETCOREAPP
public BaseODataServiceIntegratedTest(CustomWebApplicationFactory<Startup> factory, ITestOutputHelper output = null, bool useNamespaceInEntitySetName = false, bool useGisDataService = false, PseudoDetailDefinitions pseudoDetailDefinitions = null)
public BaseODataServiceIntegratedTest(CustomWebApplicationFactory<TStartup> factory, ITestOutputHelper output = null, bool useNamespaceInEntitySetName = false, bool useGisDataService = false, PseudoDetailDefinitions pseudoDetailDefinitions = null)
: base(factory, output, "ODataDB", useGisDataService)
{
Init(useNamespaceInEntitySetName, pseudoDetailDefinitions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
/// <summary>
/// Класс тестов для тестирования бизнес-серверов.
/// </summary>
#if NETFRAMEWORK
public class BusinessServersTest : BaseODataServiceIntegratedTest
#endif
#if NETCOREAPP
public class BusinessServersTest : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public BusinessServersTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
public BusinessServersTest(CustomWebApplicationFactory<TestStartup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@
/// <summary>
/// Класс тестов для тестирования изменения мастера при создании детейла.
/// </summary>
#if NETFRAMEWORK
public class ChangeMasterInBSTest : BaseODataServiceIntegratedTest
#endif
#if NETCOREAPP
public class ChangeMasterInBSTest : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public ChangeMasterInBSTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
public ChangeMasterInBSTest(CustomWebApplicationFactory<TestStartup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
/// <summary>
/// Unit-test class for creation entity instance with pseudodetail field defined through OData service.
/// </summary>
#if NETFRAMEWORK
public class CreateWithPseudoDetailDefinedTest : BaseODataServiceIntegratedTest
#endif
#if NETCOREAPP
public class CreateWithPseudoDetailDefinedTest : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
private static PseudoDetailDefinitions GetPseudoDetailDefinitions()
{
Expand All @@ -31,7 +36,7 @@ public CreateWithPseudoDetailDefinedTest() : base(pseudoDetailDefinitions: GetPs
}
#endif
#if NETCOREAPP
public CreateWithPseudoDetailDefinedTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output) : base(factory, output, pseudoDetailDefinitions: GetPseudoDetailDefinitions())
public CreateWithPseudoDetailDefinedTest(CustomWebApplicationFactory<TestStartup> factory, Xunit.Abstractions.ITestOutputHelper output) : base(factory, output, pseudoDetailDefinitions: GetPseudoDetailDefinitions())
{
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
/// <summary>
/// Класс тестов для тестирования работы с гео-данными.
/// </summary>
#if NETFRAMEWORK
public class GisCRUDTest : BaseODataServiceIntegratedTest
#endif
#if NETCOREAPP
public class GisCRUDTest : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
#if NETFRAMEWORK
/// <summary>
Expand All @@ -37,7 +42,7 @@ public GisCRUDTest()
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод диагностической информации по тестам.</param>
public GisCRUDTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, ITestOutputHelper output)
public GisCRUDTest(CustomWebApplicationFactory<TestStartup> factory, ITestOutputHelper output)
: base(factory, output, false, true)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ namespace NewPlatform.Flexberry.ORM.ODataService.Tests.CRUD
/// <summary>
/// Тесты CRUD операций с множеством пользователей.
/// </summary>
#if NETFRAMEWORK
public class MultiThreadTests : BaseODataServiceIntegratedTest
#endif
#if NETCOREAPP
public class MultiThreadTests : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
private const int ThreadCount = 50;

Expand All @@ -54,7 +59,7 @@ public MultiThreadTests(Xunit.Abstractions.ITestOutputHelper output)
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public MultiThreadTests(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
public MultiThreadTests(CustomWebApplicationFactory<TestStartup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
Expand Down Expand Up @@ -337,7 +342,7 @@ private static void RegisterCustomUser(IUnityContainer container)
container.RegisterType<IHttpContextAccessor, HttpContextAccessor>();
#if NETCOREAPP
container.RegisterType<IActionContextAccessor, ActionContextAccessor>();
#endif
#endif
container.RegisterType<CurrentUserService.IUser, WebHttpUser>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
/// <summary>
/// Класс тестов для тестирования применения $filter в OData-сервисе.
/// </summary>
#if NETFRAMEWORK
public class BuiltinQueryFunctionsTest : BaseODataServiceIntegratedTest
#endif
#if NETCOREAPP
public class BuiltinQueryFunctionsTest : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public BuiltinQueryFunctionsTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
public BuiltinQueryFunctionsTest(CustomWebApplicationFactory<TestStartup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
/// <summary>
/// A class for testing exports from Excel.
/// </summary>
#if NETFRAMEWORK
public class ExcelExportTest : BaseODataServiceIntegratedTest
#endif
#if NETCOREAPP
public class ExcelExportTest : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public ExcelExportTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
public ExcelExportTest(CustomWebApplicationFactory<TestStartup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
/// <summary>
/// Unit-test class for filtering data through OData service by master details fields.
/// </summary>
#if NETFRAMEWORK
public class FilterByMasterDetailFieldTest : BaseODataServiceIntegratedTest
#endif
#if NETCOREAPP
public class FilterByMasterDetailFieldTest : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public FilterByMasterDetailFieldTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
public FilterByMasterDetailFieldTest(CustomWebApplicationFactory<TestStartup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
Expand Down Expand Up @@ -145,82 +150,82 @@ public void TestFilterByDetailMaster()
Медведь медведь3 = new Медведь() { ПорядковыйНомер = 3 };

Лес лес1 = new Лес() { Название = "Шишкин" };
Лес лес2 = new Лес() { Название = "Ёжкин" };
Лес лес2 = new Лес() { Название = "Ёжкин" };
Лес лес3 = new Лес() { Название = "Пыжкин" };

Берлога берлога1 = new Берлога() { Наименование = "Берлога 1", ЛесРасположения = лес1, Заброшена = true };
Берлога берлога2 = new Берлога() { Наименование = "Берлога 2", ЛесРасположения = лес1, Заброшена = false };
Берлога берлога3 = new Берлога() { Наименование = "Берлога 3", ЛесРасположения = лес2, Заброшена = false };
Берлога берлога4 = new Берлога() { Наименование = "Берлога 4", ЛесРасположения = лес2, Заброшена = false };
Берлога берлога4 = new Берлога() { Наименование = "Берлога 4", ЛесРасположения = лес2, Заброшена = false };
Берлога берлога5 = new Берлога() { Наименование = "Берлога 5", ЛесРасположения = лес3, Заброшена = false };
Берлога берлога6 = new Берлога() { Наименование = "Берлога 6", ЛесРасположения = лес3, Заброшена = true};

медведь1.Берлога.AddRange(берлога1, берлога2);
медведь2.Берлога.AddRange(берлога3, берлога4);
медведь2.Берлога.AddRange(берлога3, берлога4);
медведь3.Берлога.AddRange(берлога5, берлога6);

DataObject[] newDataObjects = new DataObject[] { лес1, лес2, лес3, медведь1, медведь2, берлога1, берлога2, берлога3, берлога4, берлога5, берлога6 };

args.DataService.UpdateObjects(ref newDataObjects);
ExternalLangDef.LanguageDef.DataService = args.DataService;

// Act.
ExternalLangDef.LanguageDef.DataService = args.DataService;

// Act.
string requestUrl = string.Format(
"http://localhost/odata/{0}?$filter={1}",
args.Token.Model.GetEdmEntitySet(typeof(Берлога)).Name,
"(Медведь/Берлога/any(f:(f/Заброшена eq true)))");

using (var response = args.HttpClient.GetAsync(requestUrl).Result)
{
// Assert.
{
// Assert.
string receivedStr = response.Content.ReadAsStringAsync().Result.Beautify();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Dictionary<string, object> receivedDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(receivedStr);
Assert.Equal(4, ((JArray)receivedDict["value"]).Count);
}
});
}

}

/// <summary>
/// Tests filtering data by detail enum field with complex predicate.
/// </summary>
[Fact]
public void TestFilterByEnumDetailMaster()
{
ActODataService(args =>
{
// Arrange.
Driver driver1 = new Driver { CarCount = 2, Documents = true, Name = "Driver1" };
Driver driver2 = new Driver { CarCount = 2, Documents = true, Name = "Driver2" };
Driver driver3 = new Driver { CarCount = 2, Documents = true, Name = "Driver3" };
{
// Arrange.
Driver driver1 = new Driver { CarCount = 2, Documents = true, Name = "Driver1" };
Driver driver2 = new Driver { CarCount = 2, Documents = true, Name = "Driver2" };
Driver driver3 = new Driver { CarCount = 2, Documents = true, Name = "Driver3" };

Car car1d1 = new Car { Model = "ВАЗ", TipCar = tTip.sedan };
Car car2d1 = new Car { Model = "ГАЗ", TipCar = tTip.sedan };

Car car1d2 = new Car { Model = "BMW", TipCar = tTip.crossover };
Car car2d2 = new Car { Model = "Porsche", TipCar = tTip.sedan };


Car car1d3 = new Car { Model = "Lamborghini", TipCar = tTip.crossover };
Car car2d3 = new Car { Model = "Subaru", TipCar = tTip.sedan };

Car car2d3 = new Car { Model = "Subaru", TipCar = tTip.sedan };

driver1.Car.AddRange(car1d1, car2d1);
driver2.Car.AddRange(car1d2, car2d2);
driver2.Car.AddRange(car1d2, car2d2);
driver3.Car.AddRange(car1d3, car2d3);

DataObject[] newDataObjects = new DataObject[] { driver1, driver2, driver3, car1d1, car2d1, car1d2, car2d2, car1d3, car2d3 };

args.DataService.UpdateObjects(ref newDataObjects);
ExternalLangDef.LanguageDef.DataService = args.DataService;

// Act.
ExternalLangDef.LanguageDef.DataService = args.DataService;

// Act.
string requestUrl = string.Format(
"http://localhost/odata/{0}?$filter={1}",
args.Token.Model.GetEdmEntitySet(typeof(Car)).Name,
"(Driver/Car/any(f:(f/TipCar eq NewPlatform.Flexberry.ORM.ODataService.Tests.tTip'crossover')))");

using (var response = args.HttpClient.GetAsync(requestUrl).Result)
{
// Assert.
{
// Assert.
string receivedStr = response.Content.ReadAsStringAsync().Result.Beautify();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Dictionary<string, object> receivedDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(receivedStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
/// <summary>
/// Unit-test class for filtering data through OData service by master fields.
/// </summary>
#if NETFRAMEWORK
public class FilterByMasterFieldTest : BaseODataServiceIntegratedTest
{
#endif
#if NETCOREAPP
public class FilterByMasterFieldTest : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public FilterByMasterFieldTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
public FilterByMasterFieldTest(CustomWebApplicationFactory<TestStartup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ namespace NewPlatform.Flexberry.ORM.ODataService.Tests.CRUD.Read
/// <summary>
/// Unit-test class for filtering data through OData service by master master details fields.
/// </summary>
#if NETFRAMEWORK
public class FilterByMasterMasterDetailFieldTest : BaseODataServiceIntegratedTest
#endif
#if NETCOREAPP
public class FilterByMasterMasterDetailFieldTest : BaseODataServiceIntegratedTest<TestStartup>
#endif
{
#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public FilterByMasterMasterDetailFieldTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
public FilterByMasterMasterDetailFieldTest(CustomWebApplicationFactory<TestStartup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
Expand Down
Loading

0 comments on commit 68c60fe

Please sign in to comment.