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

Feature add new tests #71

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
12 changes: 9 additions & 3 deletions NewPlatform.Flexberry.ORM.IntegratedTests/BaseIntegratedTest.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
[assembly: Xunit.CollectionBehavior(DisableTestParallelization = true)]
namespace NewPlatform.Flexberry.ORM.IntegratedTests
{
using ICSSoft.STORMNET.Business;
using Npgsql;
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Threading;
using ICSSoft.STORMNET.Business;
using Npgsql;
using Oracle.ManagedDataAccess.Client;
using Xunit.Abstractions;

public abstract class BaseIntegratedTest : IDisposable
{
/// <summary>
/// XUnit output.
/// </summary>
protected ITestOutputHelper output;

/// <summary>
/// The temporary database name prefix.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
namespace NewPlatform.Flexberry.ORM.IntegratedTests.ExternalLDef
{
using System;
using ICSSoft.STORMNET;
using ICSSoft.STORMNET.Business;
using ICSSoft.STORMNET.FunctionalLanguage;
using ICSSoft.STORMNET.KeyGen;
using ICSSoft.STORMNET.Windows.Forms;
using NewPlatform.Flexberry.ORM.Tests;
using Xunit;
using Xunit.Abstractions;

/// <summary>
/// Test for master details limits.
/// </summary>
public class MasterDetailsLimitTest : BaseIntegratedTest
{
public MasterDetailsLimitTest(ITestOutputHelper output)
: base("MstDtLmt")
{
this.output = output;
}

/// <summary>
/// Test for limitations by master details.
/// </summary>
[Fact]
public void MasterDetailsLimitationTest()
{
foreach (IDataService dataService in DataServices)
{
// Arrange.
Медведь медведь1 = new Медведь() { ПорядковыйНомер = 1 };
Медведь медведь2 = new Медведь() { ПорядковыйНомер = 2 };

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

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

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

Блоха блоха1 = new Блоха() { Кличка = "Блоха 1", МедведьОбитания = медведь1 };
Блоха блоха2 = new Блоха() { Кличка = "Блоха 2", МедведьОбитания = медведь2 };
Блоха блоха3 = new Блоха() { Кличка = "Блоха 3" };
Блоха блоха4 = new Блоха() { Кличка = "Блоха 4", МедведьОбитания = медведь1 };

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

dataService.UpdateObjects(ref newDataObjects);

Guid лес1Pk = ((KeyGuid)лес1.__PrimaryKey).Guid;

View view = new View();
view.DefineClassType = typeof(Блоха);
view.AddProperty(Information.ExtractPropertyPath<Блоха>(б => б.Кличка));
view.AddProperty(Information.ExtractPropertyPath<Блоха>(б => б.МедведьОбитания));
view.AddProperty(Information.ExtractPropertyPath<Блоха>(б => б.МедведьОбитания.ПорядковыйНомер));

LoadingCustomizationStruct lcs = LoadingCustomizationStruct.GetSimpleStruct(typeof(Блоха), view);

// Выберем всех блох, чей медведь живёт в берлоге 1.
DetailVariableDef dvd = new DetailVariableDef();
dvd.ConnectMasterPorp = Information.ExtractPropertyPath<Берлога>(б => б.Медведь);
dvd.OwnerConnectProp = new string[] { Information.ExtractPropertyPath<Блоха>(б => б.МедведьОбитания) };
View viewDetail = new View();
viewDetail.DefineClassType = typeof(Берлога);
viewDetail.AddProperty(Information.ExtractPropertyPath<Берлога>(б => б.Наименование));
viewDetail.AddProperty(Information.ExtractPropertyPath<Берлога>(б => б.Медведь));
viewDetail.AddProperty(Information.ExtractPropertyPath<Берлога>(б => б.ЛесРасположения));

dvd.View = viewDetail;
ExternalLangDef ldef = ExternalLangDef.LanguageDef;
dvd.Type = ldef.DetailsType;
Function detailsLimitName = ldef.GetFunction(ldef.funcEQ, new VariableDef(ldef.StringType, Information.ExtractPropertyPath<Берлога>(б => б.Наименование)), "Берлога 1");
Function detailsLimitForest = ldef.GetFunction(ldef.funcEQ, new VariableDef(ldef.GuidType, Information.ExtractPropertyPath<Берлога>(б => б.ЛесРасположения)), лес1Pk);
Function detailsLimit = ldef.GetFunction(ldef.funcAND, detailsLimitName, detailsLimitForest);
lcs.LimitFunction = ldef.GetFunction(ldef.funcExist, dvd, detailsLimit);

// Act.
DataObject[] dataObjects = dataService.LoadObjects(lcs);

// Assert.
Assert.Equal(2, dataObjects.Length);

foreach (Блоха блоха in dataObjects)
{
if (блоха.Кличка == "Блоха 1" || блоха.Кличка == "Блоха 4")
{
continue;
}

throw new System.Exception("Limit not work properly.");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using ICSSoft.STORMNET.FunctionalLanguage;
using ICSSoft.STORMNET.FunctionalLanguage.SQLWhere;
using ICSSoft.STORMNET.Windows.Forms;
using Xunit;
using NewPlatform.Flexberry.ORM.Tests;
using Xunit;

/// <summary>
/// This is a test class for LinqToLcsTest and is intended
Expand Down Expand Up @@ -121,6 +121,9 @@ public void GetLcsTestDetailAnyConjunction()
Assert.True(Equals(expected, actual));
}

/// <summary>
/// Проверка ограничения на детейл мастера.
/// </summary>
[Fact]
public void GetLcsTestDetailWithCustomOwnerConnectProp()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
namespace ICSSoft.STORMNET.Business.LINQProvider
{
using System;
using System.Linq;
using System.Linq.Expressions;
using ICSSoft.STORMNET.Business.LINQProvider.Tests;
using ICSSoft.STORMNET.FunctionalLanguage;
using ICSSoft.STORMNET.Windows.Forms;
using NewPlatform.Flexberry.ORM.Tests;
using Xunit;

/// <summary>
/// Test LinqProvider for limitations by master details like <see cref="MasterDetailsLimitTest.MasterDetailsLimitationTest"/>.
/// </summary>
public class LinqToLcsMasterDetailsTest
{
/// <summary>
/// Test LinqProvider for limitations by master details like <see cref="MasterDetailsLimitTest.MasterDetailsLimitationTest"/>.
/// </summary>
[Fact]
public void GetLcsTestAny()
{
object лес1Pk = Guid.NewGuid();

View view = new View();
view.DefineClassType = typeof(Блоха);
view.AddProperty(Information.ExtractPropertyPath<Блоха>(б => б.Кличка));
view.AddProperty(Information.ExtractPropertyPath<Блоха>(б => б.МедведьОбитания));
view.AddProperty(Information.ExtractPropertyPath<Блоха>(б => б.МедведьОбитания.ПорядковыйНомер));

LoadingCustomizationStruct expected = LoadingCustomizationStruct.GetSimpleStruct(typeof(Блоха), view);

// Выберем всех блох, чей медведь живёт в берлоге 1.
DetailVariableDef dvd = new DetailVariableDef();
dvd.ConnectMasterPorp = Information.ExtractPropertyPath<Берлога>(б => б.Медведь);
dvd.OwnerConnectProp = new string[] { Information.ExtractPropertyPath<Блоха>(б => б.МедведьОбитания) };
View viewDetail = new View();
viewDetail.DefineClassType = typeof(Берлога);
viewDetail.AddProperty(Information.ExtractPropertyPath<Берлога>(б => б.Наименование));
viewDetail.AddProperty(Information.ExtractPropertyPath<Берлога>(б => б.Медведь));
viewDetail.AddProperty(Information.ExtractPropertyPath<Берлога>(б => б.ЛесРасположения));

dvd.View = viewDetail;
ExternalLangDef ldef = ExternalLangDef.LanguageDef;
dvd.Type = ldef.DetailsType;
Function detailsLimitName = ldef.GetFunction(ldef.funcEQ, new VariableDef(ldef.StringType, Information.ExtractPropertyPath<Берлога>(б => б.Наименование)), "Берлога 1");
Function detailsLimitForest = ldef.GetFunction(ldef.funcEQ, new VariableDef(ldef.GuidType, Information.ExtractPropertyPath<Берлога>(б => б.ЛесРасположения)), лес1Pk);
Function detailsLimit = ldef.GetFunction(ldef.funcAND, detailsLimitName, detailsLimitForest);
expected.LimitFunction = ldef.GetFunction(ldef.funcExist, dvd, detailsLimit);

var testProvider = new TestLcsQueryProvider<Блоха>();

new Query<Блоха>(testProvider).Where(б => б.МедведьОбитания.Берлога.Cast<Берлога>().Any(бе => бе.Наименование == "Берлога 1" && бе.ЛесРасположения.__PrimaryKey == лес1Pk)).ToList();
Expression queryExpression = testProvider.InnerExpression;

// Act.
LoadingCustomizationStruct actual = LinqToLcs.GetLcs(queryExpression, view, new[] { Медведь.Views.МедведьE });

// Assert.
Assert.Equal(expected.LimitFunction.ToString(), actual.LimitFunction.ToString());

// В сравнении Function DetailVariableDef не учитывается, поэтому проверим руками.
var expectedDvd = (DetailVariableDef)expected.LimitFunction.Parameters[0];
var actualDvd = (DetailVariableDef)actual.LimitFunction.Parameters[0];

Assert.True(Equals(expectedDvd.OwnerConnectProp[0], actualDvd.OwnerConnectProp[0]));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using ICSSoft.STORMNET;
using ICSSoft.STORMNET.Business;
using ICSSoft.STORMNET.FunctionalLanguage;
Expand All @@ -19,8 +17,6 @@
/// </summary>
public class DetailsLoadTest : BaseIntegratedTest
{
private ITestOutputHelper output;

public DetailsLoadTest(ITestOutputHelper output)
: base("DetLoad")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@
</Choose>
<ItemGroup>
<Compile Include="BaseIntegratedTest.cs" />
<Compile Include="ExternalLDef\MasterDetailsLimitTest.cs" />
<Compile Include="ICSSoft.STORMNET.Business.Audit\ConfigHelperTest.cs" />
<Compile Include="ICSSoft.STORMNET.Business.LINQProvider\LinqToLcsMasterDetailsTest.cs" />
<Compile Include="ICSSoft.STORMNET.Business.LINQProvider\TestLinqOperations.cs" />
<Compile Include="ICSSoft.STORMNET.Business\ConfigResolverTest.cs" />
<Compile Include="ICSSoft.STORMNET.Business\DetailsLoadTest.cs" />
Expand All @@ -158,7 +160,6 @@
<Compile Include="ICSSoft.STORMNET.DataObject\OrderPropertyTest.cs" />
<Compile Include="ICSSoft.STORMNET.DataObject\TypeUsageProviderTest.cs" />
<Compile Include="ICSSoft.STORMNET.DataObject\DataObjectCacheTest.cs" />
<Compile Include="ExternalLDef\ExternalLangDefTest.cs" />
<Compile Include="ExternalLDef\RestrictionsOnTheDateAndDetailleTests.cs" />
<Compile Include="ICSSoft.STORMNET.FunctionalLanguage\CompatibilityTypeTestTest.cs" />
<Compile Include="ICSSoft.STORMNET.FunctionalLanguage\Function.cs" />
Expand Down Expand Up @@ -406,4 +407,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,32 @@
using ICSSoft.STORMNET.FunctionalLanguage;
using ICSSoft.STORMNET.FunctionalLanguage.SQLWhere;
using ICSSoft.STORMNET.Windows.Forms;
using Xunit;
using NewPlatform.Flexberry.ORM.Tests;
using Xunit;

/// <summary>
/// Тесты для ExternalLangDef.
/// </summary>

public class ExternalLangDefTest
{
{
/// <summary>
/// Экземпляр ExternalLangDef для тестов.
/// </summary>
private static readonly ExternalLangDef ldef = ExternalLangDef.LanguageDef;
private readonly ExternalLangDef ldef = ExternalLangDef.LanguageDef;

/// <summary>
/// Тест свойства <see cref="ExternalLangDef.paramYearDIFF"/>.
/// </summary>
[Fact]

public void GetparamYearDiffTest()
{
Assert.Equal(ldef.paramYearDIFF, "YearDIFF");
{
Assert.Equal(ldef.paramYearDIFF, "YearDIFF");
}

/// <summary>
/// Тест свойства <see cref="ExternalLangDef.paramMonthDIFF"/>.
/// </summary>
[Fact]

public void GetparamMonthDiffTest()
{
Assert.Equal(ldef.paramMonthDIFF, "MonthDIFF");
Expand All @@ -41,7 +38,6 @@ public void GetparamMonthDiffTest()
/// Тест свойства <see cref="ExternalLangDef.paramWeekDIFF"/>.
/// </summary>
[Fact]

public void GetparamWeekDiffTest()
{
Assert.Equal(ldef.paramWeekDIFF, "WeekDIFF");
Expand All @@ -51,7 +47,6 @@ public void GetparamWeekDiffTest()
/// Тест свойства <see cref="ExternalLangDef.paramQuarterDIFF"/>.
/// </summary>
[Fact]

public void GetparamquarterDiffTest()
{
Assert.Equal(ldef.paramQuarterDIFF, "quarterDIFF");
Expand All @@ -61,7 +56,6 @@ public void GetparamquarterDiffTest()
/// Тест свойства <see cref="ExternalLangDef.paramDayDIFF"/>.
/// </summary>
[Fact]

public void GetparamDayDiffTest()
{
Assert.Equal(ldef.paramDayDIFF, "DayDIFF");
Expand All @@ -71,7 +65,6 @@ public void GetparamDayDiffTest()
/// Тест свойства <see cref="ExternalLangDef.funcMonthPart"/>.
/// </summary>
[Fact]

public void GetfuncMonthPartTest()
{
Assert.Equal(ldef.funcMonthPart, "MonthPart");
Expand All @@ -81,7 +74,6 @@ public void GetfuncMonthPartTest()
/// Тест свойства <see cref="ExternalLangDef.funcHHPart"/>.
/// </summary>
[Fact]

public void GetfuncHhPartTest()
{
Assert.Equal(ldef.funcHHPart, "hhPart");
Expand All @@ -91,7 +83,6 @@ public void GetfuncHhPartTest()
/// Тест свойства <see cref="ExternalLangDef.funcMIPart"/>.
/// </summary>
[Fact]

public void GetfuncMiPartTest()
{
Assert.Equal(ldef.funcMIPart, "miPart");
Expand All @@ -101,7 +92,6 @@ public void GetfuncMiPartTest()
/// Тест свойства <see cref="ExternalLangDef.funcDATEDIFF"/>.
/// </summary>
[Fact]

public void GetfuncDatediffTest()
{
Assert.Equal(ldef.funcDATEDIFF, "DATEDIFF");
Expand All @@ -111,7 +101,6 @@ public void GetfuncDatediffTest()
/// Тест свойства <see cref="ExternalLangDef.funcDayOfWeek"/>.
/// </summary>
[Fact]

public void GetfuncDayOfWeekTest()
{
Assert.Equal(ldef.funcDayOfWeek, "DayOfWeek");
Expand All @@ -121,7 +110,6 @@ public void GetfuncDayOfWeekTest()
/// Тест перегруженного метода <see cref="ExternalLangDef.GetObjectTypeForNetType"/>
/// </summary>
[Fact]

public void GetObjectTypeForNetTypeTest()
{
// Вариент, когда тип - массив детейлов.
Expand All @@ -132,12 +120,12 @@ public void GetObjectTypeForNetTypeTest()
}

#region этот тест лучше отнести к тестам для FunctionalLanguageDef

/// <summary>
/// Тест выпадения NotFoundFunctionParametersException в методе <see cref="ExternalLangDef.GetExistingVariableNames"/>,
/// в том случае, когда при формировании функции берётся неподходящий параметр.
/// </summary>
[Fact]

public void GetExistingVariableNamesNotFoundFunctionParametersExceptionTest()
{
var exception = Record.Exception(() =>
Expand Down
Loading