-
Notifications
You must be signed in to change notification settings - Fork 12
WrongQueryTest added #53
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
Open
TeterinaSvetlana
wants to merge
8
commits into
develop
Choose a base branch
from
feature-wrong-query-test
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
802874f
Test added
TeterinaSvetlana a0cc032
Comments cleared
TeterinaSvetlana 3bb4cb1
Update App.config
572786b
Fix remarks
TeterinaSvetlana 8d8fbb7
Fix remarks
TeterinaSvetlana f18ee91
Fix remarks
TeterinaSvetlana e2874ad
Merge branch 'develop' into feature-wrong-query-test
turbcool 66ea80d
Merge remote-tracking branch 'origin/develop' into feature-wrong-quer…
turbcool File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
NewPlatform.Flexberry.ORM.IntegratedTests/ICSSoft.STORMNET.Business/WrongQueryTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| namespace NewPlatform.Flexberry.ORM.IntegratedTests.Business | ||
| { | ||
| 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; | ||
| using ICSSoft.STORMNET.UserDataTypes; | ||
| using ICSSoft.STORMNET.Windows.Forms; | ||
| using NewPlatform.Flexberry.ORM.Tests; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
| using ICSSoft.STORMNET.Business.LINQProvider; | ||
PashaMasalkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using System.Linq; | ||
|
|
||
| /// <summary> | ||
| /// Тест для проверки ошибки на генерацию невалидного SQL. | ||
| /// </summary> | ||
| public class WrongQueryTest : BaseIntegratedTest | ||
| { | ||
| private ITestOutputHelper output; | ||
|
|
||
| public WrongQueryTest(ITestOutputHelper output) | ||
| : base("DetLoad") | ||
| { | ||
| this.output = output; | ||
| } | ||
|
|
||
| private Random _random = new Random(); | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Метод для организации многопоточности. | ||
| /// </summary> | ||
| [Fact] | ||
| public void ThreadsQueryTest() | ||
| { | ||
| foreach (IDataService dataService in DataServices) | ||
| { | ||
| var ds = (SQLDataService)dataService; | ||
|
|
||
| if (ds is OracleDataService) | ||
| { | ||
| // TODO: Fix multithreading support for OracleDataService and Long names. | ||
| continue; | ||
| } | ||
|
|
||
| ds.OnGenerateSQLSelect -= ThreadTesting_OnGenerateSQLSelect; | ||
| ds.OnGenerateSQLSelect += ThreadTesting_OnGenerateSQLSelect; | ||
| output.WriteLine($"start {ds.GetType().Name}"); | ||
|
|
||
| MultiThreadingTestTool multiThreadingTestTool = new MultiThreadingTestTool(MultiThreadMethod); | ||
| multiThreadingTestTool.StartThreads(150, ds); | ||
|
|
||
| var exception = multiThreadingTestTool.GetExceptions(); | ||
|
|
||
| if (exception != null) | ||
| { | ||
| foreach (var item in exception.InnerExceptions) | ||
| { | ||
| output.WriteLine(item.Value.ToString()); | ||
| } | ||
|
|
||
| throw exception.InnerException; | ||
| } | ||
|
|
||
| ds.OnGenerateSQLSelect -= ThreadTesting_OnGenerateSQLSelect; | ||
|
|
||
| Thread threadCat = new Thread(CatQueue); | ||
| Thread threadPaw = new Thread(BearQueue); | ||
| threadCat.Start(); | ||
| threadPaw.Start(); | ||
| } | ||
| } | ||
|
|
||
| public void CatQueue() | ||
| { | ||
| foreach (IDataService dataService in DataServices) | ||
| { | ||
| var ds = (SQLDataService)dataService; | ||
|
|
||
| // Чтобы объекты в БД точно были, создадим их. | ||
| var createdCat = new Кошка(); | ||
| ds.UpdateObject(createdCat); | ||
|
|
||
| var createdPaw = new Лапа(); | ||
| ds.UpdateObject(createdPaw); | ||
|
|
||
| // Теперь грузим их из БД. | ||
| var кошка = new Кошка(); | ||
bratchikov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| кошка.SetExistObjectPrimaryKey(createdCat.__PrimaryKey); | ||
bratchikov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ds.LoadObject(кошка, false, false); | ||
|
|
||
| var лапа = new Лапа(); | ||
bratchikov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| лапа.SetExistObjectPrimaryKey(createdPaw.__PrimaryKey); | ||
| ds.LoadObject(лапа, false, false); | ||
|
|
||
| Assert.NotNull(кошка); | ||
| Assert.NotNull(лапа); | ||
|
|
||
| кошка = new Кошка() { Кличка = nameof(ThreadsQueryTest), Порода = new Порода() { Название = "Беспородная" }, ДатаРождения = NullableDateTime.Now, Тип = ТипКошки.Дикая }; | ||
| лапа = new Лапа() { Цвет = "red", Номер = 1, ДатаРождения = NullableDateTime.Now, Кошка = кошка }; | ||
| кошка.Лапа.Add(new Лапа() { Номер = 1 }); | ||
| ds.UpdateObject(кошка); | ||
| ds.UpdateObject(лапа); | ||
|
|
||
| var statusNeedSigning = Сторона.Левая; | ||
| var requests = (from x in ds.Query<Лапа>(Лапа.Views.ЛапаFull) | ||
| where x.Сторона == statusNeedSigning && x.Кошка.ДатаРождения == NullableDateTime.Now | ||
| select x).Skip(0).Take(100).ToList(); | ||
| } | ||
| } | ||
|
|
||
| public void BearQueue() | ||
| { | ||
| foreach (IDataService dataService in DataServices) | ||
| { | ||
| var ds = (SQLDataService)dataService; | ||
|
|
||
| // Чтобы объекты в БД точно были, создадим их. | ||
| var createdBear = new Медведь(); | ||
| ds.UpdateObject(createdBear); | ||
|
|
||
| // Теперь грузим их из БД. | ||
| var медведь = new Медведь(); | ||
| медведь.SetExistObjectPrimaryKey(createdBear.__PrimaryKey); | ||
| ds.LoadObject(медведь, false, false); | ||
|
|
||
| Assert.NotNull(медведь); | ||
|
|
||
| медведь = new Медведь() { Пол = Пол.Женский, ДатаРождения = NullableDateTime.Now }; | ||
| ds.UpdateObject(медведь); | ||
|
|
||
| var statusNeedSigning = Пол.Женский; | ||
| var requests = (from x in ds.Query<Медведь>(Медведь.Views.МедведьE) | ||
| where x.Пол == statusNeedSigning && x.ДатаРождения == NullableDateTime.Now | ||
| select x).Skip(0).Take(100).ToList(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Метод для многопоточного исполнения в <see cref="ThreadsQueryTest"/>. | ||
| /// </summary> | ||
| /// <param name="sender">Словарь со значениями параметров для исполнения метода.</param> | ||
| public void MultiThreadMethod(object sender) | ||
| { | ||
| var parametersDictionary = sender as Dictionary<string, object>; | ||
| IDataService ds = parametersDictionary[MultiThreadingTestTool.ParamNameSender] as SQLDataService; | ||
| Dictionary<string, Exception> exceptions = parametersDictionary[MultiThreadingTestTool.ParamNameExceptions] as Dictionary<string, Exception>; | ||
|
|
||
| ExternalLangDef langdef = ExternalLangDef.LanguageDef; | ||
| langdef.DataService = ds; | ||
|
|
||
| // Use a custom number of iterations: less time and false positives or more time and a guaranteed result. | ||
| for (int i = 0; i < 5; i++) | ||
| { | ||
| if (!(bool)parametersDictionary[MultiThreadingTestTool.ParamNameWorking]) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| // Arrange. | ||
| LoadingCustomizationStruct lcs = LoadingCustomizationStruct.GetSimpleStruct(typeof(Кошка), Кошка.Views.k_КошкаE); | ||
| lcs.ReturnTop = 1; | ||
| lcs.LimitFunction = langdef.GetFunction(langdef.funcLike, new VariableDef(langdef.StringType, Information.ExtractPropertyName<Кошка>(к => к.Кличка)), nameof(ThreadsQueryTest)); | ||
|
|
||
| // Act & Assert. | ||
| DataObject[] dObjs = ds.LoadObjects(lcs); | ||
| Information.ClearCacheGetView(); | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| exceptions.Add(Thread.CurrentThread.Name, exception); | ||
| parametersDictionary[MultiThreadingTestTool.ParamNameWorking] = false; | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Обработчик события генерации SQL-запроса с отловом неправильно сформированного представления. | ||
| /// </summary> | ||
| /// <param name="sender">Инициатор события.</param> | ||
| /// <param name="e">Аргументы события.</param> | ||
| private void ThreadTesting_OnGenerateSQLSelect(object sender, GenerateSQLSelectQueryEventArgs e) | ||
| { | ||
| View view = e.CustomizationStruct.View; | ||
| for (int i = 0; i < view.Properties.Length; i++) | ||
| { | ||
| PropertyInView property = view.Properties[i]; | ||
| for (int j = i + 1; j < view.Properties.Length; j++) | ||
| { | ||
| PropertyInView nextProperty = view.Properties[j]; | ||
| if (property.Name == nextProperty.Name) | ||
| { | ||
| throw new Exception($"Свойство {property.Name} встречается несколько раз (OnGenerateSQLSelect)."); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.