// OneScript: ./OInt/tests/Modules/internal/Modules/os

// MIT License

// Copyright (c) 2023-2026 Anton Tsitavets

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// https://github.com/Bayselonarrend/OpenIntegrations

// BSLLS:LatinAndCyrillicSymbolInWord-off
// BSLLS:IncorrectLineBreak-off
// BSLLS:UsingHardcodePath-off
// BSLLS:Typo-off
// BSLLS:DeprecatedMessage-off
// BSLLS:UsingServiceTag-off
// BSLLS:ExecuteExternalCodeInCommonModule-off
// BSLLS:DuplicateStringLiteral-off
// BSLLS:MagicNumber-off
// BSLLS:UsingHardcodeNetworkAddress-off
// BSLLS:UsingSynchronousCalls-off
// BSLLS:UnusedLocalMethod-off
// BSLLS:MissingTemporaryFileDeletion-off
// BSLLS:MethodSize-off
// BSLLS:IfElseIfEndsWithElse-off
// BSLLS:CognitiveComplexity-off
// BSLLS:NumberOfOptionalParams-off
// BSLLS:CommentedCode-off
// BSLLS:CyclomaticComplexity-off
// BSLLS:LineLength-off
// BSLLS:NestedStatements-off
// BSLLS:IfElseDuplicatedCodeBlock-off

//@skip-check use-non-recommended-method
//@skip-check module-structure-top-region
//@skip-check module-structure-method-in-regions
//@skip-check undefined-function-or-procedure
//@skip-check wrong-string-literal-content
//@skip-check module-unused-method
//@skip-check missing-temporary-file-deletion
//@skip-check method-too-many-params
//@skip-check bsl-legacy-check-for-each-statetement-collection
//@skip-check bsl-legacy-check-string-literal
//@skip-check bsl-legacy-check-expression-type
//@skip-check undefined-variable

#Use "../../../../tools/main"
#Use "../../../../tools/http"
#Use "../../../../api/openai"
#Use "../../../../api/rportal"
#Use asserts


#Region Internal

Function ExecuteTestCLI(Val Library, Val Method, Val Options, Val Record = True) Export

    If OPI_Tools.IsWindows() Then
        Oint = """C:\Program Files (x86)\OInt\bin\oint.bat""";
    Else
        Oint = "oint";
    EndIf;

    ResultFile = GetTempFileName();

    LaunchString = Oint + " " + Library + " " + Method;
    AddOptions = New Structure;
    WriteOptions = New Structure;

    For Each Option In Options Do

        If Option.Value = Undefined Or String(Option.Value) = "" Then
            Continue;
        EndIf;

        CurrentValue = GetCLIFormedValue(Option.Value, , AddOptions);

        LaunchString = LaunchString + " --" + Option.Key + " " + CurrentValue;

        WriteOptions.Insert(Option.Key, CurrentValue);

    EndDo;

    For Each AddOption In AddOptions Do

        CurrentValue = GetCLIFormedValue(AddOption.Value);

        LaunchString = LaunchString + " --" + AddOption.Key + " " + CurrentValue;

        WriteOptions.Insert(AddOption.Key, CurrentValue);

    EndDo;

    // BSLLS:ExternalAppStarting-off
    RunApp(LaunchString + " --out """ + ResultFile + """ --debug", , True);
    // BSLLS:ExternalAppStarting-on

    Result = ReadCLIResponse(ResultFile);

    If Record Then
        WriteCLICall(Library, Method, WriteOptions);
    EndIf;

    OPI_Tools.RemoveFileWithTry(ResultFile, "Failed to delete the temporary file after the test!!");

    Return Result;

EndFunction

Function GetTestingSectionMapping() Export

    Sections = New Structure;
    Sections.Insert("Core" , 1);
    Sections.Insert("Telegram" , 5);
    Sections.Insert("VK" , 5);
    Sections.Insert("Viber" , 5);
    Sections.Insert("FTP" , 5);
    Sections.Insert("SSH" , 5);
    Sections.Insert("SFTP" , 5);
    Sections.Insert("PostgreSQL" , 5);
    Sections.Insert("MySQL" , 5);
    Sections.Insert("MSSQL" , 5);
    Sections.Insert("SQLite" , 5);
    Sections.Insert("MongoDB" , 5);
    Sections.Insert("RCON" , 5);
    Sections.Insert("YandexDisk" , 5);
    Sections.Insert("GoogleWorkspace", 2);
    Sections.Insert("GoogleCalendar" , 5);
    Sections.Insert("GoogleDrive" , 5);
    Sections.Insert("GoogleSheets" , 5);
    Sections.Insert("Notion" , 5);
    Sections.Insert("Slack" , 5);
    Sections.Insert("Airtable" , 5);
    Sections.Insert("Dropbox" , 5);
    Sections.Insert("Bitrix24" , 5);
    Sections.Insert("VKTeams" , 5);
    Sections.Insert("Neocities" , 5);
    Sections.Insert("CDEK" , 5);
    Sections.Insert("YandexMetrika" , 5);
    Sections.Insert("S3" , 5);
    Sections.Insert("TCP" , 5);
    Sections.Insert("WebSocket" , 5);
    Sections.Insert("ZeroMQ" , 5);
    Sections.Insert("GreenAPI" , 5);
    Sections.Insert("GreenMax" , 5);
    Sections.Insert("Ollama" , 5);
    Sections.Insert("HTTP" , 5);
    Sections.Insert("OpenAI" , 5);
    Sections.Insert("ReportPortal" , 5);
    Sections.Insert("GRPC" , 5);
    Sections.Insert("ClickHouse" , 5);
    Sections.Insert("RSS" , 5);
    Sections.Insert("MessagePack" , 5);
    Sections.Insert("Janx" , 5);
    Sections.Insert("Lua" , 5);

    Return Sections;

EndFunction

Function GetTestTable(Val TestModule = "") Export

    Telegram = "Telegram";
    VKontakte = "VK";
    YDisk = "YandexDisk";
    Calendar = "GoogleCalendar";
    Viber = "Viber";
    Drive = "GoogleDrive";
    VSpace = "GoogleWorkspace";
    Notion = "Notion";
    Slack = "Slack";
    Tables = "GoogleSheets";
    AirT = "Airtable";
    Dropbox = "Dropbox";
    Bitrix = "Bitrix24";
    VKT = "VKTeams";
    Neocities = "Neocities";
    Cdek = "CDEK";
    Metrika = "YandexMetrika";
    S3_ = "S3";
    TCP = "TCP";
    WebSocket = "WebSocket";
    SQLite = "SQLite";
    Postgres = "PostgreSQL";
    MongoDB = "MongoDB";
    GreenAPI = "GreenAPI";
    RCON = "RCON";
    MySQL = "MySQL";
    Ollama = "Ollama";
    Http = "HTTP";
    OpenAI = "OpenAI";
    MSSQL = "MSSQL";
    FTP = "FTP";
    RPortal = "ReportPortal";
    SSH = "SSH";
    SFTP = "SFTP";
    GreenMax = "GreenMax";
    GRPC = "GRPC";
    CHouse = "ClickHouse";
    RSS = "RSS";
    ZMQ = "ZeroMQ";
    MsgPack = "MessagePack";
    Janx = "Janx";
    Lua = "Lua";

    ArrayOfTests = New Array;

    NewTest(ArrayOfTests, TestModule, "CheckIBToLastBuildCompliance", "Check IB to last build compliance", "Core");
    NewTest(ArrayOfTests, TestModule, "ValidateAdvancedCall" , "Validate advanced call" , "Core");

    NewTest(ArrayOfTests, TestModule, "TelegramAPI_GetBotInfo" , "Get bot information" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_GetUpdates" , "Get updates" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SetWebhook" , "Set Webhook" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendTextMessage" , "Send text message" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendImage" , "Send image" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendVideo" , "Send video" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendAudio" , "Send audio" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendDocument" , "Send document" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendGIF" , "Send GIF" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendMediaGroup" , "Send mediagroup" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendLocation" , "Send location" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendContact" , "Send contact" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_SendPoll" , "Send poll" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_ForwardMessage" , "Forward message" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_BanUnban" , "Ban/Unban" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_CreateInvitationLink" , "Create invitation link" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_PinUnpinMessage" , "Pin/Unpin message" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_GetMemberCount" , "Get participant count" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_GetForumAvatarsList", "Get forum avatars list", Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_CreateDeleteForumTopic" , "Create/Delete forum topic" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_ChangeMainTopicName" , "Change main topic name" , Telegram);
    NewTest(ArrayOfTests, TestModule, "TelegramAPI_HideShowMainTopic" , "Hide/Show main topic" , Telegram);
    NewTest(ArrayOfTests, TestModule, "VKAPI_CreateTokenLink" , "Create token retrieval link", VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_CreateDeletePost" , "Create/Delete post" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_CreateCompositePost" , "Create/Delete composite post" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_CreatePoll" , "Create poll" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_SaveDeleteImage" , "Add/Delete image" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_CreateStory" , "Create story" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_LikeRepostComment" , "Like/Repost/Comment" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_GetStatistics" , "Get statistics" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_GetPostStatistics" , "Get post statistics" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_CreateAdCampaign" , "Create advertising campaign" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_SendMessage" , "Send message" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_GetProductCategories" , "Get product categories" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_CreateProductSelection" , "Create product and selection" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_CreateProductWithProperties" , "Create product with properties" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_GetProductList" , "Get product list" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_GetSelectionList" , "Get selection list" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_GetPropertyList" , "Get property list" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_GetOrderList" , "Get order list" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "VKAPI_UploadVideo" , "Upload video" , VKontakte);
    NewTest(ArrayOfTests, TestModule, "YDisk_Authorization" , "Authorization" , YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_GetDiskInfo" , "Get disk information" , YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_CreateFolder" , "Create folder" , YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_UploadByUrlAndGetObject", "Upload by URL and get" , YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_UploadDeleteFile" , "Upload/Delete file" , YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_CreateObjectCopy" , "Create object copy" , YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_GetDownloadLink" , "Get download link" , YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_GetFileList" , "Get list of files" , YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_MoveObject" , "Move object" , YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_PublicObjectActions" , "Actions with public objects", YDisk);
    NewTest(ArrayOfTests, TestModule, "YDisk_GetPublishedList" , "Get published list" , YDisk);
    NewTest(ArrayOfTests, TestModule, "GW_Auth" , "Authorization" , VSpace);
    NewTest(ArrayOfTests, TestModule, "GC_Authorization" , "Authorization" , Calendar);
    NewTest(ArrayOfTests, TestModule, "GC_GetCalendarList" , "Get list of calendars" , Calendar);
    NewTest(ArrayOfTests, TestModule, "GC_CreateDeleteCalendar" , "Create/Delete calendar" , Calendar);
    NewTest(ArrayOfTests, TestModule, "GC_CreateDeleteEvent" , "Create/Delete event" , Calendar);
    NewTest(ArrayOfTests, TestModule, "GD_Authorization" , "Authorization" , Drive);
    NewTest(ArrayOfTests, TestModule, "GD_GetCatalogList" , "Get list of directories" , Drive);
    NewTest(ArrayOfTests, TestModule, "GD_UploadDeleteFile" , "Upload/Delete file" , Drive);
    NewTest(ArrayOfTests, TestModule, "GD_CreateDeleteComment" , "Create/Delete Comment" , Drive);
    NewTest(ArrayOfTests, TestModule, "GD_CreateCatalog" , "Create/Delete catalog" , Drive);
    NewTest(ArrayOfTests, TestModule, "GT_Authorization" , "Authorization" , Tables);
    NewTest(ArrayOfTests, TestModule, "GT_CreateTable" , "Create table" , Tables);
    NewTest(ArrayOfTests, TestModule, "GT_FillClearCells" , "Fill/Clear cells" , Tables);
    NewTest(ArrayOfTests, TestModule, "Viber_DataRetrieval" , "Data retrieval" , Viber);
    NewTest(ArrayOfTests, TestModule, "Viber_MessagesSending" , "Messages sending" , Viber);
    NewTest(ArrayOfTests, TestModule, "NotionAPI_CreatePage" , "Create page" , Notion);
    NewTest(ArrayOfTests, TestModule, "NotionAPI_CreateUpdateBase" , "Create/Edit database" , Notion);
    NewTest(ArrayOfTests, TestModule, "NotionAPI_CreateDeleteBlock" , "Create/Delete block" , Notion);
    NewTest(ArrayOfTests, TestModule, "NotionAPI_GetUsers" , "Get users" , Notion);
    NewTest(ArrayOfTests, TestModule, "SlackGetData" , "Get data" , Slack);
    NewTest(ArrayOfTests, TestModule, "Slack_SendDeleteMessage" , "Send/Delete message" , Slack);
    NewTest(ArrayOfTests, TestModule, "Slack_CreateArchiveChannel" , "Create/Archive channel" , Slack);
    NewTest(ArrayOfTests, TestModule, "Slack_OpenCloseDialog" , "Open/Close dialog" , Slack);
    NewTest(ArrayOfTests, TestModule, "Slack_UploadDeleteFile" , "Upload/Delete file" , Slack);
    NewTest(ArrayOfTests, TestModule, "Slack_UploadDeleteExternalFile" , "Upload/Delete external file" , Slack);
    NewTest(ArrayOfTests, TestModule, "AT_CreateDatabase" , "Create/Edit database" , AirT);
    NewTest(ArrayOfTests, TestModule, "AT_CreateTable" , "Create/Edit table" , AirT);
    NewTest(ArrayOfTests, TestModule, "AT_CreateField" , "Create/Edit field" , AirT);
    NewTest(ArrayOfTests, TestModule, "AT_CreateDeleteRecords" , "Create/Delete records" , AirT);
    NewTest(ArrayOfTests, TestModule, "DropboxAPI_GetUpdateToken" , "Get/Update token" , Dropbox);
    NewTest(ArrayOfTests, TestModule, "DropboxAPI_UploadFile" , "Upload file" , Dropbox);
    NewTest(ArrayOfTests, TestModule, "DropboxAPI_UploadFileByURL" , "Upload file by URL" , Dropbox);
    NewTest(ArrayOfTests, TestModule, "DropboxAPI_CreateFolder" , "Create folder" , Dropbox);
    NewTest(ArrayOfTests, TestModule, "DropboxAPI_CreateDeleteTag" , "Create/Delete tag" , Dropbox);
    NewTest(ArrayOfTests, TestModule, "DropboxAPI_GetAccount" , "Get account data" , Dropbox);
    NewTest(ArrayOfTests, TestModule, "DropboxAPI_AccessManagement" , "Access management" , Dropbox);
    NewTest(ArrayOfTests, TestModule, "DropboxAPI_GetFolderFileList" , "Get list of folder files" , Dropbox);
    NewTest(ArrayOfTests, TestModule, "B24_TokenManagement" , "Token management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_ServerTime" , "Server time" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_PostsManagement" , "Posts management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_TaskManagement" , "Tasks management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_CommentsManagement" , "Comments management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_WorkingWithDrive" , "Working with drive" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_Kanban" , "Kanban" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_Timekeeping" , "Timekeeping" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_ChatManagement" , "Chats works" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_NotificationsManagement" , "Notifications management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_TasksFieldsManagement" , "Working with custom task fields" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_DepartmentsManagement" , "Departments management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B2_UsersManagement" , "Users management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_LeadsManagement" , "Leads management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_DealsManagement" , "Deals management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "B24_CalendarsManagement" , "Calendars management" , Bitrix);
    NewTest(ArrayOfTests, TestModule, "VKT_MessagesSending" , "Messages sending" , VKT);
    NewTest(ArrayOfTests, TestModule, "VKT_CommonMethods" , "Common methods" , VKT);
    NewTest(ArrayOfTests, TestModule, "VKT_ChatManagement" , "Chat management" , VKT);
    NewTest(ArrayOfTests, TestModule, "NC_FilesManagement" , "Files management" , Neocities);
    NewTest(ArrayOfTests, TestModule, "NC_DataRetrieving" , "Data retrieving" , Neocities);
    NewTest(ArrayOfTests, TestModule, "CdekAPI_CommonMethods" , "Common methods" , Cdek);
    NewTest(ArrayOfTests, TestModule, "CDEKAPI_OrdersManagement" , "Orders management" , Cdek);
    NewTest(ArrayOfTests, TestModule, "CdekAPI_CourierInvitationsManagement", "Courier invitations management" , Cdek);
    NewTest(ArrayOfTests, TestModule, "YaMetrika_TagsManagement" , "Tags management" , Metrika);
    NewTest(ArrayOfTests, TestModule, "YaMetrika_CountersManagement" , "Counters management" , Metrika);
    NewTest(ArrayOfTests, TestModule, "YaMetrika_ActionsManagement" , "Actions management" , Metrika);
    NewTest(ArrayOfTests, TestModule, "AWS_CommonMethods" , "Common methods" , S3_);
    NewTest(ArrayOfTests, TestModule, "AWS_BucketsManagement" , "Buckets management" , S3_);
    NewTest(ArrayOfTests, TestModule, "AWS_ObjectsManagement" , "Objects management" , S3_);
    NewTest(ArrayOfTests, TestModule, "TC_Client" , "TCP Client" , TCP);
    NewTest(ArrayOfTests, TestModule, "WS_Client" , "WebSocket Client" , WebSocket);
    NewTest(ArrayOfTests, TestModule, "WS_Server" , "WebSocket Server" , WebSocket);
    NewTest(ArrayOfTests, TestModule, "WS_ExtendedCheck" , "Extended check" , WebSocket);
    NewTest(ArrayOfTests, TestModule, "ZMQ_Common" , "Common" , ZMQ);
    NewTest(ArrayOfTests, TestModule, "ZMQ_ConnectionMethods" , "Connection" , ZMQ);
    NewTest(ArrayOfTests, TestModule, "ZMQ_ListeningMethods" , "Listening" , ZMQ);
    NewTest(ArrayOfTests, TestModule, "ZMQ_InteractionMethods" , "Interaction" , ZMQ);
    NewTest(ArrayOfTests, TestModule, "ZMQ_ExtendedCheck" , "Extended check" , ZMQ);
    NewTest(ArrayOfTests, TestModule, "TC_Server" , "TCP Host" , TCP);
    NewTest(ArrayOfTests, TestModule, "TC_ExtendedCheck" , "Extended check" , TCP);
    NewTest(ArrayOfTests, TestModule, "SQLL_CommonMethods" , "Common methods" , SQLite);
    NewTest(ArrayOfTests, TestModule, "SQLL_ExtendedCheck" , "Extended check" , SQLite);
    NewTest(ArrayOfTests, TestModule, "SQLL_ORM" , "ORM" , SQLite);
    NewTest(ArrayOfTests, TestModule, "Postgres_CommonMethods" , "Common methods" , Postgres);
    NewTest(ArrayOfTests, TestModule, "Postgres_ExtendedCheck" , "Extended check" , Postgres);
    NewTest(ArrayOfTests, TestModule, "Postgres_ORM" , "ORM" , Postgres);
    NewTest(ArrayOfTests, TestModule, "MYS_CommonMethods" , "Common methods" , MySQL);
    NewTest(ArrayOfTests, TestModule, "MYS_ExtendedCheck" , "Extended check" , MySQL);
    NewTest(ArrayOfTests, TestModule, "MYS_ORM" , "ORM" , MySQL);
    NewTest(ArrayOfTests, TestModule, "MSS_CommonMethods" , "Common methods" , MSSQL);
    NewTest(ArrayOfTests, TestModule, "MSS_ExtendedCheck" , "Extended check" , MSSQL);
    NewTest(ArrayOfTests, TestModule, "MSS_ORM" , "ORM" , MSSQL);
    NewTest(ArrayOfTests, TestModule, "Mongo_CommonMethods" , "Common methods" , MongoDB);
    NewTest(ArrayOfTests, TestModule, "Mongo_ExtendedCheck" , "Extended check" , MongoDB);
    NewTest(ArrayOfTests, TestModule, "Mong_DatabaseManagement" , "Database management" , MongoDB);
    NewTest(ArrayOfTests, TestModule, "Mongo_CollectionManagement" , "Collections management" , MongoDB);
    NewTest(ArrayOfTests, TestModule, "Mongo_DocumentsManagement" , "DocumentsManagement" , MongoDB);
    NewTest(ArrayOfTests, TestModule, "Mongo_UserManagement" , "Users management" , MongoDB);
    NewTest(ArrayOfTests, TestModule, "Mongo_RoleManagement" , "Role management" , MongoDB);
    NewTest(ArrayOfTests, TestModule, "GAPI_GroupManagement" , "Group management" , GreenAPI);
    NewTest(ArrayOfTests, TestModule, "GAPI_MessageSending" , "Messages sending" , GreenAPI);
    NewTest(ArrayOfTests, TestModule, "GAPI_NotificationsReceiving" , "Notifications receiving" , GreenAPI);
    NewTest(ArrayOfTests, TestModule, "GAPI_MessageQueue" , "Message queue" , GreenAPI);
    NewTest(ArrayOfTests, TestModule, "GAPI_MessageLogs" , "Message logs" , GreenAPI);
    NewTest(ArrayOfTests, TestModule, "GAPI_Account" , "Account" , GreenAPI);
    NewTest(ArrayOfTests, TestModule, "GMax_GroupManagement" , "Group management" , GreenMax);
    NewTest(ArrayOfTests, TestModule, "GMax_MessageSending" , "Messages sending" , GreenMax);
    NewTest(ArrayOfTests, TestModule, "GMax_Notifications" , "Notifications" , GreenMax);
    NewTest(ArrayOfTests, TestModule, "GMax_MessageHistory" , "Message history" , GreenMax);
    NewTest(ArrayOfTests, TestModule, "GMax_Queues" , "Queues" , GreenMax);
    NewTest(ArrayOfTests, TestModule, "GMax_Account" , "Account" , GreenMax);
    NewTest(ArrayOfTests, TestModule, "RC_CommandsExecution" , "Commands execution" , RCON);
    NewTest(ArrayOfTests, TestModule, "RC_ExtendedCheck" , "Extended check" , RCON);
    NewTest(ArrayOfTests, TestModule, "OLLM_RequestsProcessing" , "Requests processing" , Ollama);
    NewTest(ArrayOfTests, TestModule, "OLLM_ModelsManagement" , "Models management" , Ollama);
    NewTest(ArrayOfTests, TestModule, "OLLM_WorkingWithBlob" , "Working with Blob" , Ollama);
    NewTest(ArrayOfTests, TestModule, "HTTP_Initialization" , "Initialization" , Http);
    NewTest(ArrayOfTests, TestModule, "HTTP_BodySet" , "Body set" , Http);
    NewTest(ArrayOfTests, TestModule, "HTTP_Settings" , "Settings" , Http);
    NewTest(ArrayOfTests, TestModule, "HTTP_HeadersSetting" , "Headers setting" , Http);
    NewTest(ArrayOfTests, TestModule, "HTTP_Authorization" , "Authorization" , Http);
    NewTest(ArrayOfTests, TestModule, "HTTP_RequestProcessing" , "Request processing" , Http);
    NewTest(ArrayOfTests, TestModule, "HTTP_ResponseReceiving" , "Response receiving" , Http);
    NewTest(ArrayOfTests, TestModule, "OAI_RequestsProcessing" , "Requests processing" , OpenAI);
    NewTest(ArrayOfTests, TestModule, "OAI_Assistants" , "Assistants" , OpenAI);
    NewTest(ArrayOfTests, TestModule, "OAI_FileManagement" , "Files management" , OpenAI);
    NewTest(ArrayOfTests, TestModule, "OAI_AudioProcessing" , "Audio processing" , OpenAI);
    NewTest(ArrayOfTests, TestModule, "OAI_ModelsManagement" , "Models management" , OpenAI);
    NewTest(ArrayOfTests, TestModule, "FT_DirecotryManagement" , "Directory management" , FTP);
    NewTest(ArrayOfTests, TestModule, "FT_FileOperations" , "Files management" , FTP);
    NewTest(ArrayOfTests, TestModule, "FT_CommonMethods" , "Common methods" , FTP);
    NewTest(ArrayOfTests, TestModule, "FT_ExtendedCheck" , "Extended check" , FTP);
    NewTest(ArrayOfTests, TestModule, "RPortal_Authorization" , "Authorization" , RPortal);
    NewTest(ArrayOfTests, TestModule, "RPortal_TestManagement" , "Test management" , RPortal);
    NewTest(ArrayOfTests, TestModule, "RPortal_LogRecording" , "Log recording" , RPortal);
    NewTest(ArrayOfTests, TestModule, "RPortal_ProjectManagement" , "Project management" , RPortal);
    NewTest(ArrayOfTests, TestModule, "RPortal_UserManagement" , "Users management" , RPortal);
    NewTest(ArrayOfTests, TestModule, "SShell_CommonMethods" , "Common methods" , SSH);
    NewTest(ArrayOfTests, TestModule, "SShell_ExtendedCheck" , "Extended check" , SSH);
    NewTest(ArrayOfTests, TestModule, "SF_CommonMethods" , "Common methods" , SFTP);
    NewTest(ArrayOfTests, TestModule, "SF_DirectoryManagement" , "Directory management" , SFTP);
    NewTest(ArrayOfTests, TestModule, "SF_FileManagement" , "Files management" , SFTP);
    NewTest(ArrayOfTests, TestModule, "SF_ExtendedCheck" , "Extended check" , SFTP);
    NewTest(ArrayOfTests, TestModule, "GR_CommonMethods" , "Common methods" , GRPC);
    NewTest(ArrayOfTests, TestModule, "GR_ExtendedCheck" , "Extended check" , GRPC);
    NewTest(ArrayOfTests, TestModule, "GR_Introspection" , "Introspection" , GRPC);
    NewTest(ArrayOfTests, TestModule, "GR_Streaming" , "Streaming" , GRPC);
    NewTest(ArrayOfTests, TestModule, "CH_CommonMethods" , "Common methods" , CHouse);
    NewTest(ArrayOfTests, TestModule, "CH_GRPC" , "GRPC" , CHouse);
    NewTest(ArrayOfTests, TestModule, "RSS_RSSMethods" , "RSS methods" , RSS);
    NewTest(ArrayOfTests, TestModule, "RSS_AtomMethods" , "Atom methods" , RSS);
    NewTest(ArrayOfTests, TestModule, "MP_Data" , "Data" , MsgPack);
    NewTest(ArrayOfTests, TestModule, "MP_Benchmark" , "Benchmark" , MsgPack);
    NewTest(ArrayOfTests, TestModule, "MP_Compatibility" , "Reference compatibility" , MsgPack);
    NewTest(ArrayOfTests, TestModule, "Jnx_Data" , "Data" , Janx);
    NewTest(ArrayOfTests, TestModule, "Jnx_ExtendedDataCheck" , "Extended data check" , Janx);
    NewTest(ArrayOfTests, TestModule, "Jnx_Benchmark" , "Benchmark" , Janx);
    NewTest(ArrayOfTests, TestModule, "Lua_CommonMethods" , "Common methods" , Lua);
    NewTest(ArrayOfTests, TestModule, "Lua_WorkingWithScripts" , "Script management" , Lua);
    NewTest(ArrayOfTests, TestModule, "Lua_BytecodeManagement" , "Bytecode management" , Lua);
    NewTest(ArrayOfTests, TestModule, "Lua_ExtendedCheck" , "Extended check" , Lua);

    Return ArrayOfTests;

EndFunction

Function ExpectsThat(Value) Export

    Try

        Module = GetCommonModule("ЮТест");
        Ожидаем = TypeOf(Module) = Type("CommonModule");
        Return Module.ОжидаетЧто(Value);

    Except
        Return Ожидаем.Что(Value);
    EndTry;

EndFunction

Function FormYAXTests(Val TestModule) Export

    Module = GetCommonModule("ЮТТесты");
    TestTable = GetTestTable(TestModule);

    Set = Module.ДобавитьТестовыйНабор(TestModule);

    For Each Test In TestTable Do
        Set.ДобавитьКлиентскийТест(Test.Method, Test.Synonym);
        Set.ДобавитьСерверныйТест(Test.Method, Test.Synonym);
    EndDo;

    Return "";

EndFunction

Function FormYAXTestsCLI(Val TestModule = "") Export

    Module = GetCommonModule("ЮТТесты");
    TestTable = GetTestTable(TestModule);

    Set = Module.ДобавитьТестовыйНабор(TestModule + " (CLI)");

    For Each Test In TestTable Do
        Set.AddTest(Test.Method, Test.Synonym);
    EndDo;

    Return "";

EndFunction

Function FormAssertsTests(Val TestModule = "") Export

    TestTable = GetTestTable(TestModule);
    ArrayOfTests = New Array;

    For Each Test In TestTable Do
        ArrayOfTests.Add(Test.Method);
    EndDo;

    Return ArrayOfTests;

EndFunction

Function FormAssertsTestsCLI(Val TestModule = "") Export

    Return FormAssertsTests(TestModule);

EndFunction

Function GetParameter(Parameter) Export

    Path = DataFilePath();
    Return GetValueFromFile(Parameter, Path);

EndFunction

Function GetBinary(Parameter) Export

    Path = DataFilePath();
    Value = GetValueFromFile(Parameter, Path);

    If TypeOf(Value) = Type("String") Then

        Value = GetFilePath(Value);

    EndIf;

    Return Value;

EndFunction

Function GetFilePath(Val Path) Export

    If StrFind(Path, "http") > 0 Or StrFind(Path, "www") > 0 Then

        TFN = GetTempFileName();
        FileCopy(Path, TFN);
        Path = TFN;
        Binary = New BinaryData(Path);

        OPI_Tools.RemoveFileWithTry(TFN, "Failed to delete the temporary file after the test!!");

    Else

        Binary = New BinaryData(Path);

    EndIf;

    Return Binary;

EndFunction

Function GetLocalhost() Export

    If OPI_Tools.IsWindows() Then
        Result = "127.0.0.1";
    Else
        Result = "host.docker.internal";
    EndIf;

    Return Result;

EndFunction

Function IsCLITest() Export

    Try

        Data = GetEnvironmentVariable("OINT_TESTS_CLI");


    Except
        Return False;
    EndTry;

    If String(Data) = "1" Then
        Result = True;
    Else
        Result = False;
    EndIf;

    Return Result;

EndFunction

Procedure ParameterToCollection(Parameter, Collection) Export

    Value = GetParameter(Parameter);
    Collection.Insert(Parameter, Value);

EndProcedure

Procedure BinaryToCollection(Parameter, Collection) Export

    Value = GetBinary(Parameter);
    Collection.Insert(Parameter, Value);

EndProcedure

Procedure WriteParameter(Parameter, Value) Export

    Path = DataFilePath();
    WriteParameterToFile(Parameter, Value, Path);

EndProcedure

//@skip-check method-too-many-params

Procedure Process(Val Result
    , Val Library
    , Val Method
    , Val Option = ""
    , AddParam1 = Undefined
    , AddParam2 = Undefined
    , AddParam3 = Undefined) Export

    SetCLITestFlag(False);

    ProcessTestingResult(Result
        , Method
        , Library
        , Option
        , AddParam1
        , AddParam2
        , AddParam3);

EndProcedure

Procedure ProcessCLI(Val Result
    , Val Library
    , Val Method
    , Val Option = ""
    , AddParam1 = Undefined
    , AddParam2 = Undefined
    , AddParam3 = Undefined) Export

    SetCLITestFlag(True);

    ProcessTestingResult(Result
        , Method
        , Library
        , Option
        , AddParam1
        , AddParam2
        , AddParam3);

EndProcedure

Procedure SetCLITestFlag(Val Value) Export

    CLITestsMark = ?(Value, 1, 0);

    //@skip-check empty-except-statement
    Try

        SetEnvironmentVariable("OINT_TESTS_CLI", CLITestsMark);

    Except EndTry;

EndProcedure

Procedure LogServiceInformation(Val Text, Val Note, Val Library) Export

    TextTemplate = "
                   |--!!!---------%1----------!!!--
                   |
                   |%2
                   |
                   |%3
                   |
                   |---------------------------------";

    Message(StrTemplate(TextTemplate, Library, Note, Text));

EndProcedure

#Region ReportPortal

Function CreateReportPortalLaunch(Val Platform = "") Export

    Token = GetParameter("RPortal_Token");
    Project = GetParameter("RPortal_MainProject");
    URL = GetParameter("RPortal_URL");

    FinishLaunch();

    CurrentDate = GetLaunchTime();
    SystemInfo = New SystemInfo;

    OperatingSystem = String(SystemInfo.PlatformType);
    CurrentDateString = Format(CurrentDate, "DF=yyyy-MM-dd");
    UUID = String(New UUID);
    OPIVersion = OPI_Tools.OPIVersion();

    If Not ValueIsFilled(Platform) Then
        Platform = ?(OPI_Tools.IsOneScript(), "OneScript", "1C:Enterprise");
    EndIf;

    LaunchName = StrTemplate("%1 | %2 | %3 | %4", CurrentDateString, OPIVersion, Platform, OperatingSystem);

    LaunchStructure = New Structure;

    LaunchStructure.Insert("name" , LaunchName);
    LaunchStructure.Insert("startTime", CurrentDate);
    LaunchStructure.Insert("uuid" , UUID);

    WriteParameter("RPortal_MainLaunch", UUID);

    Result = ReportPortal().CreateLaunch(URL, Token, Project, LaunchStructure);
    UID = Result["id"];

    CreateLaunchFile(UID);

    Message(OPI_Tools.JSONString(Result));

    Return UID;

EndFunction

Function CreateLaunchSet(Val Name) Export

    Data = GetExistingLaunch();

    If Data = Undefined Then
        Return Undefined;
    EndIf;

    ExistingSets = Data["suites"];
    Existing = ExistingSets.Get(Name);

    If Existing <> Undefined Then
        Return Existing;
    EndIf;

    Token = GetParameter("RPortal_Token");
    Project = GetParameter("RPortal_MainProject");
    URL = GetParameter("RPortal_URL");

    CurrentDate = GetLaunchTime();
    LastSet = Data["last_suite"];

    If ValueIsFilled(LastSet) Then

        FinishStructure = New Structure("endTime,launchUuid", CurrentDate, LastSet);
        ReportPortal().FinishItem(URL, Token, Project, LastSet, FinishStructure);

    EndIf;

    UUID = String(New UUID);

    ElementStructure = New Structure;
    ElementStructure.Insert("name" , Name);
    ElementStructure.Insert("startTime" , CurrentDate);
    ElementStructure.Insert("type" , "suite");
    ElementStructure.Insert("launchUuid", Data["id"]);
    ElementStructure.Insert("uuid" , UUID);

    ReportPortal().CreateItem(URL, Token, Project, ElementStructure);

    ExistingSets.Insert(Name, UUID);

    Data.Insert("suites" , ExistingSets);
    Data.Insert("last_suite", UUID);

    WriteLaunchFile(Data);

    Return UUID;

EndFunction

Function CreateTestElement(Val Set, Val Library, Val Method, Val Option) Export

    Data = GetExistingLaunch();

    If Data = Undefined Then
        Return Undefined;
    EndIf;

    UUID = String(New UUID);
    CurrentDate = GetLaunchTime();

    If OPI_Tools.IsOneScript() Then
        LaunchType = "Common";
        HeaderPrimaryPart = Method;
    Else

        #If Client Then
            LaunchType = "Client";
        #Else
            LaunchType = "Host";
        #EndIf

        HeaderPrimaryPart = StrTemplate("%1: %2", LaunchType, Method);

    EndIf;

    If ValueIsFilled(Option) Then

        Title = StrTemplate("%1 (%2)", HeaderPrimaryPart, Option);
        Identifier = StrTemplate("%1_%2_%3_%4", LaunchType, Library, Method, Option);

    Else

        Title = HeaderPrimaryPart;
        Identifier = StrTemplate("%1_%2_%3", LaunchType, Library, Method);

    EndIf;

    Token = GetParameter("RPortal_Token");
    Project = GetParameter("RPortal_MainProject");
    URL = GetParameter("RPortal_URL");

    ElementStructure = New Structure;

    ElementStructure.Insert("name" , Title);
    ElementStructure.Insert("startTime" , CurrentDate);
    ElementStructure.Insert("uuid" , UUID);
    ElementStructure.Insert("type" , "step");
    ElementStructure.Insert("launchUuid", Data["id"]);

    ReportPortal().CreateItem(URL, Token, Project, ElementStructure, Set);

    Data["items"].Insert(UUID, Identifier);

    WriteLaunchFile(Data);

    Return UUID;

EndFunction

Procedure FinishLaunch() Export

    Token = GetParameter("RPortal_Token");
    Project = GetParameter("RPortal_MainProject");
    URL = GetParameter("RPortal_URL");

    CurrentDate = GetLaunchTime();

    ExistingLaunch = GetExistingLaunch();

    If ValueIsFilled(ExistingLaunch) Then

        LastSet = ExistingLaunch["last_suite"];

        If ValueIsFilled(LastSet) Then

            FinishStructure = New Structure("endTime,launchUuid", CurrentDate, LastSet);
            ReportPortal().FinishItem(URL, Token, Project, LastSet, FinishStructure);

        EndIf;

        // WriteMissingTests();

        FinishStructure = ReportPortal().GetLaunchCompletionStructure(CurrentDate);
        ReportPortal().FinishLaunch(URL, Token, Project, ExistingLaunch["id"], FinishStructure);

        ExistingLaunch["ended"] = True;
        WriteLaunchFile(ExistingLaunch);

    EndIf;

EndProcedure

Function GetExecutedTestsList() Export

    Tests = ReadLaunchFile()["tests"];

    Return ?(Tests = Undefined, New Array, Tests);

EndFunction

Function GetFullTestList() Export

    Lang = OPI_Tools.OPILanguage();

    Tests = StrTemplate(
        "https://raw.githubusercontent.com/Bayselonarrend/OpenIntegrations/refs/heads/main/service/tests_%1.json", Lang);

    OPI_TypeConversion.GetCollection(Tests);

    If Tests.Count() = 1 Or Not OPI_Tools.ThisIsCollection(Tests[0], True) Then
        Return New Array;
    Else
        Return Tests;
    EndIf;

EndFunction

#EndRegion

#Region Parameterization

Function GetFTPParameterOptions() Export

    OptionArray = New Array;

    TestParametersMain = New Structure;
    ParameterToCollection("FTP_IP" , TestParametersMain);
    ParameterToCollection("FTP_Port" , TestParametersMain);
    ParameterToCollection("FTPS_IP" , TestParametersMain);
    ParameterToCollection("FTPS_Port" , TestParametersMain);
    ParameterToCollection("FTP_User" , TestParametersMain);
    ParameterToCollection("FTP_Password" , TestParametersMain);
    ParameterToCollection("Proxy_User" , TestParametersMain);
    ParameterToCollection("Proxy_Password", TestParametersMain);
    ParameterToCollection("Socks5_IP" , TestParametersMain);
    ParameterToCollection("Socks5_Port" , TestParametersMain);
    ParameterToCollection("Proxy_IP" , TestParametersMain);
    ParameterToCollection("Proxy_Port" , TestParametersMain);
    ParameterToCollection("Picture" , TestParametersMain);
    ParameterToCollection("Big" , TestParametersMain);

    Localhost = GetLocalhost();

    Socks5IP = TestParametersMain["Socks5_IP"];
    TestParametersMain["Socks5_IP"] = ?(Socks5IP = "127.0.0.1", Localhost, Socks5IP);

    HttpProxyIP = TestParametersMain["Proxy_IP"];
    TestParametersMain["Proxy_IP"] = ?(HttpProxyIP = "127.0.0.1", Localhost, HttpProxyIP);

    // FTP
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", "FTP");
    ParametersStructure.Insert("FTP_IP", Localhost);
    ParametersStructure.Insert("FTP_Port", TestParametersMain["FTP_Port"]);
    ParametersStructure.Insert("FTP_User", TestParametersMain["FTP_User"]);
    ParametersStructure.Insert("FTP_Password", TestParametersMain["FTP_Password"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Socks5_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Socks5_Port"]);
    ParametersStructure.Insert("Proxy_Type", "socks5");
    ParametersStructure.Insert("Proxy", False);
    ParametersStructure.Insert("TLS", False);
    ParametersStructure.Insert("Picture", TestParametersMain["Picture"]);
    ParametersStructure.Insert("Big", TestParametersMain["Big"]);
    OptionArray.Add(ParametersStructure);

    // FTPS
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", "FTPS");
    ParametersStructure.Insert("FTP_IP", Localhost);
    ParametersStructure.Insert("FTP_Port", TestParametersMain["FTPS_Port"]);
    ParametersStructure.Insert("FTP_User", TestParametersMain["FTP_User"]);
    ParametersStructure.Insert("FTP_Password", TestParametersMain["FTP_Password"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Socks5_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Socks5_Port"]);
    ParametersStructure.Insert("Proxy_Type", "socks5");
    ParametersStructure.Insert("Proxy", False);
    ParametersStructure.Insert("TLS", True);
    ParametersStructure.Insert("Picture", TestParametersMain["Picture"]);
    ParametersStructure.Insert("Big", TestParametersMain["Big"]);
    OptionArray.Add(ParametersStructure);

    // FTP + Socks5
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", "FTP, Socks5");
    ParametersStructure.Insert("FTP_IP", TestParametersMain["FTP_IP"]);
    ParametersStructure.Insert("FTP_Port", TestParametersMain["FTP_Port"]);
    ParametersStructure.Insert("FTP_User", TestParametersMain["FTP_User"]);
    ParametersStructure.Insert("FTP_Password", TestParametersMain["FTP_Password"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Socks5_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Socks5_Port"]);
    ParametersStructure.Insert("Proxy_Type", "socks5");
    ParametersStructure.Insert("Proxy", True);
    ParametersStructure.Insert("TLS", False);
    ParametersStructure.Insert("Picture", TestParametersMain["Picture"]);
    ParametersStructure.Insert("Big", TestParametersMain["Big"]);
    OptionArray.Add(ParametersStructure);

    // FTPS + Socks5
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", ?(OPI_Tools.IsWindows(), "FTPS, Socks5", ""));
    ParametersStructure.Insert("FTP_IP", TestParametersMain["FTPS_IP"]);
    ParametersStructure.Insert("FTP_Port", TestParametersMain["FTP_Port"]);
    ParametersStructure.Insert("FTP_User", TestParametersMain["FTP_User"]);
    ParametersStructure.Insert("FTP_Password", TestParametersMain["FTP_Password"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Socks5_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Socks5_Port"]);
    ParametersStructure.Insert("Proxy_Type", "socks5");
    ParametersStructure.Insert("Proxy", True);
    ParametersStructure.Insert("TLS", True);
    ParametersStructure.Insert("Picture", TestParametersMain["Picture"]);
    ParametersStructure.Insert("Big", TestParametersMain["Big"]);
    OptionArray.Add(ParametersStructure);

    If False Then

        // FTP + HTTP
        ParametersStructure = New Structure;
        ParametersStructure.Insert("Postfix", "FTP, HTTP");
        ParametersStructure.Insert("FTP_IP", TestParametersMain["FTP_IP"]);
        ParametersStructure.Insert("FTP_Port", TestParametersMain["FTP_Port"]);
        ParametersStructure.Insert("FTP_User", TestParametersMain["FTP_User"]);
        ParametersStructure.Insert("FTP_Password", TestParametersMain["FTP_Password"]);
        ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
        ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
        ParametersStructure.Insert("Proxy_IP", TestParametersMain["Proxy_IP"]);
        ParametersStructure.Insert("Proxy_Port", TestParametersMain["Proxy_Port"]);
        ParametersStructure.Insert("Proxy_Type", "http");
        ParametersStructure.Insert("Proxy", True);
        ParametersStructure.Insert("TLS", False);
        ParametersStructure.Insert("Picture", TestParametersMain["Picture"]);
        ParametersStructure.Insert("Big", TestParametersMain["Big"]);
        OptionArray.Add(ParametersStructure);

        // FTPS + HTTP
        ParametersStructure = New Structure;
        ParametersStructure.Insert("Postfix", "");
        ParametersStructure.Insert("FTP_IP", TestParametersMain["FTPS_IP"]);
        ParametersStructure.Insert("FTP_Port", TestParametersMain["FTP_Port"]);
        ParametersStructure.Insert("FTP_User", TestParametersMain["FTP_User"]);
        ParametersStructure.Insert("FTP_Password", TestParametersMain["FTP_Password"]);
        ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
        ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
        ParametersStructure.Insert("Proxy_IP", TestParametersMain["Proxy_IP"]);
        ParametersStructure.Insert("Proxy_Port", TestParametersMain["Proxy_Port"]);
        ParametersStructure.Insert("Proxy_Type", "http");
        ParametersStructure.Insert("Proxy", True);
        ParametersStructure.Insert("TLS", True);
        ParametersStructure.Insert("Picture", TestParametersMain["Picture"]);
        ParametersStructure.Insert("Big", TestParametersMain["Big"]);
        OptionArray.Add(ParametersStructure);

    EndIf;

    Return OptionArray;

EndFunction

Function GetWebSocketParametersOptions() Export

    OptionArray = New Array;

    TestParametersMain = New Structure;
    ParameterToCollection("WS_IP" , TestParametersMain);
    ParameterToCollection("WS_Port" , TestParametersMain);
    ParameterToCollection("WS_InternalPort" , TestParametersMain);
    ParameterToCollection("WSS_IP" , TestParametersMain);
    ParameterToCollection("WSS_Port" , TestParametersMain);
    ParameterToCollection("WSS_InternalPort", TestParametersMain);
    ParameterToCollection("Proxy_User" , TestParametersMain);
    ParameterToCollection("Proxy_Password" , TestParametersMain);
    ParameterToCollection("Proxy_IP" , TestParametersMain);
    ParameterToCollection("Proxy_Port" , TestParametersMain);
    ParameterToCollection("Socks5_IP" , TestParametersMain);
    ParameterToCollection("Socks5_Port" , TestParametersMain);

    Localhost = GetLocalhost();

    Socks5IP = TestParametersMain["Socks5_IP"];
    TestParametersMain["Socks5_IP"] = ?(Socks5IP = "127.0.0.1", Localhost, Socks5IP);

    HttpProxyIP = TestParametersMain["Proxy_IP"];
    TestParametersMain["Proxy_IP"] = ?(HttpProxyIP = "127.0.0.1", Localhost, HttpProxyIP);

    // WS
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", "WS");
    ParametersStructure.Insert("WS_IP", Localhost);
    ParametersStructure.Insert("WS_Port", TestParametersMain["WS_Port"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Socks5_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Socks5_Port"]);
    ParametersStructure.Insert("Proxy_Type", "socks5");
    ParametersStructure.Insert("Proxy", False);
    ParametersStructure.Insert("TLS", False);
    OptionArray.Add(ParametersStructure);

    // WSS
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", "WSS");
    ParametersStructure.Insert("WS_IP", Localhost);
    ParametersStructure.Insert("WS_Port", TestParametersMain["WSS_Port"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Socks5_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Socks5_Port"]);
    ParametersStructure.Insert("Proxy_Type", "socks5");
    ParametersStructure.Insert("Proxy", False);
    ParametersStructure.Insert("TLS", True);
    OptionArray.Add(ParametersStructure);

    // WS + Socks5
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", "WS, Socks5");
    ParametersStructure.Insert("WS_IP", TestParametersMain["WS_IP"]);
    ParametersStructure.Insert("WS_Port", TestParametersMain["WS_InternalPort"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Socks5_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Socks5_Port"]);
    ParametersStructure.Insert("Proxy_Type", "socks5");
    ParametersStructure.Insert("Proxy", True);
    ParametersStructure.Insert("TLS", False);
    OptionArray.Add(ParametersStructure);

    // WSS + Socks5
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", "");
    ParametersStructure.Insert("WS_IP", TestParametersMain["WSS_IP"]);
    ParametersStructure.Insert("WS_Port", TestParametersMain["WSS_InternalPort"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Socks5_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Socks5_Port"]);
    ParametersStructure.Insert("Proxy_Type", "socks5");
    ParametersStructure.Insert("Proxy", True);
    ParametersStructure.Insert("TLS", True);
    OptionArray.Add(ParametersStructure);

    // WS + HTTP
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", "WS, HTTP");
    ParametersStructure.Insert("WS_IP", TestParametersMain["WS_IP"]);
    ParametersStructure.Insert("WS_Port", TestParametersMain["WS_InternalPort"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Proxy_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Proxy_Port"]);
    ParametersStructure.Insert("Proxy_Type", "http");
    ParametersStructure.Insert("Proxy", True);
    ParametersStructure.Insert("TLS", False);
    OptionArray.Add(ParametersStructure);

    // WSS + HTTP
    ParametersStructure = New Structure;
    ParametersStructure.Insert("Postfix", "WSS, HTTP");
    ParametersStructure.Insert("WS_IP", TestParametersMain["WSS_IP"]);
    ParametersStructure.Insert("WS_Port", TestParametersMain["WSS_InternalPort"]);
    ParametersStructure.Insert("Proxy_User", TestParametersMain["Proxy_User"]);
    ParametersStructure.Insert("Proxy_Password", TestParametersMain["Proxy_Password"]);
    ParametersStructure.Insert("Proxy_IP", TestParametersMain["Proxy_IP"]);
    ParametersStructure.Insert("Proxy_Port", TestParametersMain["Proxy_Port"]);
    ParametersStructure.Insert("Proxy_Type", "http");
    ParametersStructure.Insert("Proxy", True);
    ParametersStructure.Insert("TLS", True);
    OptionArray.Add(ParametersStructure);

    Return OptionArray;

EndFunction

Function GetSSHParameterOptions() Export

    OptionArray = New Array;

    TestParametersMain = New Structure;
    ParameterToCollection("Picture" , TestParametersMain);
    ParameterToCollection("Big" , TestParametersMain);
    ParameterToCollection("SSH_Host" , TestParametersMain);
    ParameterToCollection("SSH_HostKI" , TestParametersMain);
    ParameterToCollection("SSH_Port" , TestParametersMain);
    ParameterToCollection("SSH_PortKI" , TestParametersMain);
    ParameterToCollection("SSH_User" , TestParametersMain);
    ParameterToCollection("SSH_Password" , TestParametersMain);
    ParameterToCollection("SSH_Key" , TestParametersMain);
    ParameterToCollection("SSH_Pub" , TestParametersMain);
    ParameterToCollection("Proxy_User" , TestParametersMain);
    ParameterToCollection("Proxy_Password", TestParametersMain);
    ParameterToCollection("Socks5_IP" , TestParametersMain);
    ParameterToCollection("Socks5_Port" , TestParametersMain);
    ParameterToCollection("Proxy_IP" , TestParametersMain);
    ParameterToCollection("Proxy_Port" , TestParametersMain);
    ParameterToCollection("Access_Token" , TestParametersMain);

    Localhost = GetLocalhost();

    Socks5IP = TestParametersMain["Socks5_IP"];
    TestParametersMain["Socks5_IP"] = ?(Socks5IP = "127.0.0.1", Localhost, Socks5IP);

    HttpProxyIP = TestParametersMain["Proxy_IP"];
    TestParametersMain["Proxy_IP"] = ?(HttpProxyIP = "127.0.0.1", Localhost, HttpProxyIP);

    NetAddress = TestParametersMain["SSH_Host"];
    NetworkAddressKI = TestParametersMain["SSH_HostKI"];

    TestParametersMain.Insert("SSH_Host", Localhost);

    PrivateKey = GetTempFileName();
    Token = TestParametersMain["Access_Token"];
    OPI_HTTPRequests.NewRequest().Initialize(TestParametersMain["SSH_Key"]).AddBearerAuthorization(
        Token).ProcessRequest("GET").ReturnResponseAsBinaryData().Write(PrivateKey);

    TestParametersMain.Insert("SSH_Key", PrivateKey);

    TestParametersMain.Insert("Proxy" , False);
    TestParametersMain.Insert("Proxy_Type", "none");

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);
    TestParameters.Insert("AuthType", "By login and password");
    TestParameters.Insert("Postfix" , "By login and password");
    OptionArray.Add(TestParameters);

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);
    TestParameters.Insert("AuthType", "By key");
    TestParameters.Insert("Postfix" , "By key");
    OptionArray.Add(TestParameters);

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);
    TestParameters.Insert("AuthType", "Keyboard interactive");
    TestParameters.Insert("Postfix" , "Keyboard interactive");
    OptionArray.Add(TestParameters);

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);
    TestParameters.Insert("AuthType", "Via SSH agent");
    TestParameters.Insert("Postfix" , "Via SSH agent");
    //OptionArray.Add(TestParameters);

    For N = 0 To OptionArray.UBound() Do

        TestProxyParameters = OPI_Tools.CopyCollection(OptionArray[N]);

        Prefix = ?(TestProxyParameters["Postfix"] = "By login and password", "", StrTemplate("%1, SOCKS5",
            TestProxyParameters["Postfix"]));

        CurrentAddress = ?(TestProxyParameters["Postfix"] = "Keyboard interactive"
            , NetworkAddressKI
            , NetAddress);

        TestProxyParameters.Insert("SSH_Host" , CurrentAddress);
        TestProxyParameters.Insert("Proxy" , True);
        TestProxyParameters.Insert("Proxy_Type", "socks5");
        TestProxyParameters.Insert("Postfix" , Prefix);

        TestProxyParameters.Insert("Proxy_IP" , TestProxyParameters["Socks5_IP"]);
        TestProxyParameters.Insert("Proxy_Port", TestProxyParameters["Socks5_Port"]);
        OptionArray.Add(TestProxyParameters);

        TestProxyParameters = OPI_Tools.CopyCollection(OptionArray[N]);

        TestProxyParameters.Insert("SSH_Host" , CurrentAddress);
        TestProxyParameters.Insert("Proxy" , True);
        TestProxyParameters.Insert("Proxy_Type", "http");
        TestProxyParameters.Insert("Postfix" , StrTemplate("%1, HTTP", TestProxyParameters["Postfix"]));

        OptionArray.Add(TestProxyParameters);

    EndDo;

    Return OptionArray;

EndFunction

Function GetS3ParameterOptions() Export

    GpBucket = Left(String(New UUID), 8);
    DirBucket = Left(String(New UUID), 8);

    OptionArray = New Array;

    TestParametersMain = New Structure;
    ParameterToCollection("S3_AccessKey", TestParametersMain);
    ParameterToCollection("S3_SecretKey", TestParametersMain);
    ParameterToCollection("S3_URL" , TestParametersMain);
    ParameterToCollection("Picture" , TestParametersMain);
    ParameterToCollection("Audio" , TestParametersMain);

    TestParametersMain.Insert("S3_GPB", GpBucket);
    TestParametersMain.Insert("S3_DB" , DirBucket);

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);
    TestParameters.Insert("Directory", False);
    OptionArray.Add(TestParameters);

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);
    TestParameters.Insert("Directory", True);
    OptionArray.Add(TestParameters);

    Return OptionArray;

EndFunction

Function GetPostgresParameterOptions() Export

    OptionArray = New Array;

    TestParametersMain = New Structure;
    ParameterToCollection("PG_IP" , TestParametersMain);
    ParameterToCollection("PG_Password", TestParametersMain);
    ParameterToCollection("Picture" , TestParametersMain);
    ParameterToCollection("SQL" , TestParametersMain);

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);

    TestParameters.Insert("TLS" , False);
    TestParameters.Insert("Port", 5432);

    OptionArray.Add(TestParameters);

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);

    TestParameters.Insert("TLS" , True);
    TestParameters.Insert("Port", 5433);

    OptionArray.Add(TestParameters);

    Return OptionArray;

EndFunction

Function GetMySQLParameterOptions() Export

    OptionArray = New Array;

    TestParametersMain = New Structure;
    ParameterToCollection("PG_IP" , TestParametersMain);
    ParameterToCollection("PG_Password", TestParametersMain);
    ParameterToCollection("Picture" , TestParametersMain);
    ParameterToCollection("SQL2" , TestParametersMain);

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);

    TestParameters.Insert("TLS" , False);
    TestParameters.Insert("Port", 3306);

    OptionArray.Add(TestParameters);

    TestParameters = OPI_Tools.CopyCollection(TestParametersMain);

    TestParameters.Insert("TLS" , True);
    TestParameters.Insert("Port", 3307);

    OptionArray.Add(TestParameters);

    Return OptionArray;

EndFunction

Function GetTagArray(Index) Export

    TagsArray = New Array;

    If Index <= 3 Then
        TagsArray.Add("new");
    EndIf;

    If Index % 2 = 0 Then
        TagsArray.Add("sale");
    EndIf;

    If Index % 3 = 0 Then
        TagsArray.Add("popular");
    EndIf;

    If Index >= 12 Then
        TagsArray.Add("hit");
    EndIf;

    Return TagsArray;

EndFunction

Function GetJanxTestCollection(Val Option) Export

    If Option = "MultipleBinaries" Then

        Map = New Map;
        Map.Insert("alpha", GetBinaryDataFromHexString("010203"));
        Map.Insert("beta", GetBinaryDataFromHexString("AABBCCDDEE"));
        Map.Insert("gamma", GetBinaryDataFromHexString("FF00"));

        Nested = New Map;
        Nested.Insert("inner", GetBinaryDataFromHexString("DEADBEEF"));
        Nested.Insert("label", "nested");
        Map.Insert("nested", Nested);

        Meta = New Array;
        Meta.Add("x");
        Meta.Add(42);
        Map.Insert("meta", Meta);

        Return Map;

    ElsIf Option = "LuaComplexData" Then

        Map = New Map;
        Map.Insert("alpha", GetBinaryDataFromString("alpha-payload", "UTF-8"));
        Map.Insert("beta", GetBinaryDataFromString("beta-payload", "UTF-8"));
        Map.Insert("gamma", GetBinaryDataFromString("gamma-payload", "UTF-8"));

        Nested = New Map;
        Nested.Insert("inner", GetBinaryDataFromString("inner-payload", "UTF-8"));
        Nested.Insert("label", "nested");
        Map.Insert("nested", Nested);

        Meta = New Array;
        Meta.Add("x");
        Meta.Add(42);
        Map.Insert("meta", Meta);

        Return Map;

    ElsIf Option = "BinariesArray" Then

        BinaryArray = New Array;
        BinaryArray.Add(GetBinaryDataFromHexString("01"));
        BinaryArray.Add(GetBinaryDataFromHexString("020304"));
        BinaryArray.Add(GetBinaryDataFromHexString("0506070809"));

        Map = New Map;
        Map.Insert("chunks", BinaryArray);
        Map.Insert("count", 3);

        Return Map;

    ElsIf Option = "MixedArray" Then

        Array = New Array;
        Array.Add(1);
        Array.Add("text");
        Array.Add(GetBinaryDataFromHexString("0A0B"));

        NestedMap = New Map;
        NestedMap.Insert("k", "v");
        NestedMap.Insert("bin", GetBinaryDataFromHexString("112233"));
        Array.Add(NestedMap);

        NestedArray = New Array;
        NestedArray.Add(False);
        NestedArray.Add(GetBinaryDataFromHexString("445566"));
        Array.Add(NestedArray);

        Return Array;

    ElsIf Option = "LuaMixedArray" Then

        Array = New Array;
        Array.Add(1);
        Array.Add("text");
        Array.Add(GetBinaryDataFromString("item-payload", "UTF-8"));

        NestedMap = New Map;
        NestedMap.Insert("k", "v");
        NestedMap.Insert("bin", GetBinaryDataFromString("map-payload", "UTF-8"));
        Array.Add(NestedMap);

        NestedArray = New Array;
        NestedArray.Add(False);
        NestedArray.Add(GetBinaryDataFromString("arr-payload", "UTF-8"));
        Array.Add(NestedArray);

        Return Array;

    ElsIf Option = "DeepNesting" Then

        Level3 = New Map;
        Level3.Insert("blob", GetBinaryDataFromHexString("CAFEBABE"));

        Level2 = New Map;
        Level2.Insert("level3", Level3);
        Level2.Insert("values", New Array);
        Level2["values"].Add(7);
        Level2["values"].Add(GetBinaryDataFromHexString("99"));

        Level1 = New Map;
        Level1.Insert("level2", Level2);
        Level1.Insert("flag", True);

        Return Level1;

    ElsIf Option = "EmptyAndSpecial" Then

        Map = New Map;
        Map.Insert("empty_str", "");
        Map.Insert("zero", 0);
        Map.Insert("false", False);
        Map.Insert("empty_bin", GetBinaryDataFromString(""));
        Map.Insert("list", New Array);
        Map["list"].Add(GetBinaryDataFromHexString("00"));

        Return Map;

    EndIf;

    Raise "Unknown Janx test collection variant: " + Option;

EndFunction

#EndRegion

#EndRegion

#Region Private

#Region Checks

Function Check_Core_CheckIBToLastBuildCompliance(Val Result, Val Option, Val LastSum)

    //@skip-check use-non-recommended-method
    Message(StrTemplate("Current IB build: %1", Result));
    //@skip-check use-non-recommended-method
    Message(StrTemplate("Last project build: %1", LastSum));

    ExpectsThat(Result).Равно(LastSum);

    Return Undefined;

EndFunction

Function Check_Core_CallWithSettings(Val Result, Val Option)

    ResultType = TypeOf(Result);

    ExpectsThat(ResultType = Type("Structure") Or ResultType = Type("Map")).Равно(True);
    ExpectsThat(Result["status"]).Заполнено();
    ExpectsThat(Result["body"]).Заполнено();
    ExpectsThat(Result["headers"]).Заполнено();

    Return Undefined;

EndFunction

Function Check_Core_BackgroundCall(Val Result, Val Option)

    #If Not Client Then

        IsOneScript = OPI_Tools.IsOneScript();
        BackgroundJob = ?(IsOneScript
            , Result
            , Result["BackgroundJob"]);

        Try
            BackgroundJob.WaitForCompletion();
        Except

            Raise DetailErrorDescription(?(IsOneScript
                , BackgroundJob.ErrorInfo
                , BackgroundJobs.FindByUUID(BackgroundJob.UUID).ErrorInfo));

        EndTry;

        If Not IsOneScript Then
            BackgroundJob = BackgroundJobs.FindByUUID(BackgroundJob.UUID);
        EndIf;

        ExpectsThat(BackgroundJob.State).Равно(BackgroundJobState.Completed);

        If IsOneScript Then
            ResultData = BackgroundJob.Result;
        Else
        EndIf;

        If Not ValueIsFilled(Option) Then

            ExpectsThat(ResultData.Property("status")).Равно(True);
            ExpectsThat(ResultData.Property("headers")).Равно(True);
            ExpectsThat(ResultData.Property("body")).Равно(True);

        ElsIf Option = "BDReturn" Then

            ExpectsThat(TypeOf(ResultData)).Равно(Type("BinaryData"));

        ElsIf Option = "DBStructReturn" Then

            ExpectsThat(ResultData.Property("status")).Равно(True);
            ExpectsThat(ResultData.Property("headers")).Равно(True);
            ExpectsThat(TypeOf(ResultData["body"])).Равно(Type("BinaryData"));

        EndIf;

    #EndIf

    Return Undefined;

EndFunction

Function Check_Core_GetAvailableSettings(Val Result, Val Option)

    ExpectsThat(TypeOf(Result) = Type("String")).Равно(True);
    ExpectsThat(ValueIsFilled(Result)).Равно(True);
    ExpectsThat(StrFind(Result, "adv_response") > 0).Равно(True);

    Return Undefined;

EndFunction

Function Check_Telegram_GetBotInformation(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["username"]).Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_GetUpdates(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Undefined;

EndFunction

Function Check_Telegram_SetWebhook(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["description"]).Равно("Webhook was set");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_DeleteWebhook(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["description"]).Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_SendTextMessage(Val Result, Val Option, Parameters = "", Text = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    If Not ValueIsFilled(Option) Then

        ParameterName = "Telegram_MessageID";
        ExpectsThat(Result["result"]["text"]).Равно(Text);

    ElsIf Option = "Channel" Then

        ParameterName = "Telegram_ChannelMessageID";
        ExpectsThat(Result["result"]["text"]).Равно(Text);

    Else
        ParameterName = "";
    EndIf;

    If ValueIsFilled(ParameterName) Then

        MessageID = OPI_Tools.NumberToString(Result["result"]["message_id"]);
        WriteParameter(ParameterName, MessageID);
        OPI_Tools.AddField(ParameterName, MessageID, "String", Parameters);

    EndIf;

    Return Result;

EndFunction

Function Check_Telegram_FormKeyboardFromButtonArray(Val Result, Val Option)

    TypeResult = TypeOf(Result);

    ExpectsThat(TypeResult = Type("String") Or TypeResult = Type("Map")).Равно(True);
    Return Result;

EndFunction

Function Check_Telegram_SendImage(Val Result, Val Option, Parameters = "", Text = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    If Option <> "Text + Emoji" And Option <> "Complex" Then
        ExpectsThat(Result["result"]["caption"]).Равно(Text);
    EndIf;

    ExpectsThat(Result["result"]["photo"]).ИмеетТип("Array");

    If Not ValueIsFilled(Option) Then

        MessageID = OPI_Tools.NumberToString(Result["result"]["message_id"]);
        WriteParameter("Telegram_PicMessageID", MessageID);
        OPI_Tools.AddField("Telegram_PicMessageID", MessageID, "String", Parameters);

    EndIf;

    If Option = "Keyboard collection" Then

        FileID = Result["result"]["photo"][0]["file_id"];
        WriteParameter("Telegram_FileID", FileID);
        Parameters.Insert("Telegram_FileID", FileID);

    EndIf;

    Return Result;

EndFunction

Function Check_Telegram_SendVideo(Val Result, Val Option, Parameters = "", Text = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["caption"]).Равно(Text);
    ExpectsThat(Result["result"]["video"]["mime_type"]).Равно("video/mp4");

    If Option = "Binary" Then

        FileID = Result["result"]["video"]["file_id"];
        WriteParameter("Telegram_FileID", FileID);
        Parameters.Insert("Telegram_FileID", FileID);

    EndIf;

    Return Result;

EndFunction

Function Check_Telegram_SendAudio(Val Result, Val Option, Parameters = "", Text = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["caption"]).Равно(Text);
    ExpectsThat(Result["result"]["audio"]["mime_type"]).Равно("audio/mpeg");

    If Option = "Binary" Then

        FileID = Result["result"]["audio"]["file_id"];
        WriteParameter("Telegram_FileID", FileID);
        Parameters.Insert("Telegram_FileID", FileID);

    EndIf;

    Return Result;

EndFunction

Function Check_Telegram_SendDocument(Val Result, Val Option, Parameters = "", Text = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["caption"]).Равно(Text);
    ExpectsThat(Result["result"]["document"]).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_Telegram_SendGif(Val Result, Val Option, Parameters = "", Text = "")

    Result_ = "result";

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result[Result_]["caption"]).Равно(Text);
    ExpectsThat(Result[Result_]["document"]).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result[Result_]["animation"]["mime_type"]).Равно("video/mp4");

    Return Result;

EndFunction

Function Check_Telegram_SendMediaGroup(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Telegram_SendLocation(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["location"]).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_Telegram_SendContact(Val Result, Val Option, Name = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["contact"]).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["result"]["contact"]["first_name"]).Равно(Name);

    OPI_Tools.Pause(15);

    Return Result;

EndFunction

Function Check_Telegram_SendPoll(Val Result, Val Option, Question = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["poll"]).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["result"]["poll"]["question"]).Равно(Question);

    Return Result;

EndFunction

Function Check_Telegram_DownloadFile(Val Result, Val Option)

    ExpectsThat(TypeOf(Result) = Type("String") Or TypeOf(Result) = Type("BinaryData")).Равно(True);

    Return Result;

EndFunction

Function Check_Telegram_ForwardMessage(Val Result, Val Option, MessageID = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["forward_origin"]["message_id"]).Равно(Number(MessageID));

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_Ban(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["description"]).Равно("Bad Request: can't remove chat owner");

    OPI_Tools.Pause(2);

    Return Undefined;

EndFunction

Function Check_Telegram_Unban(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["description"]).Равно("Bad Request: can't remove chat owner");

    OPI_Tools.Pause(2);

    Return Undefined;

EndFunction

Function Check_Telegram_CreateInvitationLink(Val Result, Val Option, Title = "", UnixExpiration = "")

    Result_ = "result";
    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result[Result_]["member_limit"]).Равно(200);
    ExpectsThat(Result[Result_]["name"]).Равно(Title);
    ExpectsThat(Result[Result_]["expire_date"]).Равно(Number(UnixExpiration));

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_PinMessage(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_UnpinMessage(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_GetParticipantCount(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]).ИмеетТип("Number");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_GetAvatarIconList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_CreateForumTopic(Val Result, Val Option, Parameters = "", NameOrText = "", Icon = "")

    If Not ValueIsFilled(Option) Then

        TTID = "Telegram_TopicID";

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["ok"]).Равно(True);
        ExpectsThat(Result["result"]["name"]).Равно(NameOrText);
        ExpectsThat(Result["result"]["icon_custom_emoji_id"]).Равно(Icon);

        Topic = Result["result"]["message_thread_id"];

        OPI_Tools.AddField(TTID, Topic, "String", Parameters);
        WriteParameter(TTID, Parameters[TTID]);

    Else

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["ok"]).Равно(True);
        ExpectsThat(Result["result"]["text"]).Равно(NameOrText);

    EndIf;

    Return Result;

EndFunction

Function Check_Telegram_EditForumTopic(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_CloseForumTopic(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(10);

    Return Result;

EndFunction

Function Check_Telegram_OpenForumTopic(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(10);

    Return Result;

EndFunction

Function Check_Telegram_DeleteForumTopic(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(10);

    Return Result;

EndFunction

Function Check_Telegram_ClearTopicPinnedMessagesList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_HideMainForumTopic(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_ShowMainForumTopic(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_EditMainForumTopicName(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_DeleteMessage(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Telegram_ReplaceMessageText(Val Result, Val Option, Text = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["text"]).Равно(Text);

    Return Result;

EndFunction

Function Check_Telegram_ReplaceMessageKeyboard(Val Result, Val Option, Keyboard = "")

    MessageKeyboard = Result["result"]["reply_markup"];

    Keyboard_ = OPI_Tools.JsonToStructure(Keyboard);
    Keyboard_.Delete("rows");
    Keyboard_ = OPI_Tools.JSONString(Keyboard_);

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(StrLen(OPI_Tools.JSONString(MessageKeyboard))).Равно(StrLen(Keyboard_));

    Return Result;

EndFunction

Function Check_Telegram_ReplaceMessageCaption(Val Result, Val Option, Text = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["result"]["caption"]).Равно(Text);
    ExpectsThat(Result["result"]["photo"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_VK_CreateTokenRetrievalLink(Val Result, Val Option)

    If TypeOf(Result) = Type("BinaryData") Then
        Result = GetStringFromBinaryData(Result);
    EndIf;

    ExpectsThat(Result).ИмеетТип("String");
    ExpectsThat(StrStartWith(Result, "https://oauth.vk.com")).Равно(True);

    Return Result;

EndFunction

Function Check_VK_CreatePost(Val Result, Val Option, Parameters = "")

    PostID = Result["response"]["post_id"];

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(PostID).ИмеетТип("Number").Заполнено();

    If Option = "Path" Then

        OPI_Tools.AddField("VK_PostID", PostID, "String", Parameters);
        WriteParameter("VK_PostID", Parameters["VK_PostID"]);

    EndIf;

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_DeletePost(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_CreateCompositePost(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]["post_id"]).ИмеетТип("Number").Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_CreatePoll(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]["post_id"]).ИмеетТип("Number").Заполнено();

    Return Result;

EndFunction

Function Check_VK_CreateAlbum(Val Result, Val Option, Parameters = "", Description = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]["description"]).Равно(Description);

    AlbumID = Result["response"]["id"];
    Parameters.Insert("VK_AlbumID", AlbumID);
    WriteParameter("VK_AlbumID", AlbumID);

    Return Result;

EndFunction

Function Check_VK_SaveImageToAlbum(Val Result, Val Option, Parameters = "", Description = "", AlbumID = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"][0]["text"]).Равно(Description);
    ExpectsThat(Result["response"][0]["album_id"]).Равно(AlbumID);

    ImageID = Result["response"][0]["id"];
    Parameters.Insert("VK_PictureID", ImageID);
    WriteParameter("VK_PictureID", ImageID);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_DeleteImage(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_DeleteAlbum(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_CreateStory(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]["count"]).ИмеетТип("Number").Равно(1);
    ExpectsThat(Result["response"]["items"]).ИмеетТип("Array").Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_CreateDiscussion(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Заполнено();

    DiscussionID = Result["response"];
    Parameters.Insert("VK_ConvID", DiscussionID);
    WriteParameter("VK_ConvID", DiscussionID);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_CloseDiscussion(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_OpenDiscussion(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_WriteInDiscussion(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Заполнено();

    Return Result;

EndFunction

Function Check_VK_LikePost(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]["likes"]).ИмеетТип("Number").Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_MakeRepost(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]["success"]).ИмеетТип("Number").Равно(1);
    ExpectsThat(Result["response"]["wall_repost_count"]).ИмеетТип("Number");

    Parameters.Insert("Repost", Result["response"]["post_id"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_WriteComment(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]["comment_id"]).ИмеетТип("Number").Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_GetStatistics(Val Result, Val Option)

    TypeMap = "Map";

    ExpectsThat(Result).ИмеетТип(TypeMap).Заполнено();
    ExpectsThat(Result["response"][0]["visitors"]).ИмеетТип(TypeMap).Заполнено();
    ExpectsThat(Result["response"][0]["reach"]).ИмеетТип(TypeMap).Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_GetPostStatistics(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array").ИмеетДлину(2);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_CreateAdvertisingCampaign(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    CampaignID = Result["response"][0]["id"];
    WriteParameter("VK_AdsCampaignID", CampaignID);
    Parameters.Insert("VK_AdsCampaignID", CampaignID);

    Return Undefined;

EndFunction

Function Check_VK_CreateAd(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    AnnouncementID = Result["response"][0]["id"];
    WriteParameter("VK_AdsPostID", AnnouncementID);
    Parameters.Insert("VK_AdsPostID", AnnouncementID);

    Return Undefined;

EndFunction

Function Check_VK_PauseAdvertising(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Undefined;

EndFunction

Function Check_VK_FormKeyboard(Val Result, Val Option)

    TypeResult = TypeOf(Result);

    ExpectsThat(TypeResult = Type("String") Or TypeResult = Type("Map")).Равно(True);

    Return Result;

EndFunction

Function Check_VK_WriteMessage(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]).ИмеетТип("Number").Заполнено();

    Return Result;

EndFunction

Function Check_VK_GetProductCategoryList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_VK_CreateProductCollection(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]["albums_count"]).ИмеетТип("Number").Заполнено();
    ExpectsThat(Result["response"]["market_album_id"]).ИмеетТип("Number").Заполнено();

    SelectionID = Result["response"]["market_album_id"];
    WriteParameter("VK_MarketAlbumID", SelectionID);
    Parameters.Insert("VK_MarketAlbumID", SelectionID);

    Return Result;

EndFunction

Function Check_VK_EditProductCollection(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_GetSelectionsByID(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]["items"]).ИмеетТип("Array").Заполнено();

    Return Result;

EndFunction

Function Check_VK_AddProduct(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]["market_item_id"]).ИмеетТип("Number").Заполнено();

    ProductID = Result["response"]["market_item_id"];
    WriteParameter("VK_MarketItemID", ProductID);
    Parameters.Insert("VK_MarketItemID", ProductID);

    Return Result;

EndFunction

Function Check_VK_EditProduct(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    Return Result;

EndFunction

Function Check_VK_AddProductToCollection(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]).ИмеетТип("Number").Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_RemoveProductFromSelection(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_DeleteProduct(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_DeleteSelection(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_CreateProductProperty(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]["property_id"]).ИмеетТип("Number").Заполнено();

    Property = Result["response"]["property_id"];
    Property = OPI_Tools.NumberToString(Property);

    WriteParameter("VK_PropID", Property);
    Parameters.Insert("VK_PropID", Property);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_EditProductProperty(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_AddProductPropertyVariant(Val Result, Val Option, Parameters = "", Counter = 0)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]["variant_id"]).ИмеетТип("Number").Заполнено();

    VariantID = Result["response"]["variant_id"];
    ParameterName = "VK_PropVarID" + String(Counter);

    WriteParameter(ParameterName, VariantID);
    Parameters.Insert(ParameterName, VariantID);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_EditProductPropertyVariant(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_CreateProductWithProp(Val Result, Val Option, Parameters = "", Counter = 0)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]["market_item_id"]).ИмеетТип("Number").Заполнено();

    ProductID = Result["response"]["market_item_id"];
    FieldName = "VK_MarketItemID" + String(Counter);

    WriteParameter(FieldName, ProductID);
    Parameters.Insert(FieldName, ProductID);

    Return Result;

EndFunction

Function Check_VK_GetProductsByID(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]["items"]).ИмеетТип("Array").ИмеетДлину(2);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_GroupProducts(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]["item_group_id"]).ИмеетТип("Number").Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_DeleteProductPropertyVariant(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_DeleteProductProperty(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"]).ИмеетТип("Number").Равно(1);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_GetProductList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_GetSelectionList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_GetPropertyList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_GetOrderList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_UploadVideoToServer(Val Result, Val Option)

    ExpectsThat(Result["video_id"]).Заполнено();
    ExpectsThat(Result["video_hash"]).Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_VK_UploadPhotoToServer(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["response"][0]["text"]).Равно("");

    Return Result;

EndFunction

Function Check_VK_ShortenLink(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_VK_GetAdvertisingCategoryList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["response"]["v2"]).ИмеетТип("Array").Заполнено();

    Return Result;

EndFunction

Function Check_VK_GetProductDescription(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_VK_GetAuthParameters(Val Result, Val Option)

    ExpectsThat(Result["v"]).Заполнено();
    ExpectsThat(Result["from_group"]).Заполнено();
    ExpectsThat(Result["group_id"]).Заполнено();
    ExpectsThat(Result["owner_id"]).Заполнено();
    ExpectsThat(Result["app_id"]).Заполнено();
    ExpectsThat(Result["access_token"]).Заполнено();

    Return Result;

EndFunction

Function Check_YandexDisk_GetDiskInformation(Val Result, Val Option)

    Map_ = "Map";

    ExpectsThat(Result).ИмеетТип(Map_).Заполнено();
    ExpectsThat(Result["system_folders"]).ИмеетТип(Map_);
    ExpectsThat(Result["user"]).ИмеетТип(Map_);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_CreateFolder(Val Result, Val Option, Token = "", Path = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["type"]).Равно("dir");
    ExpectsThat(Result["path"]).Равно("disk:" + Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_UploadFileByURL(Val Result, Val Option, Parameters = "", Path = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["href"]).Заполнено();
    ExpectsThat(Result["method"]).Заполнено();

    WriteParameter("YandexDisk_FileByURLPath", Path);
    Parameters.Insert("YandexDisk_FileByURLPath", Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_GetObject(Val Result, Val Option, Path = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["type"]).Равно("file");
    ExpectsThat(Result["path"]).Равно("disk:" + Path);

    Return Result;

EndFunction

Function Check_YandexDisk_DeleteObject(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_UploadFile(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_UploadFileInParts(Val Result, Val Option, File = "")

    If Option = "Downloading" Then

        OPI_TypeConversion.GetBinaryData(File);

        ExpectsThat(Result).ИмеетТип("BinaryData").Заполнено();
        ExpectsThat(Result.Size()).Равно(File.Size());

        HashOrigianl = GetStringFromBinaryData(OPI_Cryptography.Hash(File, "SHA256"));
        HashCheck = GetStringFromBinaryData(OPI_Cryptography.Hash(Result, "SHA256"));

        ExpectsThat(HashCheck).Равно(HashOrigianl);

    ElsIf Option = "Deletion" Then

        If Not Lower(String(Result)) = "null" Then
            ExpectsThat(ValueIsFilled(Result)).Равно(False);
        EndIf;

    Else
        ExpectsThat(Result["status"] >= 200 And Result["status"] < 300).Равно(True);
    EndIf;

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_CreateObjectCopy(Val Result, Val Option, Parameters = "", Path = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["type"]).Равно("file");
    ExpectsThat(Result["path"]).Равно("disk:" + Path);

    WriteParameter("YandexDisk_CopyFilePath", Path);
    Parameters.Insert("YandexDisk_CopyFilePath", Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_GetDownloadLink(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["method"]).Равно("GET");
    ExpectsThat(Result["href"]).ИмеетТип("String").Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_DownloadFile(Val Result, Val Option)

    MinimumSize = 1000;

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() > MinimumSize).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_GetFilesList(Val Result, Val Option, Count = 0, Indent = 0)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["limit"]).Равно(Count);
    ExpectsThat(Result["offset"]).Равно(Indent);
    ExpectsThat(Result["items"]).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_MoveObject(Val Result, Val Option, Parameters = "", Path = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["type"]).Равно("file");
    ExpectsThat(Result["path"]).Равно("disk:" + Path);

    WriteParameter("YandexDisk_NewFilePath", Path);
    Parameters.Insert("YandexDisk_NewFilePath", Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_GetPublishedObjectsList(Val Result, Val Option, Count = 0,
    Indent = 0)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["limit"]).Равно(Count);
    ExpectsThat(Result["offset"]).Равно(Indent);
    ExpectsThat(Result["items"]).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_YandexDisk_PublishObject(Val Result, Val Option, Parameters = "", Path = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["type"]).Равно("file");
    ExpectsThat(Result["path"]).Равно("disk:" + Path);
    ExpectsThat(Result["public_url"]).ИмеетТип("String").Заполнено();

    URL = Result["public_url"];
    WriteParameter("YandexDisk_PublicURL", URL);
    Parameters.Insert("YandexDisk_PublicURL", URL);

    Return Result;

EndFunction

Function Check_YandexDisk_GetDownloadLinkForPublicObject(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["method"]).Равно("GET");
    ExpectsThat(Result["href"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_YandexDisk_GetPublicObject(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["type"]).Равно("file");
    ExpectsThat(Result["path"]).Заполнено();
    ExpectsThat(Result["public_url"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_YandexDisk_SavePublicObjectToDisk(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["type"]).Равно("file");
    ExpectsThat(Result["path"]).Заполнено();
    ExpectsThat(Result["public_url"]).ИмеетТип("Undefined");

    Return Result;

EndFunction

Function Check_YandexDisk_CancelObjectPublication(Val Result, Val Option, Path = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["type"]).Равно("file");
    ExpectsThat(Result["path"]).Равно("disk:" + Path);
    ExpectsThat(Result["public_url"]).ИмеетТип("Undefined");

    Return Result;

EndFunction

Function Check_YandexDisk_GetConfirmationCode(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["verification_url"]).Заполнено();
    ExpectsThat(Result["device_code"]).Заполнено();

    Return Result;

EndFunction

Function Check_YandexDisk_ConvertCodeToToken(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    If Result.Get("access_token") <> Undefined Then

        Token = Result["access_token"];
        WriteParameter("YandexDisk_Token", Token);
        Parameters.Insert("YandexDisk_Token", Token);

        Token = Result["refresh_token"];
        WriteParameter("YandexDisk_RefreshToken", Token);
        Parameters.Insert("YandexDisk_RefreshToken", Token);

    EndIf;

    Return Undefined;

EndFunction

Function Check_YandexDisk_RefreshToken(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["access_token"]).Заполнено();
    ExpectsThat(Result["refresh_token"]).Заполнено();

    Token = Result["access_token"];
    WriteParameter("YandexDisk_Token", Token);
    Parameters.Insert("YandexDisk_Token", Token);

    Token = Result["refresh_token"];
    WriteParameter("YandexDisk_RefreshToken", Token);
    Parameters.Insert("YandexDisk_RefreshToken", Token);

    Return Undefined;

EndFunction

Function Check_Viber_SetWebhook(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_Viber_GetChannelInformation(Val Result, Val Option)

    ExpectsThat(Result["status_message"]).Равно("ok");
    ExpectsThat(Result["status"]).Равно(0);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Viber_GetUserData(Val Result, Val Option)

    ExpectsThat(Result["chat_hostname"]).Заполнено();
    ExpectsThat(Result["status_message"]).Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Viber_GetOnlineUsers(Val Result, Val Option)

    ExpectsThat(Result["status_message"]).Равно("ok");
    ExpectsThat(Result["status"]).Равно(0);
    ExpectsThat(Result["users"]).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Viber_CreateKeyboardFromArrayButton(Val Result, Val Option)

    Return Result;

EndFunction

Function Check_Viber_SendTextMessage(Val Result, Val Option)

    ExpectsThat(Result["message_token"]).Заполнено();
    ExpectsThat(Result["status_message"]).Равно("ok");
    ExpectsThat(Result["status"]).Равно(0);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Viber_SendImage(Val Result, Val Option)

    ExpectsThat(Result["message_token"]).Заполнено();
    ExpectsThat(Result["status_message"]).Равно("ok");
    ExpectsThat(Result["status"]).Равно(0);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Viber_SendFile(Val Result, Val Option)

    ExpectsThat(Result["message_token"]).Заполнено();
    ExpectsThat(Result["status_message"]).Равно("ok");
    ExpectsThat(Result["status"]).Равно(0);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Viber_SendContact(Val Result, Val Option)

    ExpectsThat(Result["message_token"]).Заполнено();
    ExpectsThat(Result["status_message"]).Равно("ok");
    ExpectsThat(Result["status"]).Равно(0);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Viber_SendLocation(Val Result, Val Option)

    ExpectsThat(Result["message_token"]).Заполнено();
    ExpectsThat(Result["status_message"]).Равно("ok");
    ExpectsThat(Result["status"]).Равно(0);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Viber_SendLink(Val Result, Val Option)

    ExpectsThat(Result["message_token"]).Заполнено();
    ExpectsThat(Result["status_message"]).Равно("ok");
    ExpectsThat(Result["status"]).Равно(0);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleWorkspace_FormCodeRetrievalLink(Val Result, Val Option)

    If TypeOf(Result) = Type("BinaryData") Then
        Result = GetStringFromBinaryData(Result);
    EndIf;

    ExpectsThat(Result).ИмеетТип("String");
    ExpectsThat(StrStartWith(Result, "https://accounts.google.com/o/oauth2")).Равно(True);

    WriteParameter("Google_Link", Result);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleWorkspace_GetTokenByCode(Val Result, Val Option)

    If ValueIsFilled(Result["access_token"]) And ValueIsFilled(Result["refresh_token"]) Then

        WriteParameter("Google_Token" , Result["access_token"]);
        WriteParameter("Google_Refresh", Result["refresh_token"]);

    EndIf;

    OPI_Tools.Pause(2);

    Return Undefined;

EndFunction

Function Check_GoogleWorkspace_RefreshToken(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["access_token"]).Заполнено();
    WriteParameter("Google_Token", Result["access_token"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleWorkspace_GetServiceAccountToken(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["access_token"]).Заполнено();
    WriteParameter("Google_ServiceToken", Result["access_token"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleCalendar_FormCodeRetrievalLink(Val Result, Val Option)

    If TypeOf(Result) = Type("BinaryData") Then
        Result = GetStringFromBinaryData(Result);
    EndIf;

    ExpectsThat(Result).ИмеетТип("String");
    ExpectsThat(StrStartWith(Result, "https://accounts.google.com/o/oauth2")).Равно(True);

    WriteParameter("Google_Link", Result);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleCalendar_GetTokenByCode(Val Result, Val Option)

    If ValueIsFilled(Result["access_token"]) And ValueIsFilled(Result["refresh_token"]) Then

        WriteParameter("Google_Token" , Result["access_token"]);
        WriteParameter("Google_Refresh", Result["refresh_token"]);

    EndIf;

    OPI_Tools.Pause(2);

    Return Undefined;

EndFunction

Function Check_GoogleCalendar_RefreshToken(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["access_token"]).Заполнено();
    WriteParameter("Google_Token", Result["access_token"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleCalendar_GetServiceAccountToken(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["access_token"]).Заполнено();
    WriteParameter("Google_ServiceToken", Result["access_token"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleCalendar_GetCalendarList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleCalendar_CreateCalendar(Val Result, Val Option, Parameters = "", Name = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["summary"]).Равно(Name);
    ExpectsThat(Result["id"]).ИмеетТип("String").Заполнено();

    Calendar = Result["id"];
    WriteParameter("Google_NewCalendarID", Calendar);
    OPI_Tools.AddField("Google_NewCalendarID", Calendar, "String", Parameters);

    Return Result;

EndFunction

Function Check_GoogleCalendar_EditCalendarMetadata(Val Result, Val Option, Name = "",
    Description = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["summary"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);
    ExpectsThat(Result["id"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_GoogleCalendar_GetCalendarMetadata(Val Result, Val Option, Name = "",
    Description = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["summary"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);
    ExpectsThat(Result["id"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_GoogleCalendar_AddCalendarToList(Val Result, Val Option, Name = "", Description = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["summary"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);
    ExpectsThat(Result["id"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_GoogleCalendar_EditListCalendar(Val Result, Val Option, PrimaryColor = "",
    SecondaryColor = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["foregroundColor"]).Равно(PrimaryColor);
    ExpectsThat(Result["backgroundColor"]).Равно(SecondaryColor);

    Return Result;

EndFunction

Function Check_GoogleCalendar_GetListCalendar(Val Result, Val Option, PrimaryColor = "",
    SecondaryColor = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["foregroundColor"]).Равно(PrimaryColor);
    ExpectsThat(Result["backgroundColor"]).Равно(SecondaryColor);

    Return Result;

EndFunction

Function Check_GoogleCalendar_ClearMainCalendar(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_GoogleCalendar_DeleteCalendarFromList(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then

        If ValueIsFilled(Result) Then
            ExpectsThat(Result["error"]["message"])
                .Равно("Data owner of a calendar cannot remove calendar list entry for that calendar.");
        EndIf;

    EndIf;

    Return Result;

EndFunction

Function Check_GoogleCalendar_DeleteCalendar(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_GoogleCalendar_CreateEvent(Val Result, Val Option, Parameters = "", Name = "",
    Description = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["summary"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);
    ExpectsThat(Result["id"]).ИмеетТип("String").Заполнено();

    Event = Result["id"];
    WriteParameter("Google_EventID", Event);
    OPI_Tools.AddField("Google_EventID", Event, "String", Parameters);

    Return Result;

EndFunction

Function Check_GoogleCalendar_EditEvent(Val Result, Val Option, Name = "", Description = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["summary"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);
    ExpectsThat(Result["id"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_GoogleCalendar_GetEvent(Val Result, Val Option, Name = "", Description = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["summary"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);
    ExpectsThat(Result["id"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_GoogleCalendar_MoveEvent(Val Result, Val Option, Name = "", Description = "")

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["summary"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);
    ExpectsThat(Result["id"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_GoogleCalendar_DeleteEvent(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_GoogleCalendar_GetEventList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_GoogleCalendar_GetEventDescription(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_GoogleDrive_FormCodeRetrievalLink(Val Result, Val Option)

    If TypeOf(Result) = Type("BinaryData") Then
        Result = GetStringFromBinaryData(Result);
    EndIf;

    ExpectsThat(Result).ИмеетТип("String");
    ExpectsThat(StrStartWith(Result, "https://accounts.google.com/o/oauth2")).Равно(True);

    WriteParameter("Google_Link", Result);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleDrive_GetTokenByCode(Val Result, Val Option)

    If ValueIsFilled(Result["access_token"]) And ValueIsFilled(Result["refresh_token"]) Then

        WriteParameter("Google_Token" , Result["access_token"]);
        WriteParameter("Google_Refresh", Result["refresh_token"]);

    EndIf;

    OPI_Tools.Pause(2);

    Return Undefined;

EndFunction

Function Check_GoogleDrive_RefreshToken(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["access_token"]).Заполнено();
    WriteParameter("Google_Token", Result["access_token"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleDrive_GetServiceAccountToken(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["access_token"]).Заполнено();
    WriteParameter("Google_ServiceToken", Result["access_token"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleDrive_GetDirectoriesList(Val Result, Val Option, Parameters = "")

    Result = Result[0];

    ExpectsThat(Result["mimeType"]).Равно("application/vnd.google-apps.folder");
    ExpectsThat(Result["name"]).Заполнено();

    Identifier = Result["id"];
    WriteParameter("GD_Catalog", Identifier);
    OPI_Tools.AddField("GD_Catalog", Identifier, "String", Parameters);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleDrive_GetObjectInformation(Val Result, Val Option)

    ExpectsThat(Result["mimeType"]).Равно("application/vnd.google-apps.folder");
    ExpectsThat(Result["name"]).Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleDrive_UploadFile(Val Result, Val Option, Parameters = "", Description = "")

    If Not ValueIsFilled(Option) Then

        ExpectsThat(Result["mimeType"]).Равно(Description["MIME"]);
        ExpectsThat(Result["name"]).Равно(Description["Name"]);

        Identifier = Result["id"];

        WriteParameter("GD_File", Identifier);
        OPI_Tools.AddField("GD_File", Identifier, "String", Parameters);

    ElsIf Option = "Check" Then

        File = Parameters["Big"];

        OPI_TypeConversion.GetBinaryData(File);

        ExpectsThat(Result).ИмеетТип("BinaryData").Заполнено();
        ExpectsThat(Result.Size()).Равно(File.Size());

        HashOrigianl = GetStringFromBinaryData(OPI_Cryptography.Hash(File, "SHA256"));
        HashCheck = GetStringFromBinaryData(OPI_Cryptography.Hash(Result, "SHA256"));

        ExpectsThat(HashCheck).Равно(HashOrigianl);

    Else

        ExpectsThat(Result["mimeType"]).Равно(Description["MIME"]);
        ExpectsThat(Result["name"]).Равно(Description["Name"]);

        Identifier = Result["id"];

        ArrayOfDeletions = Parameters["ArrayOfDeletions"];
        ArrayOfDeletions.Add(Identifier);
        Parameters.Insert("ArrayOfDeletions", ArrayOfDeletions);

    EndIf;

    Return Result;

EndFunction

Function Check_GoogleDrive_CopyObject(Val Result, Val Option, Parameters = "", NewName = "")

    Description = New Structure("Name,MIME", NewName, "image/jpeg");

    ExpectsThat(Result["mimeType"]).Равно(Description["MIME"]);
    ExpectsThat(Result["name"]).Равно(Description["Name"]);

    Identifier = Result["id"];

    ArrayOfDeletions = Parameters["ArrayOfDeletions"];
    ArrayOfDeletions.Add(Identifier);
    Parameters.Insert("ArrayOfDeletions", ArrayOfDeletions);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleDrive_DownloadFile(Val Result, Val Option, Parameters = "")

    Size = OPI_HTTPRequests.Get(Parameters["Picture"]).Size();

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() >= Size).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleDrive_UpdateFile(Val Result, Val Option, NewName = "")

    Description = New Structure("Name,MIME", NewName, "image/jpeg");

    ExpectsThat(Result["mimeType"]).Равно(Description["MIME"]);
    ExpectsThat(Result["name"]).Равно(Description["Name"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleDrive_GetFilesList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_GoogleDrive_DeleteObject(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_GoogleDrive_GetFileDescription(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_GoogleDrive_CreateComment(Val Result, Val Option, Parameters = "", Comment = "")

    ExpectsThat(Result["content"]).Равно(Comment);
    ExpectsThat(Result["kind"]).Равно("drive#comment");

    Identifier = Result["id"];

    WriteParameter("GD_Comment", Identifier);
    OPI_Tools.AddField("GD_Comment", Identifier, "String", Parameters);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleDrive_GetComment(Val Result, Val Option)

    ExpectsThat(Result["content"]).Равно("Comment text");
    ExpectsThat(Result["kind"]).Равно("drive#comment");

    Return Result;

EndFunction

Function Check_GoogleDrive_GetCommentList(Val Result, Val Option)

    Comments = Result["comments"];
    CommentObject = Comments[Comments.UBound()];

    ExpectsThat(CommentObject["content"]).Равно("Comment text");
    ExpectsThat(CommentObject["kind"]).Равно("drive#comment");

    Return Result;

EndFunction

Function Check_GoogleDrive_DeleteComment(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_GoogleDrive_CreateFolder(Val Result, Val Option)

    ExpectsThat(Result["mimeType"]).Равно("application/vnd.google-apps.folder");
    ExpectsThat(Result["name"]).Заполнено();

    Return Result;

EndFunction

Function Check_GoogleSheets_FormCodeRetrievalLink(Val Result, Val Option)

    If TypeOf(Result) = Type("BinaryData") Then
        Result = GetStringFromBinaryData(Result);
    EndIf;

    ExpectsThat(Result).ИмеетТип("String");
    ExpectsThat(StrStartWith(Result, "https://accounts.google.com/o/oauth2")).Равно(True);

    WriteParameter("Google_Link", Result);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleSheets_GetTokenByCode(Val Result, Val Option)

    If ValueIsFilled(Result["access_token"]) And ValueIsFilled(Result["refresh_token"]) Then

        WriteParameter("Google_Token" , Result["access_token"]);
        WriteParameter("Google_Refresh", Result["refresh_token"]);

    EndIf;

    OPI_Tools.Pause(2);

    Return Undefined;

EndFunction

Function Check_GoogleSheets_RefreshToken(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["access_token"]).Заполнено();
    WriteParameter("Google_Token", Result["access_token"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleSheets_GetServiceAccountToken(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    ExpectsThat(Result["access_token"]).Заполнено();
    WriteParameter("Google_ServiceToken", Result["access_token"]);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_GoogleSheets_CreateSpreadsheet(Val Result, Val Option, Parameters = "", Name = "",
    SheetArray = "")

    ExpectsThat(Result["properties"]["title"]).Равно(Name);

    If ValueIsFilled(SheetArray) Then

        For N = 0 To SheetArray.UBound() Do

            SheetName = Result["sheets"][N]["properties"]["title"];
            ExpectsThat(SheetName).Равно(SheetArray[N]);

        EndDo;

    EndIf;

    Spreadsheet = Result["spreadsheetId"];

    If Not ValueIsFilled(Option) Then

        Sheet = Result["sheets"][0]["properties"]["sheetId"];
        Sheet = OPI_Tools.NumberToString(Sheet);

        WriteParameter("GS_Spreadsheet", Spreadsheet);
        WriteParameter("GS_Sheet" , Sheet);

        OPI_Tools.AddField("GS_Spreadsheet", Spreadsheet, "String", Parameters);
        OPI_Tools.AddField("GS_Sheet" , Sheet , "String", Parameters);

    Else

        WriteParameter("GS_Spreadsheet2", Spreadsheet);
        OPI_Tools.AddField("GS_Spreadsheet2", Spreadsheet, "String", Parameters);

    EndIf;

    Return Result;

EndFunction

Function Check_GoogleSheets_GetSpreadsheet(Val Result, Val Option, Token = "")

    Name = "TestTable";

    SheetArray = New Array;
    SheetArray.Add("Sheet1");
    SheetArray.Add("Sheet2");

    ExpectsThat(Result["properties"]["title"]).Равно(Name);

    For N = 0 To SheetArray.UBound() Do

        SheetName = Result["sheets"][N]["properties"]["title"];
        ExpectsThat(SheetName).Равно(SheetArray[N]);

    EndDo;

    Return Result;

EndFunction

Function Check_GoogleSheets_CopySheet(Val Result, Val Option)

    ExpectsThat(Result["title"]).Заполнено();

    Return Result;

EndFunction

Function Check_GoogleSheets_AddSheet(Val Result, Val Option)

    NewSheet = Result["replies"][0]["addSheet"]["properties"];
    ExpectsThat(NewSheet["title"]).Заполнено();

    Return Result;

EndFunction

Function Check_GoogleSheets_DeleteSheet(Val Result, Val Option, Spreadsheet = "")

    ExpectsThat(Result["spreadsheetId"]).Равно(Spreadsheet);

    Return Result;

EndFunction

Function Check_GoogleSheets_EditSpreadsheetTitle(Val Result, Val Option, Spreadsheet = "")

    ExpectsThat(Result["spreadsheetId"]).Равно(Spreadsheet);

    Return Result;

EndFunction

Function Check_GoogleSheets_GetTable(Val Result, Val Option)

    Name = "Test table (changed.)";
    ExpectsThat(Result["properties"]["title"]).Равно(Name);

    Return Result;

EndFunction

Function Check_GoogleSheets_SetCellValues(Val Result, Val Option, Count = 0)

    ExpectsThat(Result["totalUpdatedCells"]).Равно(Count);

    Return Result;

EndFunction

Function Check_GoogleSheets_GetCellValues(Val Result, Val Option, BookOrAmount = 0)

    If Option = "All" Then
        ExpectsThat(Result["spreadsheetId"]).Равно(BookOrAmount);
    Else
        ExpectsThat(Result["valueRanges"].Count()).Равно(BookOrAmount);
    EndIf;

    Return Result;

EndFunction

Function Check_GoogleSheets_ClearCells(Val Result, Val Option, Count = 0)

    ExpectsThat(Result["clearedRanges"].Count()).Равно(Count);

    Return Result;

EndFunction

Function Check_Slack_GetBotInformation(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["bot_id"]).Заполнено();
    ExpectsThat(Result["user_id"]).Заполнено();

    Return Result;

EndFunction

Function Check_Slack_GetUserList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["members"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Slack_GetWorkspaceList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["teams"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Slack_SendMessage(Val Result, Val Option, Parameters = "", Text = "", Channel = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["channel"]).Равно(Channel);
    ExpectsThat(Result["message"]["text"]).Равно(Text);

    If Not ValueIsFilled(Option) Then

        Timestamp = Result["ts"];
        WriteParameter("Slack_MessageTS", Timestamp);
        OPI_Tools.AddField("Slack_MessageTS", Timestamp, "String", Parameters);

    EndIf;

    If Not Option = "Sheduled" Then

        ExpectsThat(Result["ts"]).Заполнено();

    EndIf;

    Return Result;

EndFunction

Function Check_Slack_GenerateImageBlock(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_Slack_EditMessage(Val Result, Val Option, Text = "", Channel = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["channel"]).Равно(Channel);
    ExpectsThat(Result["ts"]).Заполнено();
    ExpectsThat(Result["message"]["text"]).Равно(Text);

    Return Result;

EndFunction

Function Check_Slack_GetMessageReplyList(Val Result, Val Option)

    ExpectsThat(Result["messages"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Slack_GetMessageLink(Val Result, Val Option, Channel = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["channel"]).Равно(Channel);
    ExpectsThat(Result["permalink"]).Заполнено();

    Return Result;

EndFunction

Function Check_Slack_DeleteMessage(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Slack_SendEphemeralMessage(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["message_ts"]).Заполнено();

    Return Result;

EndFunction

Function Check_Slack_GetDelayedMessageList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["scheduled_messages"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Slack_CreateChannel(Val Result, Val Option, Parameters = "", Name = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Data = Result["channel"];
    ExpectsThat(Data["name"]).Равно(Name);

    Channel = Result["channel"]["id"];
    WriteParameter("Slack_NewChannel", Channel);
    OPI_Tools.AddField("Slack_NewChannel", Channel, "String", Parameters);

    WriteParameter("Slack_NewChannelName", Name);
    OPI_Tools.AddField("Slack_NewChannelName", Name, "String", Parameters);

    Return Result;

EndFunction

Function Check_Slack_SetChannelTopic(Val Result, Val Option, Topic = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Data = Result["channel"];
    ExpectsThat(Data["topic"]["value"]).Равно(Topic);

    Return Result;

EndFunction

Function Check_Slack_SetChannelGoal(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Slack_GetChannel(Val Result, Val Option, Name = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Data = Result["channel"];
    ExpectsThat(Data["name"]).Равно(Name);

    Return Result;

EndFunction

Function Check_Slack_InviteUsersToChannel(Val Result, Val Option, Name = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Data = Result["channel"];
    ExpectsThat(Data["name"]).Равно(Name);

    Return Result;

EndFunction

Function Check_Slack_KickUserFromChannel(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Slack_GetChannelHistory(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["messages"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Slack_GetChannelUserList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["members"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Slack_LeaveChannel(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Slack_JoinChannel(Val Result, Val Option, Name = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Data = Result["channel"];
    ExpectsThat(Data["name"]).Равно(Name);

    Return Result;

EndFunction

Function Check_Slack_RenameChannel(Val Result, Val Option, Name = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Data = Result["channel"];
    ExpectsThat(Data["name"]).Равно(Name);

    Return Result;

EndFunction

Function Check_Slack_ArchiveChannel(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Slack_GetChannelList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["channels"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Slack_OpenDialog(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    If Not ValueIsFilled(Option) Then

        Dialog = Result["channel"]["id"];

        ExpectsThat(Result["channel"]).ИмеетТип("Map");
        ExpectsThat(Dialog).Заполнено();

        WriteParameter("Slack_Dialog", Dialog);
        OPI_Tools.AddField("Slack_Dialog", Dialog, "String", Parameters);

    EndIf;

    Return Result;

EndFunction

Function Check_Slack_CloseDialog(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Slack_GetFilesList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["files"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Slack_UploadFile(Val Result, Val Option, Parameters = "", FileName = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    If ValueIsFilled(Result["files"]) Then
        UploadedFile = Result["files"][0];
    Else
        UploadedFile = Result["file"];
    EndIf;

    ExpectsThat(UploadedFile["name"]).Равно(FileName);

    If Not ValueIsFilled(Option) Then

        UploadedFile = Result["files"][0]["id"];
        WriteParameter("Slack_FileID", UploadedFile);
        OPI_Tools.AddField("Slack_FileID", UploadedFile, "String", Parameters);

    EndIf;

    Return Result;

EndFunction

Function Check_Slack_MakeFilePublic(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Undefined;

EndFunction

Function Check_Slack_MakeFilePrivate(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Undefined;

EndFunction

Function Check_Slack_GetFileData(Val Result, Val Option, FileName = "")

    If ValueIsFilled(Result["files"]) Then
        UploadedFile = Result["files"][0];
    Else
        UploadedFile = Result["file"];
    EndIf;

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(UploadedFile["name"]).Равно(FileName);

    Return Result;

EndFunction

Function Check_Slack_DeleteFile(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Slack_GetExternalFileList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["files"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Slack_AddExternalFile(Val Result, Val Option, Parameters = "", Title = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    UploadedFile = Result["file"];
    ExpectsThat(UploadedFile["title"]).Равно(Title);

    UploadedFile = Result["file"]["id"];
    WriteParameter("Slack_ExtFileID", UploadedFile);
    OPI_Tools.AddField("Slack_ExtFileID", UploadedFile, "String", Parameters);

    Return Result;

EndFunction

Function Check_Slack_GetExternalFile(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    UploadedFile = Result["file"];
    ExpectsThat(UploadedFile["title"]).Равно("NewFile");

    Return Result;

EndFunction

Function Check_Slack_SendExternalFile(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Slack_DeleteExternalFile(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Airtable_CreateDatabase(Val Result, Val Option, Parameters = "", TableName = "")

    ExpectsThat(Result["id"]).Заполнено();
    ExpectsThat(Result["tables"][0]["name"]).Равно(TableName);

    Base = Result["id"];
    WriteParameter("Airtable_Base", Base);
    OPI_Tools.AddField("Airtable_Base", Base, "String", Parameters);

    Return Result;

EndFunction

Function Check_Airtable_GetDatabaseTables(Val Result, Val Option)

    ExpectsThat(Result["tables"]).Заполнено();
    ExpectsThat(Result["tables"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Airtable_GetListOfBases(Val Result, Val Option)

    ExpectsThat(Result["bases"]).Заполнено();
    ExpectsThat(Result["bases"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Airtable_GetNumberField(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Airtable_GetStringField(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Airtable_GetAttachmentField(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Airtable_GetCheckboxField(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Airtable_GetDateField(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Airtable_GetPhoneField(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Airtable_GetEmailField(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Airtable_GetLinkField(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Airtable_CreateTable(Val Result, Val Option, Parameters = "", Name = "", Description = "")

    ExpectsThat(Result["name"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);

    Table = Result["id"];
    WriteParameter("Airtable_Table", Table);
    OPI_Tools.AddField("Airtable_Table", Table, "String", Parameters);

    Return Result;

EndFunction

Function Check_Airtable_ModifyTable(Val Result, Val Option, Name = "", Description = "")

    ExpectsThat(Result["name"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);

    Return Result;

EndFunction

Function Check_Airtable_CreateField(Val Result, Val Option, Parameters = "", Name = "")

    ExpectsThat(Result["name"]).Равно(Name);

    Field = Result["id"];
    WriteParameter("Airtable_Field", Field);
    OPI_Tools.AddField("Airtable_Field", Field, "String", Parameters);

    Return Result;

EndFunction

Function Check_Airtable_ModifyField(Val Result, Val Option, Name = "", Description = "")

    ExpectsThat(Result["name"]).Равно(Name);
    ExpectsThat(Result["description"]).Равно(Description);

    Return Result;

EndFunction

Function Check_Airtable_CreatePosts(Val Result, Val Option, Parameters = "", Numeric = "", StringType = "")

    If Not ValueIsFilled(Option) Then

        ExpectsThat(Result["records"]).ИмеетТип("Array");
        ExpectsThat(Result["records"]).Заполнено();

    Else

        SingleRecord = Result["id"];
        ExpectsThat(SingleRecord).Заполнено();
        ExpectsThat(Result["createdTime"]).Заполнено();
        ExpectsThat(Result["fields"]["Number"]).Равно(Numeric);
        ExpectsThat(TrimAll(Result["fields"]["String"])).Равно(StringType);

        Record = Result["id"];
        WriteParameter("Airtable_Record", Record);
        OPI_Tools.AddField("Airtable_Record", Record, "String", Parameters);

    EndIf;

    Return Result;

EndFunction

Function Check_Airtable_GetRecord(Val Result, Val Option, Record = "")

    ExpectsThat(Result["id"]).Равно(Record);

    Return Result;

EndFunction

Function Check_Airtable_CreateComment(Val Result, Val Option, Parameters = "", Text = "")

    ExpectsThat(Result["text"]).Равно(Text);

    Comment = Result["id"];
    WriteParameter("Airtable_Comment", Comment);
    OPI_Tools.AddField("Airtable_Comment", Comment, "String", Parameters);

    Return Result;

EndFunction

Function Check_Airtable_EditComment(Val Result, Val Option, Text = "")

    ExpectsThat(Result["text"]).Равно(Text);

    Return Result;

EndFunction

Function Check_Airtable_GetComments(Val Result, Val Option)

    ExpectsThat(Result["comments"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Airtable_DeleteComment(Val Result, Val Option, Comment = "")

    ExpectsThat(Result["deleted"]).Равно(True);
    ExpectsThat(Result["id"]).Равно(Comment);

    Return Result;

EndFunction

Function Check_Airtable_GetListOfRecords(Val Result, Val Option, Comment = "")

    ExpectsThat(Result["records"]).ИмеетТип("Array");
    ExpectsThat(Result["records"]).Заполнено();

    Return Result;

EndFunction

Function Check_Airtable_DeleteRecords(Val Result, Val Option, Comment = "")

    ExpectsThat(Result["records"]).ИмеетТип("Array");
    ExpectsThat(Result["records"]).Заполнено();

    Return Result;

EndFunction

Function Check_Notion_CreatePage(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("page");

    Page = Result["id"];
    WriteParameter("Notion_Page", Page);
    OPI_Tools.AddField("Notion_Page", Page, "String", Parameters);

    Return Result;

EndFunction

Function Check_Notion_CreateDatabase(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("database");

    Base = Result["id"];
    WriteParameter("Notion_Base", Base);
    OPI_Tools.AddField("Notion_Base", Base, "String", Parameters);

    Return Result;

EndFunction

Function Check_Notion_EditDatabaseProperties(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("database");

    Return Result;

EndFunction

Function Check_Notion_GetPage(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("page");

    Return Result;

EndFunction

Function Check_Notion_GetDatabase(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("database");

    Return Result;

EndFunction

Function Check_Notion_CreatePageInDatabase(Val Result, Val Option, Base = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("page");

    Parent = Result["parent"]["database_id"];
    ExpectsThat(Parent).Равно(Base);

    Return Result;

EndFunction

Function Check_Notion_EditPageProperties(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("page");

    Return Result;

EndFunction

Function Check_Notion_ReturnBlock(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("block");

    Return Result;

EndFunction

Function Check_Notion_CreateBlock(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("list");

    Block = Result["results"][0]["id"];
    WriteParameter("Notion_NewBlock", Block);
    OPI_Tools.AddField("Notion_NewBlock", Block, "String", Parameters);

    Return Result;

EndFunction

Function Check_Notion_ReturnChildBlocks(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("list");

    Return Result;

EndFunction

Function Check_Notion_DeleteBlock(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("block");

    Return Result;

EndFunction

Function Check_Notion_UserList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("list");

    Return Result;

EndFunction

Function Check_Notion_GetUserData(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["object"]).Равно("user");

    Return Result;

EndFunction

Function Check_Dropbox_GetAuthorizationLink(Val Result, Val Option)

    If TypeOf(Result) = Type("BinaryData") Then
        Result = GetStringFromBinaryData(Result);
    EndIf;

    ExpectsThat(Result).ИмеетТип("String");
    ExpectsThat(StrStartWith(Result, "https://www.dropbox.com/oauth2")).Равно(True);

    Return Result;

EndFunction

Function Check_Dropbox_GetToken(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Token = Result["access_token"];
    Refresh = Result["refresh_token"];

    If ValueIsFilled(Token) Then
        WriteParameter("Dropbox_Token", Token);
    EndIf;

    If ValueIsFilled(Refresh) Then
        WriteParameter("Dropbox_Refresh", Refresh);
    EndIf;

    Return Undefined;

EndFunction

Function Check_Dropbox_RefreshToken(Val Result, Val Option)

    Token = Result["access_token"];

    ExpectsThat(Token).ИмеетТип("String").Заполнено();
    WriteParameter("Dropbox_Token", Token);

    Return Undefined;

EndFunction

Function Check_Dropbox_GetObjectInformation(Val Result, Val Option, Path = "")

    ExpectsThat(Result["path_display"]).Равно(Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_GetPreview(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() >= 1200).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_UploadFile(Val Result, Val Option, Path = "")

    ExpectsThat(Result["path_display"]).Равно(Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_UploadFileByURL(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["async_job_id"]).Заполнено();

    Work = Result["async_job_id"];
    Parameters.Insert("Dropbox_Job", Work);
    WriteParameter("Dropbox_Job", Work);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_GetUploadStatusByURL(Val Result, Val Option, Path = "")

    If Not ValueIsFilled(Option) Then

        ExpectsThat(Result[".tag"]).Равно("complete");

        OPI_Tools.Pause(2);

    EndIf;

    If Option = "Deletion" Then
        ExpectsThat(Result["metadata"]["path_display"]).Равно(Path);
    EndIf;

    Return Result;

EndFunction

Function Check_Dropbox_DeleteObject(Val Result, Val Option, Path = "")

    ExpectsThat(Result["metadata"]["path_display"]).Равно(Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_CopyObject(Val Result, Val Option, Path = "")

    ExpectsThat(Result["metadata"]["path_display"]).Равно(Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_MoveObject(Val Result, Val Option, Path = "")

    ExpectsThat(Result["metadata"]["path_display"]).Равно(Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_CreateFolder(Val Result, Val Option, Path = "")

    ExpectsThat(Result["metadata"]["path_display"]).Равно(Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_DownloadFile(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() >= 2000000).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_DownloadFolder(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() >= 200000).Равно(True);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_GetListOfFolderFiles(Val Result, Val Option)

    ExpectsThat(Result["entries"]).ИмеетТип("Array");

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_GetObjectVersionList(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["entries"]).ИмеетТип("Array");
    ExpectsThat(Result["entries"].Count()).Равно(1);

    Revision = Result["entries"][0]["rev"];

    Parameters.Insert("Dropbox_FileRevision", Revision);
    WriteParameter("Dropbox_FileRevision", Revision);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_RestoreObjectToVersion(Val Result, Val Option, Path = "")

    ExpectsThat(Result["path_display"]).Равно(Path);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_GetTagList(Val Result, Val Option, Parameters = "", PathsArray = "")

    ExpectsThat(Result["paths_to_tags"]).ИмеетТип("Array");
    ExpectsThat(Result["paths_to_tags"].Count()).Равно(PathsArray.Count());

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_AddTag(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_DeleteTag(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_GetAccountInformation(Val Result, Val Option)

    ExpectsThat(Result["account_id"]).Заполнено();

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_GetSpaceUsageData(Val Result, Val Option)

    ExpectsThat(Result["used"]).Заполнено();

    Return Result;

EndFunction

Function Check_Dropbox_AddUsersToFile(Val Result, Val Option, Email = "", ViewOnly = "")

    ExpectsThat(Result[0]["result"][".tag"]).Равно("success");
    ExpectsThat(Result[0]["member"]["email"]).Равно(Email);
    ExpectsThat(Result[0]["result"]["success"][".tag"]).Равно(?(ViewOnly, "viewer", "editor"));

    Return Result;

EndFunction

Function Check_Dropbox_PublishFolder(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["shared_folder_id"]).Заполнено();

    FolderID = Result["shared_folder_id"];

    Parameters.Insert("Dropbox_SharedFolder", FolderID);
    WriteParameter("Dropbox_SharedFolder", FolderID);

    OPI_Tools.Pause(2);

    Return Result;

EndFunction

Function Check_Dropbox_CancelFolderPublication(Val Result, Val Option, Parameters = "", JobID = "")

    If ValueIsFilled(Option) Then

        ExpectsThat(Result[".tag"]).Равно("complete");

        Parameters.Insert("Dropbox_NewJobID", JobID);
        WriteParameter("Dropbox_NewJobID", JobID);

        OPI_Tools.Pause(2);

    EndIf;

    Return Result;

EndFunction

Function Check_Dropbox_GetAsynchronousChangeStatus(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_Dropbox_AddUsersToFolder(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_Dropbox_CancelFilePublication(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_Bitrix24_GetAppAuthLink(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("String");

    WriteParameter("Bitrix24_AuthURL", Result);

    Return Result;

EndFunction

Function Check_Bitrix24_GetToken(Val Result, Val Option)

    If ValueIsFilled(Result["access_token"]) And ValueIsFilled(Result["refresh_token"]) Then

        WriteParameter("Bitrix24_Token" , Result["access_token"]);
        WriteParameter("Bitrix24_Refresh", Result["refresh_token"]);

    EndIf;

    Return Undefined;

EndFunction

Function Check_Bitrix24_RefreshToken(Val Result, Val Option)

    ExpectsThat(Result["access_token"]).Заполнено();
    ExpectsThat(Result["refresh_token"]).Заполнено();

    If ValueIsFilled(Result["access_token"]) And ValueIsFilled(Result["refresh_token"]) Then

        WriteParameter("Bitrix24_Token" , Result["access_token"]);
        WriteParameter("Bitrix24_Refresh", Result["refresh_token"]);

    EndIf;

    Return Undefined;

EndFunction

Function Check_Bitrix24_ServerTime(Val Result, Val Option)

    Time = Result["result"];

    If Not TypeOf(Time) = Type("Date") Then
        Time = XMLValue(Type("Date"), Time);
    EndIf;

    ExpectsThat(Time).ИмеетТип("Date").Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_CreatePost(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookPostID";
    Else
        ParameterName = "Bitrix24_PostID";
    EndIf;

    PostID = Result["result"];

    WriteParameter(ParameterName, PostID);
    Parameters.Insert(ParameterName, PostID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdatePost(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_DeletePost(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetImportantPostViewers(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_GetPosts(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");
    ExpectsThat(Result["result"][0]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_AddPostComment(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_AddPostRecipients(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetTaskFieldsStructure(Val Result, Val Option)

    ExpectsThat(Result["result"]["fields"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_CreateTask(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]["task"]).Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookTaskID";
    Else
        ParameterName = "Bitrix24_TaskID";
    EndIf;

    TaskID = Result["result"]["task"]["id"];

    WriteParameter(ParameterName, TaskID);
    Parameters.Insert(ParameterName, TaskID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_ApproveTask(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["error"]).Равно("1048582");

    Return Undefined;

EndFunction

Function Check_Bitrix24_DisapproveTask(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(Result["error"]).Равно("1048582");

    Return Undefined;

EndFunction

Function Check_Bitrix24_CompleteTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_RenewTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_DeferTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_StartTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_StartWatchingTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_StopWatchingTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_PauseTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_DelegateTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_AddTaskToFavorites(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_RemoveTaskFromFavorites(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetTaskHistory(Val Result, Val Option)

    ExpectsThat(Result["result"]["list"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_GetTasksList(Val Result, Val Option)

    ExpectsThat(Result["result"]["tasks"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_GetStoragesList(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");
    ExpectsThat(Result["total"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetAppStorage(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    StorageID = Result["result"]["ID"];
    WriteParameter("Bitrix24_StorageID", StorageID);
    Parameters.Insert("Bitrix24_StorageID", StorageID);

    Return Result;

EndFunction

Function Check_Bitrix24_UploadFileToStorage(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookFileID";
    Else
        ParameterName = "Bitrix24_FileID";
    EndIf;

    FileID = Result["result"]["ID"];

    WriteParameter(ParameterName, FileID);
    Parameters.Insert(ParameterName, FileID);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteFile(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_CreateStorageFolder(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookFolderID";
    Else
        ParameterName = "Bitrix24_FolderID";
    EndIf;

    FolderID = Result["result"]["ID"];

    WriteParameter(ParameterName, FolderID);
    Parameters.Insert(ParameterName, FolderID);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteFolder(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetStorage(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetStorageObjects(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_RenameStorage(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetFolderInformation(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_CreateSubfolder(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookSubfolderID";
    Else
        ParameterName = "Bitrix24_SubfolderID";
    EndIf;

    SubfolderID = Result["result"]["ID"];

    WriteParameter(ParameterName, SubfolderID);
    Parameters.Insert(ParameterName, SubfolderID);

    Return Result;

EndFunction

Function Check_Bitrix24_MakeFolderCopy(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetFolderExternalLink(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetFolderFilterStructure(Val Result, Val Option)

    ResultType = TypeOf(Result);

    ExpectsThat(ResultType = Type("Structure") Or ResultType = Type("Map")).Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetFolderItems(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_MarkFolderAsDeleted(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_RestoreFolder(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_MoveFolder(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_RenameFolder(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_UploadFileToFolder(Val Result, Val Option, URL = "", Token = "")

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_MakeFileCopy(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetFileInformation(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetFileExternalLink(Val Result, Val Option)

    Return Undefined;

EndFunction

Function Check_Bitrix24_MarkFileAsDeleted(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_RestoreFile(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_RenameFile(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_MoveFileToFolder(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_AttachFileToTopic(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["attachmentId"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_CheckTaskAccesses(Val Result, Val Option, Count = "")

    ExpectsThat(Result["result"]).ИмеетТип("Map");

    Actions = Result["result"]["allowedActions"];
    ExpectsThat(Actions).ИмеетТип("Map");
    ExpectsThat(Actions.Count()).Равно(Count);

    Return Result;

EndFunction

Function Check_Bitrix24_MuteTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_UnmuteTask(Val Result, Val Option)

    ExpectsThat(Result["result"]["task"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_AddTaskComment(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookCommentID";
    Else
        ParameterName = "Bitrix24_CommentID";
    EndIf;

    CommentID = Result["result"];

    WriteParameter(ParameterName, CommentID);
    Parameters.Insert(ParameterName, CommentID);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteTaskComment(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_CreateResultFromComment(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["text"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteResultFromComment(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Undefined");
    ExpectsThat(Result["time"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetResultsList(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");
    ExpectsThat(Result["result"][0]["text"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetTaskCommentsList(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");
    ExpectsThat(Result["result"][0]["POST_MESSAGE"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetTaskComment(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateTaskComment(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map").Заполнено();
    ExpectsThat(StrFind(Result["error_description"], "not allowed") > 0).Равно(True);

    Return Undefined;

EndFunction

Function Check_Bitrix24_CreateTasksDependencies(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteTasksDependencies(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_AddKanbanStage(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookStageID";
    Else
        ParameterName = "Bitrix24_StageID";
    EndIf;

    StageID = Result["result"];

    WriteParameter(ParameterName, StageID);
    Parameters.Insert(ParameterName, StageID);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteKanbanStage(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetKanbanStages(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_Bitrix24_MoveTaskToKanbanStage(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateKanbansStage(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_AddTasksChecklistElement(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookCheckElementID";
    Else
        ParameterName = "Bitrix24_CheckElementID";
    EndIf;

    ElementID = Result["result"];

    WriteParameter(ParameterName, ElementID);
    Parameters.Insert(ParameterName, ElementID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateTasksChecklistElement(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Undefined");
    ExpectsThat(Result["time"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteTasksChecklistElement(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetTasksChecklist(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_GetTasksChecklistElement(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_CompleteTasksChecklistElement(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_RenewTasksChecklistElement(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_AddTaskTimeAccounting(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookTimeID";
    Else
        ParameterName = "Bitrix24_TimeID";
    EndIf;

    SpendingID = Result["result"];

    WriteParameter(ParameterName, SpendingID);
    Parameters.Insert(ParameterName, SpendingID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateTaskTimeAccounting(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Undefined");
    ExpectsThat(Result["time"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteTaskTimeAccounting(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Undefined");
    ExpectsThat(Result["time"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetTaskTimeAccounting(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetTaskTimeAccountingList(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");
    ExpectsThat(Result["result"][0]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetDailyPlan(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_CreateChat(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookChatID";
    Else
        ParameterName = "Bitrix24_ChatID";
    EndIf;

    ChatID = Result["result"];

    WriteParameter(ParameterName, ChatID);
    Parameters.Insert(ParameterName, ChatID);

    Return Result;

EndFunction

Function Check_Bitrix24_GetChatUsers(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_LeaveChat(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteUserFromChat(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_AddUsersToChat(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_ChangeChatTitle(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_ChangeChatColor(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    OPI_Tools.Pause(10);

    Return Result;

EndFunction

Function Check_Bitrix24_ChangeChatPicture(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_DisableChatNotifications(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_EnableChatNotifications(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_ChangeChatOwner(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetChatMessagesList(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]["messages"]).ИмеетТип("Array");

    If Option = "Hook" Then
        ParameterName = "Bitrix24_ChatMessageID";
    Else
        ParameterName = "Bitrix24_UserMessageID";
    EndIf;

    MessageID = Result["result"]["messages"][0]["id"];

    WriteParameter(ParameterName, MessageID);
    Parameters.Insert(ParameterName, MessageID);

    Return Result;

EndFunction

Function Check_Bitrix24_MarkMessageAsReaded(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");

    Return Undefined;

EndFunction

Function Check_Bitrix24_MarkMessageAsUnreaded(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetDialog(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["id"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetChatMembersList(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_SendWritingNotification(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_ReadAll(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_SendMessage(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_ChatMessageID";
    Else
        ParameterName = "Bitrix24_UserMessageID";
    EndIf;

    MessageID = Result["result"];

    WriteParameter(ParameterName, MessageID);
    Parameters.Insert(ParameterName, MessageID);

    Return Result;

EndFunction

Function Check_Bitrix24_EditMessage(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteMessage(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_SetMessageReaction(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetChatFilesFolder(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_SendFile(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["MESSAGE_ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetUsers(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_Bitrix24_GetUserStatus(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_SetUserStatus(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_CreatePersonalNotification(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_PersonalHookNotifyID";
    Else
        ParameterName = "Bitrix24_PersonalNotifyID";
    EndIf;

    MessageID = Result["result"];

    WriteParameter(ParameterName, MessageID);
    Parameters.Insert(ParameterName, MessageID);

    Return Result;

EndFunction

Function Check_Bitrix24_CreateSystemNotification(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_SystemHookNotifyID";
    Else
        ParameterName = "Bitrix24_SystemNotifyID";
    EndIf;

    MessageID = Result["result"];

    WriteParameter(ParameterName, MessageID);
    Parameters.Insert(ParameterName, MessageID);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteNotification(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean");

    Return Result;

EndFunction

Function Check_Bitrix24_CreateDepartment(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookDepID";
    Else
        ParameterName = "Bitrix24_DepID";
    EndIf;

    DepartmentID = Result["result"];

    WriteParameter(ParameterName, DepartmentID);
    Parameters.Insert(ParameterName, DepartmentID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateDepartment(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteDepartment(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetDepartments(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_GetCurrentUser(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetUserFieldsStructure(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");
    ExpectsThat(Result["result"]["ID"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_CreateUser(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookUserID";
    Else
        ParameterName = "Bitrix24_UserID";
    EndIf;

    UserID = Result["result"];

    WriteParameter(ParameterName, UserID);
    Parameters.Insert(ParameterName, UserID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateUser(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_ChangeUserStatus(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetUser(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_FindUsers(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_GetLeadFilterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetLeadStructure(Val Result, Val Option)

    ExpectsThat(Result["result"]["PHONE"]).Заполнено();
    ExpectsThat(Result["result"]["NAME"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_CreateLead(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookLeadID";
    Else
        ParameterName = "Bitrix24_LeadID";
    EndIf;

    LeadID = Result["result"];

    WriteParameter(ParameterName, LeadID);
    Parameters.Insert(ParameterName, LeadID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateLead(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteLead(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetLead(Val Result, Val Option)

    ExpectsThat(Result["result"]["PHONE"]).Заполнено();
    ExpectsThat(Result["result"]["NAME"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetLeadsList(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_GetDealsFilterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetDealStructure(Val Result, Val Option)

    ExpectsThat(Result["result"]["ID"]).Заполнено();
    ExpectsThat(Result["result"]["BEGINDATE"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_CreateDeal(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookDealID";
    Else
        ParameterName = "Bitrix24_DealID";
    EndIf;

    DealID = Result["result"];

    WriteParameter(ParameterName, DealID);
    Parameters.Insert(ParameterName, DealID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateDeal(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetDeal(Val Result, Val Option)

    ExpectsThat(Result["result"]["ID"]).Заполнено();
    ExpectsThat(Result["result"]["BEGINDATE"]).Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteDeal(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetDealsList(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_GetTasksFilterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetCommentStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetChatStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetPictureBlock(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetFileBlock(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetUserFilterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_CreateCalendar(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookCalendarID";
    Else
        ParameterName = "Bitrix24_CalendarID";
    EndIf;

    CalendarID = Result["result"];

    WriteParameter(ParameterName, CalendarID);
    Parameters.Insert(ParameterName, CalendarID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateCalendar(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteCalendar(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetCalendarStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_Bitrix24_GetCalendarList(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_GetCalendarSettingsStructure(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_Bitrix24_GetCalednarCustomSettingsStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_Bitrix24_GetCustomCalendarSettings(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_Bitrix24_SetCustomCalendarSettings(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetUserBusy(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_Bitrix24_CreateCalendarEvent(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookCEventID";
    Else
        ParameterName = "Bitrix24_CEventID";
    EndIf;

    EventID = Result["result"];

    WriteParameter(ParameterName, EventID);
    Parameters.Insert(ParameterName, EventID);

    Return Result;

EndFunction

Function Check_Bitrix24_UpdateCalendarEvent(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["result"]).ИмеетТип("Number").Заполнено();

    If Option = "Hook" Then
        ParameterName = "Bitrix24_HookCEventID";
    Else
        ParameterName = "Bitrix24_CEventID";
    EndIf;

    EventID = Result["result"];

    WriteParameter(ParameterName, EventID);
    Parameters.Insert(ParameterName, EventID);

    Return Result;

EndFunction

Function Check_Bitrix24_DeleteCalendarEvent(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetCalendarEvent(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_Bitrix24_GetCalendarEvents(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Bitrix24_SetUserParticipationStatus(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("Boolean").Равно(True);

    Return Result;

EndFunction

Function Check_Bitrix24_GetUserParticipationStatus(Val Result, Val Option)

    ExpectsThat(Result["result"]).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_Bitrix24_GetCalendarEventsStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_Bitrix24_GetCalendarEventsFilterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_VKTeams_CheckToken(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["userId"]).Заполнено();

    Return Result;

EndFunction

Function Check_VKTeams_GetEvents(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["events"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_VKTeams_SendTextMessage(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["msgId"]).Заполнено();

    If Not ValueIsFilled(Option) Then

        MessageID = Result["msgId"];
        WriteParameter("VKTeams_MessageID", MessageID);
        Parameters.Insert("VKTeams_MessageID", MessageID);

    EndIf;

    Return Result;

EndFunction

Function Check_VKTeams_ForwardMessage(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["msgId"]).Заполнено();

    Return Result;

EndFunction

Function Check_VKTeams_SendFile(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["msgId"]).Заполнено();

    If Not ValueIsFilled(Option) Then

        FileID = Result["fileId"];
        WriteParameter("VKTeams_FileID", FileID);
        Parameters.Insert("VKTeams_FileID", FileID);

        OPI_Tools.Pause(2);

    EndIf;

    Return Result;

EndFunction

Function Check_VKTeams_ResendFile(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["msgId"]).Заполнено();

    Return Result;

EndFunction

Function Check_VKTeams_GetFileInformation(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["type"]).Заполнено();
    ExpectsThat(Result["size"]).Заполнено();

    Return Result;

EndFunction

Function Check_VKTeams_EditMessageText(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_DeleteMessage(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_SendVoice(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["msgId"]).Заполнено();

    If Not ValueIsFilled(Option) Then

        FileID = Result["fileId"];
        WriteParameter("VKTeams_VoiceID", FileID);
        Parameters.Insert("VKTeams_VoiceID", FileID);

        OPI_Tools.Pause(2);

    EndIf;

    Return Result;

EndFunction

Function Check_VKTeams_ResendVoice(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);
    ExpectsThat(Result["msgId"]).Заполнено();

    Return Result;

EndFunction

Function Check_VKTeams_RemoveChatMembers(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_ChangeChatPicture(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_GetChatInfo(Val Result, Val Option)

    ExpectsThat(Result["type"]).Заполнено();
    ExpectsThat(Result["inviteLink"]).Заполнено();

    Return Result;

EndFunction

Function Check_VKTeams_GetChatAdmins(Val Result, Val Option)

    ExpectsThat(Result["admins"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_VKTeams_GetChatMembers(Val Result, Val Option)

    ExpectsThat(Result["members"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_VKTeams_GetChatBlockedUsers(Val Result, Val Option)

    ExpectsThat(Result["users"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_VKTeams_GetChatJoinRequests(Val Result, Val Option)

    ExpectsThat(Result["users"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_VKTeams_BlockChatUser(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_UnblockChatUser(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_PinMessage(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_UnpinMessage(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_ApprovePending(Val Result, Val Option)

    If Not Result["ok"] Then
        ExpectsThat(Result["description"]).Равно("User is not pending or nobody in pending list");
    EndIf;

    Return Result;

EndFunction

Function Check_VKTeams_DisapprovePending(Val Result, Val Option)

    If Not Result["ok"] Then
        ExpectsThat(Result["description"]).Равно("User is not pending or nobody in pending list");
    EndIf;

    Return Result;

EndFunction

Function Check_VKTeams_SetChatTitle(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_SetChatDescription(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_SetChatRules(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_VKTeams_AnswerButtonEvent(Val Result, Val Option)

    ExpectsThat(Result["ok"]).Равно(True);

    Return Result;

EndFunction

Function Check_Neocities_UploadFile(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно("success");

    Return Result;

EndFunction

Function Check_Neocities_UploadFiles(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно("success");

    Return Result;

EndFunction

Function Check_Neocities_DeleteSelectedFiles(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно("success");

    Return Result;

EndFunction

Function Check_Neocities_GetFilesList(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно("success");

    Return Result;

EndFunction

Function Check_Neocities_GetSiteData(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно("success");

    Return Result;

EndFunction

Function Check_Neocities_GetToken(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно("success");

    Return Result;

EndFunction

Function Check_Neocities_SynchronizeFolders(Val Result, Val Option)

    ExpectsThat(Result["errors"]).Равно(0);
    ExpectsThat(Result["items"].Count()).Равно(0);

    Return Result;

EndFunction

Function Check_CDEK_GetToken(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["access_token"]).Заполнено();
    ExpectsThat(Result["expires_in"]).Заполнено();
    ExpectsThat(Result["token_type"]).Заполнено();

    Token = Result["access_token"];
    WriteParameter("CDEK_Token", Token);
    OPI_Tools.AddField("CDEK_Token", Token, "String", Parameters);

    Return Result;

EndFunction

Function Check_CDEK_GetOrderDescription(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_CreateOrder(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    UUID = Result["entity"]["uuid"];
    WriteParameter("CDEK_OrderUUID", UUID);
    OPI_Tools.AddField("CDEK_OrderUUID", UUID, "String", Parameters);

    Return Result;

EndFunction

Function Check_CDEK_GetOrder(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["entity"]["number"]).Заполнено();

    IMNumber = Result["entity"]["number"];
    WriteParameter("CDEK_OrderIMN", IMNumber);
    OPI_Tools.AddField("CDEK_OrderIMN", IMNumber, "String", Parameters);

    Return Result;

EndFunction

Function Check_CDEK_GetOrderByNumber(Val Result, Val Option)

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["entity"]["number"]).Заполнено();

    Return Result;

EndFunction

Function Check_CDEK_UpdateOrder(Val Result, Val Option)

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_DeleteOrder(Val Result, Val Option)

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_CreateCustomerRefund(Val Result, Val Option)

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_CreateRefusal(Val Result, Val Option)

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_GetCourierInvitationsDescription(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_CreateCourierInvitation(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    UUID = Result["entity"]["uuid"];
    WriteParameter("CDEK_IntakeUUID", UUID);
    OPI_Tools.AddField("CDEK_IntakeUUID", UUID, "String", Parameters);

    Return Result;

EndFunction

Function Check_CDEK_GetCourierInvitation(Val Result, Val Option)

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_DeleteCourierInvitation(Val Result, Val Option)

    // ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    // ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    // Status = Result["requests"][0]["state"];

    // ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    Return Undefined;

EndFunction

Function Check_CDEK_CreateReceipt(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    UUID = Result["entity"]["uuid"];
    WriteParameter("CDEK_PrintUUID", UUID);
    OPI_Tools.AddField("CDEK_PrintUUID", UUID, "String", Parameters);

    Return Result;

EndFunction

Function Check_CDEK_GetReceipt(Val Result, Val Option)

    ExpectsThat(Result["entity"]["statuses"][0]["code"]).Равно("ACCEPTED");
    ExpectsThat(Result["entity"]["copy_count"]).Равно(1);

    Return Result;

EndFunction

Function Check_CDEK_CreateBarcode(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    UUID = Result["entity"]["uuid"];
    WriteParameter("CDEK_BarcodeUUID", UUID);
    OPI_Tools.AddField("CDEK_BarcodeUUID", UUID, "String", Parameters);

    Return Result;

EndFunction

Function Check_CDEK_GetBarcode(Val Result, Val Option)

    ExpectsThat(Result["entity"]["statuses"][0]["code"]).Равно("ACCEPTED");
    ExpectsThat(Result["entity"]["copy_count"]).Равно(1);

    Return Result;

EndFunction

Function Check_CDEK_GetAvailableDeliveryIntervals(Val Result, Val Option)

    ExpectsThat(Result["date_intervals"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_CDEK_GetAppointmentDescription(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_RegisterDeliveryAppointment(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    UUID = Result["entity"]["uuid"];
    WriteParameter("CDEK_ApptUUID", UUID);
    OPI_Tools.AddField("CDEK_ApptUUID", UUID, "String", Parameters);

    Return Result;

EndFunction

Function Check_CDEK_GetDeliveryAppointment(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_CreatePrealert(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["entity"]["uuid"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    UUID = Result["entity"]["uuid"];
    WriteParameter("CDEK_PrealertUUID", UUID);
    OPI_Tools.AddField("CDEK_PrealertUUID", UUID, "String", Parameters);

    Return Result;

EndFunction

Function Check_CDEK_GetPrealert(Val Result, Val Option)

    ExpectsThat(Result["entity"]["shipment_point"]).Заполнено();
    ExpectsThat(Result["requests"]).ИмеетТип("Array").Заполнено();

    Status = Result["requests"][0]["state"];

    ExpectsThat(Status = "ACCEPTED" Or Status = "SUCCESSFUL").Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_GetPassportDataStatus(Val Result, Val Option)

    ExpectsThat(Result["orders"][0]["passport"][0]["client"]).Равно("SENDER");
    ExpectsThat(Result["orders"][0]["passport"][1]["client"]).Равно("RECEIVER");

    Return Result;

EndFunction

Function Check_CDEK_GetCashboxCheck(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_GetCashboxChecksByDate(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_GetDeliveryCashRegistry(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_GetDeliveryCashTransfers(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_GetOfficeFilterDescription(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_CDEK_GetOfficeList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_CDEK_GetRegionsList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_YandexMetrika_GetTagsList(Val Result, Val Option)

    ExpectsThat(Result["labels"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_YandexMetrika_CreateTag(Val Result, Val Option, Parameters = "", Name = "")

    ExpectsThat(Result["label"]).ИмеетТип("Map");
    ExpectsThat(Result["label"]["id"]).Заполнено();

    If ValueIsFilled(Name) Then
        ExpectsThat(Result["label"]["name"]).Равно(Name);
    EndIf;

    TagID = Result["label"]["id"];
    WriteParameter("Metrika_LabelID", TagID);
    OPI_Tools.AddField("Metrika_LabelID", TagID, "String", Parameters);

    Return Result;

EndFunction

Function Check_YandexMetrika_DeleteTag(Val Result, Val Option)

    ExpectsThat(Result["success"]).Равно(True);

    Return Result;

EndFunction

Function Check_YandexMetrika_UpdateTag(Val Result, Val Option, Name = "")

    ExpectsThat(Result["label"]).ИмеетТип("Map");
    ExpectsThat(Result["label"]["id"]).Заполнено();

    If ValueIsFilled(Name) Then
        ExpectsThat(Result["label"]["name"]).Равно(Name);
    EndIf;

    Return Result;

EndFunction

Function Check_YandexMetrika_GetTag(Val Result, Val Option)

    ExpectsThat(Result["label"]).ИмеетТип("Map");
    ExpectsThat(Result["label"]["id"]).Заполнено();

    Return Result;

EndFunction

Function Check_YandexMetrika_GetCounterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_YandexMetrika_CreateCounter(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["counter"]).ИмеетТип("Map").Заполнено();

    CounterID = Result["counter"]["id"];
    WriteParameter("Metrika_CounterID", CounterID);
    OPI_Tools.AddField("Metrika_CounterID", CounterID, "String", Parameters);

    Return Result;

EndFunction

Function Check_YandexMetrika_DeleteCounter(Val Result, Val Option)

    ExpectsThat(Result["success"]).Равно(True);

    Return Result;

EndFunction

Function Check_YandexMetrika_UpdateCounter(Val Result, Val Option)

    ExpectsThat(Result["counter"]).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_YandexMetrika_GetCounter(Val Result, Val Option)

    ExpectsThat(Result["counter"]).ИмеетТип("Map").Заполнено();

    Return Result;

EndFunction

Function Check_YandexMetrika_RestoreCounter(Val Result, Val Option)

    ExpectsThat(Result["success"]).Равно(True);

    Return Result;

EndFunction

Function Check_YandexMetrika_GetCountersList(Val Result, Val Option)

    ExpectsThat(Result["counters"]).ИмеетТип("Array").Заполнено();

    Return Result;

EndFunction

Function Check_YandexMetrika_GetActionsList(Val Result, Val Option)

    ExpectsThat(Result["operations"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_S3_GetBasicDataStructure(Val Result, Val Option)

    Result["SecretKey"] = "***";

    Return Result;

EndFunction

Function Check_S3_SendRequestWithoutBody(Val Result, Val Option)

    Return Undefined;

EndFunction

Function Check_S3_SendRequestWithBody(Val Result, Val Option)

    Return Undefined;

EndFunction

Function Check_S3_CreateBucket(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then
        Success = Result["status"] >= 200 And Result["status"] < 300;
        ExpectsThat(Success).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_S3_DeleteBucket(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_ListBuckets(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_HeadBucket(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_GetBucketEncryption(Val Result, Val Option)

    Return Undefined;

EndFunction

Function Check_S3_DeleteBucketEncryption(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_PutBucketEncryption(Val Result, Val Option)

    Success = Result["status"] = 501;
    ExpectsThat(Success).Равно(True);

    Return Undefined;

EndFunction

Function Check_S3_GetBucketTagging(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_PutBucketTagging(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_DeleteBucketTagging(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_GetBucketVersioning(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_PutBucketVersioning(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_PutObject(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_UploadFullObject(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_DeleteObject(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_HeadObject(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_CopyObject(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_PutObjectTagging(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_GetObjectTagging(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_DeleteObjectTagging(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_ListObjects(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_ListObjectVersions(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_GetObject(Val Result, Val Option, Size = "")

    If Option = "File" Or Option = "Big file" Then

        If Not TypeOf(Result) = Type("BinaryData") Then

            Result = New File(Result);
            ExpectsThat(Result).ИмеетТип("File");
            ExpectsThat(Result.Exists()).Равно(True);

        EndIf;

    Else
        ExpectsThat(Result).ИмеетТип("BinaryData");
    EndIf;

    ExpectsThat(Result.Size() >= Size).Равно(True);

    Return Result;

EndFunction

Function Check_S3_InitPartsUpload(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_FinishPartsUpload(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_UploadObjectPart(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_AbortMultipartUpload(Val Result, Val Option)

    Success = Result["status"] >= 200 And Result["status"] < 300;
    ExpectsThat(Success).Равно(True);

    Return Result;

EndFunction

Function Check_S3_GetObjectDownloadLink(Val Result, Val Option, Size = "")

    If Not ValueIsFilled(Option) Then
        ExpectsThat(Result).ИмеетТип("String");
    Else
        ExpectsThat(Result).ИмеетТип("BinaryData");
        ExpectsThat(Result.Size() >= Size).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_S3_GetObjectUploadLink(Val Result, Val Option, Size = "")

    If Not ValueIsFilled(Option) Then
        ExpectsThat(Result).ИмеетТип("String");
    ElsIf Option = "Check" Then
        ExpectsThat(Number(Result["headers"]["Content-Length"])).Равно(Size);
    EndIf;

    Return Result;

EndFunction

Function Check_TCP_CloseConnection(Val Result, Val Option)

    ExpectsThat(Result).Равно(True);

    Return Result;

EndFunction

Function Check_TCP_CreateConnection(Val Result, Val Option)

    Result = String(TypeOf(Result));

    ExpectsThat(Result).Равно("AddIn.OPI_TCPClient.Main");

    Return Result;

EndFunction

Function Check_TCP_ReadBinaryData(Val Result, Val Option, Message = "")

    Result = GetStringFromBinaryData(Result);

    ExpectsThat(Result).Равно(Message);

    Return Result;

EndFunction

Function Check_TCP_SendBinaryData(Val Result, Val Option, Message = "")

    Result = GetStringFromBinaryData(Result);

    ExpectsThat(Result).Равно(Message);

    Return Result;

EndFunction

Function Check_TCP_ProcessRequest(Val Result, Val Option, Message = "")

    ExpectsThat(Result).Равно(Message);

    Return Result;

EndFunction

Function Check_TCP_ReadLine(Val Result, Val Option, Message = "")

    ExpectsThat(Result).Равно(Message);

    Return Result;

EndFunction

Function Check_TCP_SendLine(Val Result, Val Option, Message = "")

    ExpectsThat(Result).Равно(Message);

    Return Result;

EndFunction

Function Check_TCP_GetTlsSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_TCP_GetLastError(Val Result, Val Option)

    Return Result;

EndFunction

Function Check_TCP_GetProxySettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Result["password"] = "***";

    Return Result;

EndFunction

Function Check_TCP_StartServer(Val Result, Val Option)

    Result = String(TypeOf(Result));

    ExpectsThat(Result).Равно("AddIn.OPI_TCPServer.Main");

    Return Result;

EndFunction

Function Check_TCP_StopServer(Val Result, Val Option)

    If Option = "List" Then
        // After stopping the server, an attempt to get the list should return an error
        ExpectsThat(Result["result"]).Равно(False);
        ExpectsThat(ValueIsFilled(Result["error"])).Равно(True);
    ElsIf Option = "Connection" Then
        // Attempting to connect to a stopped server should return an error
        ExpectsThat(TypeOf(Result)).Равно(Type("Map"));
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_TCP_GetNextConnectionData(Val Result, Val Option, Message = "")

    If Option = "Closed" Then
        ExpectsThat(Result["result"]).Равно(False);
        ExpectsThat(Result["error"]).Равно("timeout");
    Else

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(ValueIsFilled(Result["connectionId"])).Равно(True);

        Data = Result["message"];
        Data = GetStringFromBinaryData(Data);

        ExpectsThat(Data).Равно(Message);

        Result["message"] = "<BinaryData>";

    EndIf;

    Return Result;

EndFunction

Function Check_TCP_GetConnectionData(Val Result, Val Option, Message = "")

    If Option = "Empty" Or Option = "Closed" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else

        ExpectsThat(Result["result"]).Равно(True);

        If Option = "EmptyList" Then
            ExpectsThat(Result["connections"].Count()).Равно(0);
        Else

            Data = Result["message"];
            Data = GetStringFromBinaryData(Data);

            ExpectsThat(Data).Равно(Message);

            Result["message"] = "<BinaryData>";

        EndIf;

    EndIf;

    Return Result;

EndFunction

Function Check_TCP_SendData(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result).Равно(Message);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_TCP_CloseIncomingConnection(Val Result, Val Option)

    If Option = "EmptyList" Then

        ExpectsThat(Result["connections"].Count()).Равно(0);

    ElsIf Option = "SendingToClosed" Then

        ExpectsThat(Result).Равно(False);

    Else

        ExpectsThat(Result["result"]).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_TCP_CompleteSend(Val Result, Val Option)

    If Option = "SendingServer" Then

        ExpectsThat(Result["error"]).Равно("Write half is closed");

    ElsIf Option = "SendingClient" Then

        ExpectsThat(Result).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_TCP_FinishReceiving(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_TCP_GetConnectionList(Val Result, Val Option)

    If Option = "Closing" Or IsCLITest() Then
        ExpectsThat(Result["connections"].Count()).Равно(1);
    Else
        ExpectsThat(Result["connections"].Count()).Равно(2);
    EndIf;

    Return Result;

EndFunction

Function Check_TCP_GetLog(Val Result, Val Option, LogFile = "")

    If StrFind(Option, "AsString") > 0 Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    EndIf;

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_TCP_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_TCP_IsServerObject(Val Result, Val Option)

    If Option = "False" Then
        ExpectsThat(Result).Равно(False);
    Else
        ExpectsThat(Result).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_TCP_Extended_GetDataOfNextTimeout(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(Result["error"]).Равно("timeout");

    Return Result;

EndFunction

Function Check_TCP_Extended_OperationWithoutStart(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "not started") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_TCP_Extended_GetLogOnServerStart(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_TCP_Extended_ReadTimeout(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_TCP_Extended_OperationWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "no connection") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_TCP_Extended_JanxCollectionExchange(Val Result, Val Option, Restored = Undefined, InitialValue = Undefined)

    ExpectsThat(TypeOf(Result)).Равно(Type("BinaryData"));
    CheckMapJanx(Restored, InitialValue);

    Return Result;

EndFunction

Function Check_TCP_Extended_GetLogOnConnectionOpening(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_WebSocket_CreateConnection(Val Result, Val Option)

    Result = String(TypeOf(Result));
    ExpectsThat(Result).Равно("AddIn.OPI_WSClient.Main");

    Return Result;

EndFunction

Function Check_WebSocket_CloseConnection(Val Result, Val Option)

    If Left(Option, 8) = "Openning" Then
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_WSClient.Main");
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_SendPing(Val Result, Val Option)

    If Left(Option, 8) = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["type"]).Равно("pong");
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_SendPong(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_WebSocket_GetMessage(Val Result, Val Option, Message = "")

    ExpectsThat(Result["result"]).Равно(True);

    If StrFind(Option, "Sending") = 0 Then
        ExpectsThat(Result["type"]).Равно("text");
        ExpectsThat(Result["data"]["payload"]).Равно(Message);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_SendTextMessage(Val Result, Val Option, Message = "")

    If Left(Option, 8) = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["type"]).Равно("text");
        ExpectsThat(Result["data"]["payload"]).Равно(Message);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_SendBinaryMessage(Val Result, Val Option, Message = "")

    If Left(Option, 8) = "Check" Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["type"]).Равно("binary");

        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);

        Result["data"] = "<BinaryData>";

    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_GetTlsSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_WebSocket_GetProxySettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "server")).Равно(True);
    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "port")).Равно(True);
    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "proxy_type")).Равно(True);

    ExpectsThat(ValueIsFilled(Result["server"])).Равно(True);
    ExpectsThat(TypeOf(Result["port"]) = Type("Number")).Равно(True);
    ExpectsThat(ValueIsFilled(Result["proxy_type"])).Равно(True);

    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "login")).Равно(True);
    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "password")).Равно(True);
    ExpectsThat(ValueIsFilled(Result["login"])).Равно(True);
    ExpectsThat(ValueIsFilled(Result["password"])).Равно(True);

    Result["password"] = "***";

    Return Result;

EndFunction

Function Check_WebSocket_IsClientObject(Val Result, Val Option)

    If StrFind(Option, "False") > 0 Then
        ExpectsThat(Result).Равно(False);
    Else
        ExpectsThat(Result).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_StartServer(Val Result, Val Option)

    Result = String(TypeOf(Result));
    ExpectsThat(Result).Равно("AddIn.OPI_WSServer.Main");

    Return Result;

EndFunction

Function Check_WebSocket_StopServer(Val Result, Val Option)

    If Option = "List" Then

        ExpectsThat(Result["result"]).Равно(False);

    ElsIf Option = "Connection" Then

        ExpectsThat(String(TypeOf(Result)) = "AddIn.OPI_WSClient.Main").Равно(False);

    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_GetNextConnectionData(Val Result, Val Option, Message = "")

    If Option = "Closed" Then

        ExpectsThat(Result["result"]).Равно(False);

    Else

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(ValueIsFilled(Result["connectionId"])).Равно(True);

        ResponseMessage = Result["message"];

        If TypeOf(ResponseMessage) = Type("BinaryData") Then

            ResponseMessage = GetStringFromBinaryData(ResponseMessage);

            Result["message"] = "<Binary data>";

        ElsIf OPI_Tools.ThisIsCollection(ResponseMessage, True) Then

            ResponseMessage = OPI_Tools.GetOr(ResponseMessage, "payload", "");

            If TypeOf(ResponseMessage) = Type("BinaryData") Then
                ResponseMessage["payload"] = "<Binary data>";
            EndIf;

        EndIf;

        ExpectsThat(ResponseMessage).Равно(Message);

    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_GetConnectionData(Val Result, Val Option, Message = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "EmptyList" Then

        ExpectsThat(Result["connections"]).ИмеетТип("Array").ИмеетДлину(0);

    Else

        If Option = "Closed" Then
            ExpectsThat(Result["isActive"]).Равно(False);
        Else
            ExpectsThat(Result["isActive"]).Равно(True);
        EndIf;

        ResponseMessage = Result["message"];

        If TypeOf(ResponseMessage) = Type("BinaryData") Then

            ResponseMessage = GetStringFromBinaryData(ResponseMessage);
            Result["message"] = "<Binary data>";

        ElsIf OPI_Tools.ThisIsCollection(ResponseMessage, True) Then

            ResponseMessage = OPI_Tools.GetOr(ResponseMessage, "payload", "");

            If TypeOf(ResponseMessage) = Type("BinaryData") Then
                ResponseMessage["payload"] = "<Binary data>";
            EndIf;

        EndIf;

        ExpectsThat(ResponseMessage).Равно(Message);

    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_SendData(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["type"]).Равно("binary");
        ExpectsThat(GetStringFromBinaryData(Result["data"])).Равно(Message);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_CloseIncomingConnection(Val Result, Val Option)

    If Option = "EmptyList" Then
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["connections"]).ИмеетТип("Array").ИмеетДлину(0);
    ElsIf Option = "SendingToClosed" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_GetConnectionList(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["connections"].Count() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_WebSocket_IsServerObject(Val Result, Val Option)

    If Option = "False" Then
        ExpectsThat(Result).Равно(False);
    Else
        ExpectsThat(Result).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_Extended_GetDataOfNextTimeout(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(Result["error"]).Равно("timeout");

    Return Result;

EndFunction

Function Check_WebSocket_Extended_OperationWithoutStart(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "not started") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_WebSocket_Extended_GetLogOnServerStart(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_WebSocket_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_WebSocket_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_CreateConnectionReq(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_ZeroMQ.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_CreateConnectionSub(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_ZeroMQ.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_CreateConnectionPush(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_ZeroMQ.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_CreateConnectionPull(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_ZeroMQ.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_BindPortRep(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_ZeroMQ.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_BindPortPub(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_ZeroMQ.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_BindPortPush(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_ZeroMQ.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_BindPortPull(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_ZeroMQ.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_SendData(Val Result, Val Option, Message = "")

    If Option = "Check" Then
        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_ReceiveData(Val Result, Val Option, Message = "")

    ExpectsThat(Result["result"]).Равно(True);
    Data = GetStringFromBinaryData(Result["data"]);
    ExpectsThat(Data).Равно(Message);
    Result["data"] = "<BinaryData>";

    Return Result;

EndFunction

Function Check_ZeroMQ_Extended_GetTimeoutData(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsTimeout = StrFind(ErrorText, "timeout") > 0
        Or StrFind(ErrorText, "timed out") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsTimeout).Равно(True);

    Return Result;

EndFunction

Function Check_ZeroMQ_Extended_HandleTimeoutRequest(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsTimeout = StrFind(ErrorText, "timeout") > 0
        Or StrFind(ErrorText, "timed out") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsTimeout).Равно(True);

    Return Result;

EndFunction

Function Check_ZeroMQ_Extended_JanxCollectionExchange(Val Result, Val Option, Restored = Undefined, InitialValue = Undefined, SentBinaryData = Undefined)

    ExpectsThat(Result["result"]).Равно(True);
    CheckBinaryDataJanx(Result["data"], SentBinaryData);
    CheckMapJanx(Restored, InitialValue);
    Result["data"] = "<BinaryData>";

    Return Result;

EndFunction

Function Check_ZeroMQ_Extended_GetLogOnPortOpening(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);

    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_ZeroMQ_ProcessRequest(Val Result, Val Option, Message = "")

    If Option = "ReceivingTimeout" Then

        ExpectsThat(Result["result"]).Равно(False);
        ExpectsThat(StrFind(Lower(Result["error"]), "timeout") > 0).Равно(True);

    ElsIf Option = "Response" Or Not ValueIsFilled(Option) Then

        ExpectsThat(Result["result"]).Равно(True);

        Data = GetStringFromBinaryData(Result["data"]);
        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";

    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_Subscribe(Val Result, Val Option, Message = "")

    If Option = "ForeignTopic" Then
        ExpectsThat(Result["result"]).Равно(False);
    ElsIf Option = "Check" Then

        ExpectsThat(Result["result"]).Равно(True);
        Data = GetStringFromBinaryData(Result["data"]);

        ExpectsThat(Data).Равно(Message);
        Result["data"] = "<BinaryData>";

    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_CloseConnection(Val Result, Val Option)

    If Option = "Openning" Then
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_ZeroMQ.Main");
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_ZeroMQ_IsConnectorObject(Val Result, Val Option)

    If Option = "False" Then
        ExpectsThat(Result).Равно(False);
    Else
        ExpectsThat(Result).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_CreateConnection(Val Result, Val Option)

    If Option = "Closing" Then
        ExpectsThat(Result["result"]).Равно(True);
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_SQLite.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_CloseConnection(Val Result, Val Option)

    If Option = "Openning" Then
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_SQLite.Main");
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_ExecuteSQLQuery(Val Result, Val Option, Image = "")

    If Not ValueIsFilled(Option) Then

        Blob = Result["data"][0]["data"];

        Result["data"][0]["data"] = "Binary";
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Blob.Size()).Равно(Image.Size());

    ElsIf Option = "Openning" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_SQLite.Main");

    ElsIf Option = "Extension" Then

        SystemInfo = New SystemInfo;

        If StrFind(String(SystemInfo.PlatformType), "64") <> 0 Then
            ExpectsThat(Result["data"]).ИмеетТип("Array").ИмеетДлину(1);
        Else
            Return Undefined;
        EndIf;

    EndIf;

    If Not Option = "Openning" Then
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_IsConnector(Val Result, Val Option)

    ExpectsThat(Result).Равно(True);

    Return Result;

EndFunction

Function Check_SQLite_CreateTable(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_SQLite_AddRecords(Val Result, Val Option)

    If Option = "Field error" Or Option = "JSON Error" Then
        ExpectsThat(Result["result"]).Равно(False);
    ElsIf Option = "Error without transaction" Then
        ExpectsThat(Result["rows"] = 1 Or Result["rows"] = 2).Равно(True);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_GetRecords(Val Result, Val Option)

    If Option = "Error" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_UpdateRecords(Val Result, Val Option, FieldsStructure = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        Check = Result["data"][0];

        For Each Value In FieldsStructure Do
            Check[Value.Key] = Value.Value;
        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_DeleteRecords(Val Result, Val Option)

    If Option = "Check" Then
        ExpectsThat(Result["data"].Count()).Равно(0);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_GetTableInformation(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_SQLite_GetRecordsFilterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_DeleteTable(Val Result, Val Option)

    If Option = "Check" Then
        ExpectsThat(Result["data"].Count()).Равно(0);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_ClearTable(Val Result, Val Option)

    If Option = "Check" Then

        ExpectsThat(Result["data"].Count()).Равно(0);

    ElsIf Option = "Table" Then

        ExpectsThat(Result["data"].Count()).Равно(5);

    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_Extended_ExecuteQueryWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "not connected") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_SQLite_Extended_Reconnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsRetry = StrFind(ErrorText, "already") > 0
        Or StrFind(ErrorText, "initialized") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsRetry).Равно(True);

    Return Result;

EndFunction

Function Check_SQLite_Extended_RequestWithTwoBlobs(Val Result, Val Option, InitialValue = Undefined)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"].Count()).Равно(1);

    String = Result["data"][0];
    CheckBinaryDataJanx(String["alpha"], InitialValue["alpha"]);
    CheckBinaryDataJanx(String["beta"], InitialValue["beta"]);
    CheckBinaryDataJanx(String["inner_blob"], InitialValue["nested"]["inner"]);

    Result["data"][0]["alpha"] = "Binary";
    Result["data"][0]["beta"] = "Binary";
    Result["data"][0]["inner_blob"] = "Binary";

    Return Result;

EndFunction

Function Check_SQLite_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_SQLite_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_ConnectExtension(Val Result, Val Option)

    SystemInfo = New SystemInfo;

    If StrFind(String(SystemInfo.PlatformType), "64") <> 0 Then

        ExpectsThat(Result["result"]).Равно(True);

        If Option = "Check" Then
            ExpectsThat(Result["data"].Count()).Равно(1);
        EndIf;

    Else
        Return Undefined;
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_AddTableColumn(Val Result, Val Option)

    If Option = "Check" Then

        Found = False;

        For Each Column In Result["data"] Do

            If Column["name"] = "new_col" Then

                ExpectsThat(Column["type"]).Равно("TEXT");
                Found = True;

            EndIf;

        EndDo;

        ExpectsThat(Found).Равно(True);

    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_DeleteTableColumn(Val Result, Val Option)

    If Option = "Check" Then

        Found = False;

        For Each Column In Result["data"] Do

            If Column["name"] = "new_col" Then

                Found = True;

            EndIf;

        EndDo;

        ExpectsThat(Found).Равно(False);

    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_EnsureTable(Val Result, Val Option, ColoumnsStruct = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Not ValueIsFilled(Option) Or Option = "New" Then

        ExpectsThat(Result["commit"]["result"]).Равно(True);

    Else

        ExpectsThat(Result["data"].Count()).Равно(ColoumnsStruct.Count());

        For Each Column In Result["data"] Do
            ExpectsThat(Column["type"]).Равно(ColoumnsStruct[Column["name"]]);
        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_SQLite_EnsureRecords(Val Result, Val Option)

    If Option = "Insertion" Or Option = "Updating" Then

        ExpectsThat(Result["result"]).Равно(True);

    ElsIf Option = "Insertion check" Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count()).Равно(2);

    ElsIf Option = "Updating check" Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count()).Равно(3);

        Found = False;

        For Each Record In Result["data"] Do
            If Record["id"] = 1 Then
                ExpectsThat(Record["name"]).Равно("Vitaly Updated");
                ExpectsThat(Record["salary"]).Равно(1500.50);
                Found = True;
            EndIf;
        EndDo;

        ExpectsThat(Found).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_Extended_ExecuteQueryWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "not connected") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_Extended_ConnectionWithoutString(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "empty connection") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_Extended_Reconnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsRetry = StrFind(ErrorText, "already") > 0
        Or StrFind(ErrorText, "initialized") > 0
        Or StrFind(ErrorText, "connected") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsRetry).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_GenerateConnectionString(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_PostgreSQL_CreateConnection(Val Result, Val Option)

    Result = String(TypeOf(Result));
    ExpectsThat(Result).Равно("AddIn.OPI_PostgreSQL.Main");

    Return Result;

EndFunction

Function Check_PostgreSQL_CloseConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_IsConnector(Val Result, Val Option)

    ExpectsThat(Result).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_ExecuteSQLQuery(Val Result, Val Option, Image = "")

    If Option = "Connection" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_PostgreSQL.Main");

    ElsIf ValueIsFilled(Option) Then

        ExpectsThat(Result["result"]).Равно(True);

    Else

        Blob = Result["data"][0]["data"];

        Result["data"][0]["data"] = "Binary";
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Blob.Size()).Равно(Image.Size());

    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_CreateDatabase(Val Result, Val Option)

    If Option = "Openning" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_PostgreSQL.Main");

    ElsIf Option = "Existing" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_CreateTable(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then
        ExpectsThat(Result["result"]).Равно(True);
    Else
        ExpectsThat(Result["result"]).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_GetTableInformation(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then
        ExpectsThat(Result["data"].Count()).Равно(26);
    Else
        ExpectsThat(Result["data"].Count()).Равно(0);
    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_AddRecords(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_GetRecords(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Not ValueIsFilled(Option) Then

        If ValueIsFilled(Result["data"]) Then
            Result["data"][0]["bytea_field"] = "Binary";
        EndIf;

    Else
        ExpectsThat(Result["data"].Count()).Равно(5);
    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_UpdateRecords(Val Result, Val Option, Count = "", FieldsStructure = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        ExpectsThat(Result["data"].Count()).Равно(Count);

        For N = 0 To Result["data"].UBound() Do

            For Each Value In FieldsStructure Do
                Result["data"][N][Value.Key] = Value.Value;
            EndDo;

        EndDo;
    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_DeleteRecords(Val Result, Val Option, Count = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then
        ExpectsThat(Result["data"].Count()).Равно(Count);
    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_DeleteTable(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_DeleteDatabase(Val Result, Val Option)

    If Option = "Openning" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_PostgreSQL.Main");

    ElsIf Option = "Error" Or Option = "Connection error" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_ClearTable(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then
        ExpectsThat(Result["data"].Count()).Равно(0);
    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_DisableAllDatabaseConnections(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_GetRecordsFilterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_GetTLSSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_PostgreSQL_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_AddTableColumn(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        Found = False;

        For Each Column In Result["data"] Do

            If Column["column_name"] = "new_field" Then
                ExpectsThat(Lower(Column["data_type"])).Равно("text");
                Found = True;
            EndIf;

        EndDo;

        ExpectsThat(Found).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_DeleteTableColumn(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        Found = False;

        For Each Column In Result["data"] Do

            If Column["column_name"] = "new_field" Then
                Found = True;
            EndIf;

        EndDo;

        ExpectsThat(Found).Равно(False);

    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_EnsureTable(Val Result, Val Option, ColoumnsStruct = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        ExpectsThat(Result["data"].Count()).Равно(ColoumnsStruct.Count());

        For Each Column In Result["data"] Do
            ExpectsThat(Lower(Column["data_type"])).Равно(Lower(ColoumnsStruct[Column["column_name"]]));
        EndDo;

    Else
        ExpectsThat(Result["commit"]["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_PostgreSQL_EnsureRecords(Val Result, Val Option)

    If Option = "Insertion" Or Option = "Updating" Then

        ExpectsThat(Result["result"]).Равно(True);

    ElsIf Option = "Insertion check" Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count()).Равно(2);

    ElsIf Option = "Updating check" Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count()).Равно(3);

        Found = False;

        For Each Record In Result["data"] Do
            If Record["id"] = 1 Then
                ExpectsThat(Record["name"]).Равно("Vitaly Updated");
                ExpectsThat(Record["salary"]).Равно(1500.50);
                Found = True;
            EndIf;
        EndDo;

        ExpectsThat(Found).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_Extended_ExecuteQueryWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "not connected") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_MySQL_Extended_ConnectionWithoutString(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "empty connection") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_MySQL_Extended_Reconnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsRetry = StrFind(ErrorText, "already") > 0
        Or StrFind(ErrorText, "initialized") > 0
        Or StrFind(ErrorText, "connected") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsRetry).Равно(True);

    Return Result;

EndFunction

Function Check_MySQL_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_MySQL_GenerateConnectionString(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_MySQL_CreateConnection(Val Result, Val Option)

    Result = String(TypeOf(Result));
    ExpectsThat(Result).Равно("AddIn.OPI_MySQL.Main");

    Return Result;

EndFunction

Function Check_MySQL_CloseConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MySQL_IsConnector(Val Result, Val Option)

    ExpectsThat(Result).Равно(True);

    Return Result;

EndFunction

Function Check_MySQL_ExecuteSQLQuery(Val Result, Val Option, Image = "")

    If Option = "Connection" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_MySQL.Main");

    ElsIf ValueIsFilled(Option) Then

        ExpectsThat(Result["result"]).Равно(True);

    Else

        Blob = Result["data"][0]["data"];

        Result["data"][0]["data"] = "Binary";
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Blob.Size()).Равно(Image.Size());

    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_CreateDatabase(Val Result, Val Option)

    If Option = "Openning" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_MySQL.Main");

    ElsIf Option = "Existing" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_CreateTable(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then
        ExpectsThat(Result["result"]).Равно(True);
    Else
        ExpectsThat(Result["result"]).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_AddRecords(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MySQL_GetRecords(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Not ValueIsFilled(Option) Then

        If ValueIsFilled(Result["data"]) Then

            Result["data"][0]["mediumblob_field"] = "Binary";

        EndIf;

    Else
        ExpectsThat(Result["data"].Count()).Равно(5);
    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_UpdateRecords(Val Result, Val Option, Count = "", FieldsStructure = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        ExpectsThat(Result["data"].Count()).Равно(Count);

        For N = 0 To Result["data"].UBound() Do

            For Each Value In FieldsStructure Do
                Result["data"][N][Value.Key] = Value.Value;
            EndDo;

        EndDo;
    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_DeleteRecords(Val Result, Val Option, Count = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then
        ExpectsThat(Result["data"].Count()).Равно(Count);
    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_DeleteTable(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MySQL_DeleteDatabase(Val Result, Val Option)

    If Option = "Openning" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_MySQL.Main");

    ElsIf Option = "Error" Or Option = "Connection error" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_ClearTable(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then
        ExpectsThat(Result["data"].Count()).Равно(0);
    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_GetRecordsFilterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_GetTLSSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_MySQL_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_GetTableInformation(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then
        ExpectsThat(Result["data"].Count()).Равно(20);
    Else
        ExpectsThat(Result["data"].Count()).Равно(0);
    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_AddTableColumn(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        Found = False;

        For Each Column In Result["data"] Do

            If Column["COLUMN_NAME"] = "new_field" Then

                CurrentType = Column["DATA_TYPE"];
                ExpectsThat(Lower(CurrentType)).Равно("mediumtext");
                Found = True;
            EndIf;

        EndDo;

        ExpectsThat(Found).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_DeleteTableColumn(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        Found = False;

        For Each Column In Result["data"] Do

            If Column["COLUMN_NAME"] = "new_field" Then
                Found = True;
            EndIf;

        EndDo;

        ExpectsThat(Found).Равно(False);

    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_EnsureTable(Val Result, Val Option, ColoumnsStruct = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        ExpectsThat(Result["data"].Count()).Равно(ColoumnsStruct.Count());

        For Each Column In Result["data"] Do
            CurrentType = Column["DATA_TYPE"];
            ExpectsThat(Lower(CurrentType)).Равно(Lower(ColoumnsStruct[Column["COLUMN_NAME"]]));
        EndDo;

    Else
        ExpectsThat(Result["commit"]["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MySQL_EnsureRecords(Val Result, Val Option)

    If Option = "Insertion" Or Option = "Updating" Then

        ExpectsThat(Result["result"]).Равно(True);

    ElsIf Option = "Insertion check" Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count()).Равно(2);

    ElsIf Option = "Updating check" Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count()).Равно(3);

        Found = False;

        For Each Record In Result["data"] Do
            If Record["id"] = 1 Then
                ExpectsThat(Record["name"]).Равно("Vitaly Updated");
                ExpectsThat(Record["salary"]).Равно(1500.50);
                Found = True;
            EndIf;
        EndDo;

        ExpectsThat(Found).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_GreenAPI_FormAccessParameters(Val Result, Val Option)

    Result.Insert("apiTokenInstance", "***");
    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_GetInstanceSettings(Val Result, Val Option, Parameters = "")

    Try
        JSON = OPI_Tools.JSONString(Result);
        JSON = StrReplace(JSON, Parameters["GreenAPI_AccountID"], "1234567890@c.us");

        Result = OPI_Tools.JsonToStructure(JSON, True);
    Except
        Message("JSON Error");
    EndTry;

    ExpectsThat(Result["proxyInstance"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenAPI_GetAccountInformation(Val Result, Val Option, Parameters = "")

    Try
        Result["deviceId"] = "***";
        Result["phone"] = "***";
    Except
        Message("Failed to replace the secrets!!");
    EndTry;

    ExpectsThat(Result["deviceId"]).Заполнено();
    ExpectsThat(Result["phone"]).Заполнено();

    ChatID = Result["chatId"];
    WriteParameter("GreenAPI_ChatID", ChatID);
    OPI_Tools.AddField("GreenAPI_ChatID", ChatID, "String", Parameters);

    Return Result;

EndFunction

Function Check_GreenAPI_GetInstanceSettingsStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_GreenAPI_SetInstanceSettings(Val Result, Val Option)

    ExpectsThat(Result["saveSettings"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_GetInstanceStatus(Val Result, Val Option)

    ExpectsThat(Result["stateInstance"]).Равно("authorized");

    Return Result;

EndFunction

Function Check_GreenAPI_RebootInstance(Val Result, Val Option)

    ExpectsThat(Result["isReboot"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_GetQR(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() >= 0).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_LogoutInstance(Val Result, Val Option)

    ExpectsThat(Result["isLogout"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_GetAuthorizationCode(Val Result, Val Option)

    Return Result;

EndFunction

Function Check_GreenAPI_SetProfilePicture(Val Result, Val Option)

    ExpectsThat(Result["setProfilePicture"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_CreateGroup(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["created"]).Равно(True);
    ExpectsThat(Result["chatId"]).Заполнено();

    GroupID = Result["chatId"];
    WriteParameter("GreenAPI_GroupID", GroupID);
    OPI_Tools.AddField("GreenAPI_GroupID", GroupID, "String", Parameters);

    Return Result;

EndFunction

Function Check_GreenAPI_LeaveGroup(Val Result, Val Option)

    ExpectsThat(Result["removeAdmin"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_GetGroupInformation(Val Result, Val Option)

    Try
        Result["owner"] = "***";
        Result["participants"][0]["id"] = "***";
    Except
        Message("Failed to replace the secrets!!");
    EndTry;

    ExpectsThat(Result["groupId"]).Заполнено();
    ExpectsThat(Result["owner"]).Заполнено();
    ExpectsThat(Result["creation"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenAPI_UpdateGroupName(Val Result, Val Option)

    ExpectsThat(Result["updateGroupName"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_AddGroupMember(Val Result, Val Option)

    Try
        Result["addParticipant"] = True;
    Except
        Message("Failed to replace the secrets!!");
    EndTry;

    ExpectsThat(Result["addParticipant"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_ExcludeGroupMember(Val Result, Val Option)

    Try
        Result["removeParticipant"] = True;
    Except
        Message("Failed to replace the secrets!!");
    EndTry;

    ExpectsThat(Result["removeParticipant"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_SetAdminRights(Val Result, Val Option)

    Try
        Result["setGroupAdmin"] = True;
    Except
        Message("Failed to replace the secrets!!");
    EndTry;

    ExpectsThat(Result["setGroupAdmin"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_RevokeAdminRights(Val Result, Val Option)

    Try
        Result["removeAdmin"] = True;
    Except
        Message("Failed to replace the secrets!!");
    EndTry;

    ExpectsThat(Result["removeAdmin"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_SetGroupPicture(Val Result, Val Option)

    ExpectsThat(Result["setGroupPicture"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_SendTextMessage(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["idMessage"]).Заполнено();

    If Not ValueIsFilled(Option) Then

        MessageID = Result["idMessage"];
        WriteParameter("GreenAPI_MessageID", MessageID);
        OPI_Tools.AddField("GreenAPI_MessageID", MessageID, "String", Parameters);

    EndIf;

    Return Result;

EndFunction

Function Check_GreenAPI_DeleteMessage(Val Result, Val Option)

    If Not Lower(String(Result)) = "null" Then
        ExpectsThat(ValueIsFilled(Result)).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_GreenAPI_EditMessageText(Val Result, Val Option)

    ExpectsThat(Result["idMessage"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenAPI_SendFile(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["idMessage"]).Заполнено();
    ExpectsThat(Result["urlFile"]).Заполнено();

    If Not ValueIsFilled(Option) Then
        MessageID = Result["idMessage"];
        WriteParameter("GreenAPI_FileMessageID", MessageID);
        OPI_Tools.AddField("GreenAPI_FileMessageID", MessageID, "String", Parameters);
    EndIf;

    Return Result;

EndFunction

Function Check_GreenAPI_SendFileByURL(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["idMessage"]).Заполнено();

    If Not ValueIsFilled(Option) Then
        MessageID = Result["idMessage"];
        WriteParameter("GreenAPI_FileMessageID", MessageID);
        OPI_Tools.AddField("GreenAPI_FileMessageID", MessageID, "String", Parameters);
    EndIf;

    Return Result;

EndFunction

Function Check_GreenAPI_SendPoll(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["idMessage"]).Заполнено();

    If Not ValueIsFilled(Option) Then
        MessageID = Result["idMessage"];
        WriteParameter("GreenAPI_PollMessageID", MessageID);
        OPI_Tools.AddField("GreenAPI_PollMessageID", MessageID, "String", Parameters);
    EndIf;

    Return Result;

EndFunction

Function Check_GreenAPI_GetLocationDescription(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_SendLocation(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["idMessage"]).Заполнено();

    If Not ValueIsFilled(Option) Then
        MessageID = Result["idMessage"];
        WriteParameter("GreenAPI_LocMessageID", MessageID);
        OPI_Tools.AddField("GreenAPI_LocMessageID", MessageID, "String", Parameters);
    EndIf;

    Return Result;

EndFunction

Function Check_GreenAPI_GetContactDescription(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_SendContact(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["idMessage"]).Заполнено();

    If Not ValueIsFilled(Option) Then
        MessageID = Result["idMessage"];
        WriteParameter("GreenAPI_ContactMessageID", MessageID);
        OPI_Tools.AddField("GreenAPI_ContactMessageID", MessageID, "String", Parameters);
    EndIf;

    Return Result;

EndFunction

Function Check_GreenAPI_ForwardMessages(Val Result, Val Option)

    ExpectsThat(Result["messages"]).ИмеетТип("Array").Заполнено();

    Return Result;

EndFunction

Function Check_GreenAPI_GetNotification(Val Result, Val Option, Parameters = "")

    Try
        JSON = OPI_Tools.JSONString(Result);
        JSON = StrReplace(JSON, Parameters["GreenAPI_AccountID"], "1234567890@c.us");

        Result = OPI_Tools.JsonToStructure(JSON, True);
    Except
        Message("JSON Error");
    EndTry;

    Result = OPI_Tools.JsonToStructure(JSON, True);

    ExpectsThat(Result["receiptId"]).Заполнено();

    NotificationID = Result["receiptId"];
    WriteParameter("GreenAPI_ReceiptID", NotificationID);
    OPI_Tools.AddField("GreenAPI_ReceiptID", NotificationID, "String", Parameters);

    Return Result;

EndFunction

Function Check_GreenAPI_DeleteNotificationFromQueue(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_DownloadMessageFile(Val Result, Val Option)

    ExpectsThat(Result["downloadUrl"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenAPI_SetReadMark(Val Result, Val Option)

    ExpectsThat(Result["setRead"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_GetMessageQueue(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result)).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_ClearMessageQueue(Val Result, Val Option)

    ExpectsThat(Result["isCleared"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_GetChatHistory(Val Result, Val Option, Parameters = "")

    Try
        JSON = OPI_Tools.JSONString(Result);
        JSON = StrReplace(JSON, Parameters["GreenAPI_AccountID"], "1234567890@c.us");

        Result = OPI_Tools.JsonToStructure(JSON, True);
    Except
        Message("JSON Error");
    EndTry;

    ExpectsThat(Result).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_GreenAPI_GetMessage(Val Result, Val Option, Parameters = "")

    Try
        JSON = OPI_Tools.JSONString(Result);
        JSON = StrReplace(JSON, Parameters["GreenAPI_AccountID"], "1234567890@c.us");

        Result = OPI_Tools.JsonToStructure(JSON, True);
    Except
        Message("JSON Error");
    EndTry;

    ExpectsThat(Result["idMessage"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenAPI_GetIncomingMessageLog(Val Result, Val Option, Parameters = "")

    Try
        JSON = OPI_Tools.JSONString(Result);
        JSON = StrReplace(JSON, Parameters["GreenAPI_AccountID"], "1234567890@c.us");

        Result = OPI_Tools.JsonToStructure(JSON, True);
    Except
        Message("JSON Error");
    EndTry;

    ExpectsThat(OPI_Tools.ThisIsCollection(Result)).Равно(True);

    Return Result;

EndFunction

Function Check_GreenAPI_GetOutgoingMessageLog(Val Result, Val Option, Parameters = "")

    Try
        JSON = OPI_Tools.JSONString(Result);
        JSON = StrReplace(JSON, Parameters["GreenAPI_AccountID"], "1234567890@c.us");

        Result = OPI_Tools.JsonToStructure(JSON, True);
    Except
        Message("JSON Error");
    EndTry;

    ExpectsThat(Result).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_GreenAPI_ArchiveChat(Val Result, Val Option)

    // !DISABLED! ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Undefined;

EndFunction

Function Check_GreenAPI_UnarchiveChat(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then
        ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_RCON_Extended_ExecuteCommandWithoutConnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsError = StrFind(ErrorText, "no client") > 0
        Or StrFind(ErrorText, "initialize connection") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsError).Равно(True);

    Return Result;

EndFunction

Function Check_RCON_Extended_Reconnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsRetry = StrFind(ErrorText, "already") > 0
        Or StrFind(ErrorText, "initialized") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsRetry).Равно(True);

    Return Result;

EndFunction

Function Check_RCON_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_RCON_FormConnectionParameters(Val Result, Val Option)

    Result["url"] = "127.0.0.1:25565";
    Result["password"] = "***";

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_RCON_CreateConnection(Val Result, Val Option)

    Result = String(TypeOf(Result));
    ExpectsThat(Result).Равно("AddIn.OPI_RCON.Main");

    Return Result;

EndFunction

Function Check_RCON_ExecuteCommand(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_RCON_IsConnector(Val Result, Val Option)

    ExpectsThat(Result).Равно(True);

    Return Result;

EndFunction

Function Check_RCON_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_RCON_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_Ollama_GetResponse(Val Result, Val Option)

    ExpectsThat(Result["model"]).Заполнено();
    ExpectsThat(Result["response"]).Заполнено();
    ExpectsThat(Result["done"]).Равно(True);

    Return Result;

EndFunction

Function Check_Ollama_GetContextResponse(Val Result, Val Option, Message1 = "", Message2 = "",
    Message3 = "")

    If Option = "Comparison" Then

        ExpectsThat(Message1 = Message2).Равно(True);
        ExpectsThat(Message1 = Message3).Равно(False);

    Else
        ExpectsThat(Result["model"]).Заполнено();
        ExpectsThat(Result["message"]).Заполнено();
        ExpectsThat(Result["done"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_Ollama_LoadModelToMemory(Val Result, Val Option)

    ExpectsThat(Result["model"]).Заполнено();
    ExpectsThat(Result["done"]).Равно(True);
    ExpectsThat(Result["done_reason"]).Равно("load");

    Return Result;

EndFunction

Function Check_Ollama_UnloadModelFromMemory(Val Result, Val Option)

    ExpectsThat(Result["model"]).Заполнено();
    ExpectsThat(Result["done"]).Равно(True);
    ExpectsThat(Result["done_reason"]).Равно("unload");

    Return Result;

EndFunction

Function Check_Ollama_GetRequestParameterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_Ollama_GetContextParameterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_Ollama_GetContextMessageStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_Ollama_GetModelSettingsStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_Ollama_CreateModel(Val Result, Val Option)

    If Option = "Request" Then

        ExpectsThat(Result["model"]).Заполнено();
        ExpectsThat(Result["response"]).Заполнено();
        ExpectsThat(Result["done"]).Равно(True);

    Else
        ExpectsThat(Result["status"]).Равно("success");
    EndIf;

    Return Result;

EndFunction

Function Check_Ollama_DeleteModel(Val Result, Val Option)

    If Option = "List" Then
        ExpectsThat(Result["models"].Count()).Равно(4);
    ElsIf Not ValueIsFilled(Option) Then
        ExpectsThat(Result["status_code"] < 300).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_Ollama_GetModelList(Val Result, Val Option)

    ExpectsThat(Result["models"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Ollama_ListRunningModels(Val Result, Val Option)

    ExpectsThat(Result["models"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_Ollama_GetModelInformation(Val Result, Val Option)

    ExpectsThat(Result["parameters"]).Заполнено();
    ExpectsThat(Result["model_info"]).Заполнено();

    Return Result;

EndFunction

Function Check_Ollama_CopyModel(Val Result, Val Option)

    ExpectsThat(Result["status_code"] < 300).Равно(True);

    Return Result;

EndFunction

Function Check_Ollama_GetVersion(Val Result, Val Option)

    ExpectsThat(Result["version"]).Заполнено();

    Return Result;

EndFunction

Function Check_Ollama_GetEmbeddings(Val Result, Val Option)

    ExpectsThat(Result["embeddings"]).Заполнено();

    Return Result;

EndFunction

Function Check_Ollama_GetEmbeddingsParameterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_Ollama_PushModel(Val Result, Val Option)

    ExpectsThat(Result["status"]).Равно("success");

    Return Result;

EndFunction

Function Check_Ollama_PullModel(Val Result, Val Option)

    ExpectsThat(Result["status"]).Равно("success");

    Return Result;

EndFunction

Function Check_Ollama_PushBlob(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["status_code"] < 300).Равно(True);

    WriteParameter("Ollama_Blob", Result["digest"]);
    Parameters.Insert("Ollama_Blob", Result["digest"]);

    Return Result;

EndFunction

Function Check_Ollama_CheckBlob(Val Result, Val Option, Parameters = "")

    If Option = "Error" Then
        ExpectsThat(Result["status_code"] >= 400).Равно(True);
    Else
        ExpectsThat(Result["status_code"] < 300).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_Initialize(Val Result, Val Option, Parameters = "")

    If Not ValueIsFilled(Option) Then

        Try
            Result["origin"] = "***";
        Except
            Try
                Raise Result.GetLog(True);
            Except
                Raise GetStringFromBinaryData(Result);
            EndTry;
        EndTry;

        ExpectsThat(Result["args"]).ИмеетТип("Map");
        ExpectsThat(Result["args"].Count()).Равно(0);

    ElsIf Option = "Check 1" Then

        Try

            HTTPRequest = Result.ReturnRequest();
            HTTPConnection = Result.ReturnConnection();
            HTTPResponse = Result.ReturnResponse();

            MainURL = StrReplace(Parameters["HTTP_URL"], "https://", "");
            MainURL = StrReplace(MainURL , "http://" , "");

            If StrFind(MainURL, ":") > 0 Then
                MainURL = StrSplit(MainURL, ":")[0];
            EndIf;

            ExpectsThat(HTTPRequest).ИмеетТип("HTTPRequest");
            ExpectsThat(HTTPConnection).ИмеетТип("HTTPConnection");

            ExpectsThat(HTTPRequest.ResourceAddress).Равно("/get");
            ExpectsThat(HTTPConnection.Host).Равно(MainURL);

            ExpectsThat(HTTPResponse).Равно(Undefined);

        Except
            Raise ErrorDescription() + Chars.LF + Chars.LF + Result.GetLog(True);
        EndTry;

    Else

        Try
            ExpectsThat(Result).ИмеетТип("HTTPRequest");
            ExpectsThat(Result.ResourceAddress).Равно("/post");
        Except
            Raise ErrorDescription() + Chars.LF + Chars.LF + Result.GetLog(True);
        EndTry;

    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_SetURL(Val Result, Val Option, Parameters = "")

    If Not ValueIsFilled(Option) Then

        Try
            Result["origin"] = "***";
        Except
            Try
                Raise Result.GetLog(True);
            Except
                Raise GetStringFromBinaryData(Result);
            EndTry;
        EndTry;

        ExpectsThat(Result["args"]).ИмеетТип("Map");
        ExpectsThat(Result["args"].Count()).Равно(0);

    Else

        Try

            HTTPRequest = Result.ReturnRequest();
            HTTPConnection = Result.ReturnConnection();
            HTTPResponse = Result.ReturnResponse();
            MainURL = StrReplace(Parameters["HTTP_URL"], "https://", "");
            MainURL = StrReplace(MainURL , "http://" , "");

            If StrFind(MainURL, ":") > 0 Then
                MainURL = StrSplit(MainURL, ":")[0];
            EndIf;

            ExpectsThat(HTTPRequest).ИмеетТип("HTTPRequest");
            ExpectsThat(HTTPConnection).ИмеетТип("HTTPConnection");

            ExpectsThat(HTTPRequest.ResourceAddress).Равно("/get");
            ExpectsThat(HTTPConnection.Host).Равно(MainURL);

            ExpectsThat(HTTPResponse).Равно(Undefined);

        Except
            Raise ErrorDescription() + Chars.LF + Chars.LF + Result.GetLog(True);
        EndTry;

    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_SetURLParams(Val Result, Val Option, Parameters = "")

    Address = "/get?param1=text&param2=10";

    ResponseMap = New Map;
    ResponseMap.Insert("Option 1", "/page?param1=search%3Ftext&param2=John" + "%20Doe&param3=value%26another&param4=%D0%BA%D0%B8%D1%80%D0%B8%D0%BB%D0%BB%"
        + "D0%B8%D1%86%D0%B0&param5=%3Cscript%3Ealert%28%27XSS%27%29%3C%2Fscript%3E");

    ResponseMap.Insert("Option 2", "/page?existing=value&param1=search%3Ftext&param2=John%20Doe");
    ResponseMap.Insert("Variant 3", "/page?param1=search%3Ftext&param2=John%20Doe");
    ResponseMap.Insert("Variant 4", "/path%20with%20spaces?param1=search%3Ftext&param2=John%20Doe");
    ResponseMap.Insert("Variant 5", "/page?param1=search%3Ftext&param2=John%20Doe#section");
    ResponseMap.Insert("Variant 6", "/%D0%BF%D1%83%D1%82%D1%8C?param1=search%3Ftext&param2=John%20Doe");
    ResponseMap.Insert("Variant 7", "/page?param1=value1&param2=value%20two&param3=value%3Cthree%3E");

    If Not ValueIsFilled(Option) Then

        Try
            Result["origin"] = "***";
        Except
            Try
                Raise Result.GetLog(True);
            Except
                Raise GetStringFromBinaryData(Result);
            EndTry;
        EndTry;

        FullURL = Parameters["HTTP_URL"] + Address;

        ExpectsThat(Result["args"]).ИмеетТип("Map");
        ExpectsThat(Result["args"].Count()).Равно(2);
        ExpectsThat(Result["url"]).Равно(FullURL);

    ElsIf Option = "Check" Then

        Try

            ExpectsThat(Result).ИмеетТип("HTTPRequest");
            ExpectsThat(Result.ResourceAddress).Равно(Address);

        Except
            Raise ErrorDescription() + Chars.LF + Chars.LF + Result.GetLog(True);
        EndTry;

    Else
        ExpectsThat(Result).Равно(ResponseMap[Option]);
    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_SetResponseFile(Val Result, Val Option, TFN = "")

    BodyFile = New File(TFN);

    If Not ValueIsFilled(Option) Then

        BodyFileReturn = New File(Result);

        ExpectsThat(TFN).Равно(Result);
        ExpectsThat(BodyFile.Size()).Равно(BodyFileReturn.Size());
        ExpectsThat(BodyFile.Size() > 0).Равно(True);

    Else

        ExpectsThat(BodyFile.Size()).Равно(Result.Size());

        CheckResultAsString = GetStringFromBinaryData(Result);

        ExpectsThat(OPI_Tools.JsonToStructure(CheckResultAsString)).ИмеетТип("Map");

    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_SetDataType(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(Result["headers"]["Content-Type"]).Равно("text/markdown");

    Return Result;

EndFunction

Function Check_HTTP_GetLog(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("String");

    Return Result;

EndFunction

Function Check_HTTP_SetBinaryBody(Val Result, Val Option, Image = "")

    Try
        Result["origin"] = "***";
        Result["data"] = "...";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/octet-stream");

    OPI_TypeConversion.GetBinaryData(Image);

    Size = Image.Size();
    OPI_TypeConversion.GetLine(Size);
    ExpectsThat(Result["headers"]["Content-Length"]).Равно(Size);

    Return Result;

EndFunction

Function Check_HTTP_SetStringBody(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    Text = "Hello world!!";
    Encoding = "Windows-1251";

    ExpectsThat(Result["headers"]["Content-Type"]).Равно("text/plain; charset=" + Encoding);

    TextBD = GetBinaryDataFromString(Text, Encoding);
    Size = TextBD.Size();
    OPI_TypeConversion.GetLine(Size);

    ExpectsThat(Result["headers"]["Content-Length"]).Равно(Size);

    TextB64 = "data:application/octet-stream;base64," + Base64String(TextBD);

    ExpectsThat(Result["data"] = TextB64 Or Result["data"] = Text).Равно(True);

    Return Result;

EndFunction

Function Check_HTTP_SetJsonBody(Val Result, Val Option, JSONOriginal = "")

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/json; charset=utf-8");

    JSONResult = Result["json"];

    ExpectsThat(JSONResult["Field1"]).Равно(JSONOriginal["Field1"]);
    ExpectsThat(JSONResult["Field2"]).Равно(JSONOriginal["Field2"]);
    ExpectsThat(JSONResult["Field3"][0]).Равно(JSONOriginal["Field3"][0]);
    ExpectsThat(JSONResult["Field3"][1]).Равно(JSONOriginal["Field3"][1]);
    ExpectsThat(JSONResult["Field3"][2]).Равно(JSONOriginal["Field3"][2]);

    Return Result;

EndFunction

Function Check_HTTP_SetFormBody(Val Result, Val Option, Data = "")

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/x-www-form-urlencoded; charset=utf-8");

    ExpectsThat(Result["form"]["Field1"]).Равно(Data["Field1"]);
    ExpectsThat(Result["form"]["Field2"]).Равно(Data["Field2"]);

    Return Result;

EndFunction

Function Check_HTTP_StartMultipartBody(Val Result, Val Option, Image = "")

    Try
        Result["origin"] = "***";
        ResponseFile = Result["files"]["file1"];
        Result["files"]["file1"] = "...";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(StrStartWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);

    OPI_TypeConversion.GetBinaryData(Image);
    TextB64 = "data:image/png;base64," + Base64String(Image);
    TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");

    ExpectsThat(Result["form"]["Field1"]).Равно("Text");
    ExpectsThat(Result["form"]["Field2"]).Равно("10");
    ExpectsThat(ResponseFile).Равно(TextB64);

    Return Result;

EndFunction

Function Check_HTTP_AddMultipartFormDataFile(Val Result, Val Option, Image = "")

    Try
        Result["origin"] = "***";
        ResponseFile = Result["files"]["file1"];
        Result["files"]["file1"] = "...";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(StrStartWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);

    OPI_TypeConversion.GetBinaryData(Image);
    TextB64 = "data:image/png;base64," + Base64String(Image);
    TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");

    ExpectsThat(Result["form"]["Field1"]).Равно("Text");
    ExpectsThat(Result["form"]["Field2"]).Равно("10");
    ExpectsThat(ResponseFile).Равно(TextB64);

    Return Result;

EndFunction

Function Check_HTTP_AddMultipartFormDataField(Val Result, Val Option, Image = "")

    Try
        Result["origin"] = "***";
        ResponseFile = Result["files"]["file1"];
        Result["files"]["file1"] = "...";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(StrStartWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);

    OPI_TypeConversion.GetBinaryData(Image);
    TextB64 = "data:image/png;base64," + Base64String(Image);
    TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");

    ExpectsThat(Result["form"]["Field1"]).Равно("Text");
    ExpectsThat(Result["form"]["Field2"]).Равно("10");
    ExpectsThat(ResponseFile).Равно(TextB64);

    Return Result;

EndFunction

Function Check_HTTP_AddDataAsRelated(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(StrStartWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);

    Return Result;

EndFunction

Function Check_HTTP_UseEncoding(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    Encoding = "Windows-1251";
    ExpectsThat(Result["headers"]["Content-Type"]).Равно("text/plain; charset=" + Encoding);

    Return Result;

EndFunction

Function Check_HTTP_UseGzipCompression(Val Result, Val Option)

    If Option = "Enabled" Then
        Compression = "gzip";
    Else
        Compression = Undefined;
    EndIf;

    ExpectsThat(Result.Headers["Accept-Encoding"]).Равно(Compression);

    Return Result;

EndFunction

Function Check_HTTP_MaxAttempts(Val Result, Val Option)

    ExpectsThat(Result["MaxAttempts"]).Равно(10);

    Return Result;

EndFunction

Function Check_HTTP_MaxRedirects(Val Result, Val Option)

    ExpectsThat(Result["MaxRedirects"]).Равно(15);

    Return Result;

EndFunction

Function Check_HTTP_ReturnSettings(Val Result, Val Option)

    If Option = "Single" Then

        ExpectsThat(Result).Равно("UTF-8");

    ElsIf Option = "Nonexistent" Then

        ExpectsThat(ValueIsFilled(Result)).Равно(False);

    Else

        ExpectsThat(Result).ИмеетТип("Structure");

        If Option = "Array" Then

            ExpectsThat(Result.Count()).Равно(2);
            ExpectsThat(ValueIsFilled(Result["MaxAttempts"])).Равно(True);
            ExpectsThat(ValueIsFilled(Result["MaxRedirects"])).Равно(True);

        EndIf;

    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_UseBodyFiledsAtOAuth(Val Result, Val Option, LogAsString = "")

    If Option = "Enabled" Then
        ExpectsThat(StrFind(Result, "adding body fields to the signature string") <> 0).Равно(True);
    Else

        Try
            Result["origin"] = "***";
            Result["files"]["file1"] = "...";
        Except

            Try
                Log = Result.GetLog(True);
            Except
                Raise GetStringFromBinaryData(Result);
            EndTry;

            Raise Log;

        EndTry;

        ExpectsThat(StrFind(LogAsString, "adding body fields to the signature string")).Равно(0);

    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_SetHeaders(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    If Option = "Rewrite" Then
        ExpectsThat(Result["headers"]["X-Header1"]).Равно("Value1");
        ExpectsThat(Result["headers"]["X-Header2"]).Равно("Value2");
        ExpectsThat(Result["headers"]["Authorization"]).Равно("Bearer 1111");
    Else
        ExpectsThat(Result["headers"]["X-Header1"]).Равно("Value1");
        ExpectsThat(Result["headers"]["X-Header2"]).Равно("Value2");
    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_AddHeader(Val Result, Val Option)

    If Option = "Replace" Then

        ExpectsThat(Result["headers"]["X-Header1"]).Равно("Value1");
        ExpectsThat(Result["headers"]["X-Header2"]).Равно("Value2");
        ExpectsThat(Result["headers"]["X-Header3"]).Равно(Undefined);
        ExpectsThat(Result["headers"]["X-Header4"]).Равно(Undefined);
        ExpectsThat(Result["headers"]["Authorization"]).Равно("Bearer 1111");

    ElsIf Option = "Addition" Then

        ExpectsThat(Result["headers"]["X-Header1"]).Равно("Value1");
        ExpectsThat(Result["headers"]["X-Header2"]).Равно("Value2");
        ExpectsThat(Result["headers"]["X-Header3"]).Равно("BadValue");
        ExpectsThat(Result["headers"]["X-Header4"]).Равно("BadValue");
        ExpectsThat(Result["headers"]["Authorization"]).Равно("Bearer 1111");

    Else

        Try
            Result["origin"] = "***";
        Except
            Try
                Raise Result.GetLog(True);
            Except
                Raise GetStringFromBinaryData(Result);
            EndTry;
        EndTry;

        ExpectsThat(Result["headers"]["X-Header1"]).Равно("Value1");
        ExpectsThat(Result["headers"]["X-Header2"]).Равно("Value2");

    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_AddBasicAuthorization(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    Data = GetBinaryDataFromString("user:password");
    Basic = "Basic " + Base64String(Data);
    ExpectsThat(Result["headers"]["Authorization"]).Равно(Basic);

    Return Result;

EndFunction

Function Check_HTTP_AddBearerAuthorization(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(Result["headers"]["Authorization"]).Равно("Bearer " + "123123");

    Return Result;

EndFunction

Function Check_HTTP_AddAWS4Authorization(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(StrStartWith(Result["headers"]["Authorization"], "AWS4")).Равно(True);
    ExpectsThat(Result["headers"]["X-Amz-Content-Sha256"] = Undefined).Равно(False);

    Return Result;

EndFunction

Function Check_HTTP_AddOAuthV1Authorization(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(StrStartWith(Result["headers"]["Authorization"], "OAuth")).Равно(True);

    Return Result;

EndFunction

Function Check_HTTP_SetOAuthV1Algorithm(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(StrStartWith(Result["headers"]["Authorization"], "OAuth")).Равно(True);

    Return Result;

EndFunction

Function Check_HTTP_ProcessRequest(Val Result, Val Option)

    Try
        Result["origin"] = "***";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(Result["args"]).ИмеетТип("Map");
    ExpectsThat(Result["args"].Count()).Равно(0);

    Return Result;

EndFunction

Function Check_HTTP_ExecuteRequest(Val Result, Val Option)

    If Option = "No execution" Then

        ExpectsThat(Result).Равно(Undefined);

    ElsIf Option = "Execution" Then

        ExpectsThat(Result = Undefined).Равно(False);

    Else

        Try
            Result["origin"] = "***";
        Except
            Try
                Raise Result.GetLog(True);
            Except
                Raise GetStringFromBinaryData(Result);
            EndTry;
        EndTry;

        ExpectsThat(Result["args"]).ИмеетТип("Map");
        ExpectsThat(Result["args"].Count()).Равно(0);

    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_ReturnRequest(Val Result, Val Option)

    If Option = "Forced" Then

        ExpectsThat(Result).Равно(Undefined);

    Else

        ExpectsThat(Result).ИмеетТип("HTTPRequest");

    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_ReturnConnection(Val Result, Val Option)

    If Option = "Forced" Then

        ExpectsThat(Result).Равно(Undefined);

    Else

        ExpectsThat(Result).ИмеетТип("HTTPConnection");

    EndIf;

    Return Result;

EndFunction

Function Check_HTTP_ReturnResponse(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("HTTPResponse");

    Return Result;

EndFunction

Function Check_HTTP_ReturnResponseAsJSONObject(Val Result, Val Option)

    Try
        Result["origin"] = "***";
        Result["data"] = "...";
    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(Result).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_HTTP_ReturnResponseAsBinaryData(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("BinaryData");

    Return Result;

EndFunction

Function Check_HTTP_ReturnResponseAsString(Val Result, Val Option)

    Try

        ResultJSON = OPI_Tools.JSONToStructure(Result);

        ResultJSON["origin"] = "***";
        ResultJSON["data"] = "...";

        Result = OPI_Tools.JSONString(ResultJSON);

    Except
        Try
            Raise Result.GetLog(True);
        Except
            Raise GetStringFromBinaryData(Result);
        EndTry;
    EndTry;

    ExpectsThat(Result).ИмеетТип("String");

    Return Result;

EndFunction

Function Check_HTTP_ReturnResponseFilename(Val Result, Val Option, TFN = "")

    BodyFile = New File(TFN);
    BodyFileReturn = New File(Result);

    ExpectsThat(TFN).Равно(Result);
    ExpectsThat(BodyFile.Size()).Равно(BodyFileReturn.Size());
    ExpectsThat(BodyFile.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_HTTP_SetProxy(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("HTTPConnection");
    ExpectsThat(Result.Proxy.User("https")).Равно("user");
    ExpectsThat(Result.Proxy.Password("https")).Равно("password");

    Return Result;

EndFunction

Function Check_HTTP_SetTimeout(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("HTTPConnection");
    ExpectsThat(Result.Timeout).Равно(60);

    Return Result;

EndFunction

Function Check_HTTP_UseURLEncoding(Val Result, Val Option)

    CorrectVariant1 = "/page?param1=search?text&param2=John Doe&param3"
        + "=value&another&param4=кириллица&param5=<script>alert('XSS')</script>";

    ExpectsThat(Result["No encoding"]).Равно(CorrectVariant1);

    CorrectVariant2 = "/page?param1=search%3Ftext&param2=John%20Doe&pa" + "ram3=value%26another&param4=%D0%BA%D0%B8%D1%80%D0%B8%D0%BB%D0%"
        + "BB%D0%B8%D1%86%D0%B0&param5=%3Cscript%3Ealert%28%27XSS%27%29%3C%2Fscript%3E";

    ExpectsThat(Result["With encoding"]).Равно(CorrectVariant2);

    Return Result;

EndFunction

Function Check_HTTP_SplitArraysInURL(Val Result, Val Option)

    Separation = Result["Separation"];
    NoSeparation = Result["No separation"];
    SeparationPhp = Result["PHP"];

    CorrectVariant1 = "/page?arrayfield=val1&arrayfield=val2&arrayfield=val3";
    ExpectsThat(Separation).Равно(CorrectVariant1);

    CorrectVariant2 = "/page?arrayfield=[val1,val2,val3]";
    ExpectsThat(NoSeparation).Равно(CorrectVariant2);

    CorrectVariant3 = "/page?arrayfield[]=val1&arrayfield[]=val2&arrayfield[]=val3";
    ExpectsThat(SeparationPhp).Равно(CorrectVariant3);

    Result = StrTemplate("No separation: %1;
                          |Separation: %2
                          |Separation (php): %3", NoSeparation, Separation, SeparationPhp);

    Return Result;

EndFunction

Function Check_HTTP_SendDataInParts(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");
    Return Result;

EndFunction

Function Check_HTTP_SendPart(Val Result, Val Option)

    ExpectsThat(Result["data"]).Равно("data for");
    ExpectsThat(Result["headers"]["Content-Length"]).Равно("8");
    ExpectsThat(Result["headers"]["Content-Range"]).Равно("bytes 5-12/21");

    Return Result;

EndFunction

Function Check_OpenAI_GetResponse(Val Result, Val Option)

    ExpectsThat(Result["id"]).Заполнено();

    If Not Option = "Image upload" Then
        ExpectsThat(Result["object"]).Равно("chat.completion");
        ExpectsThat(Result["choices"]).ИмеетТип("Array").Заполнено();
    EndIf;

    Return Result;

EndFunction

Function Check_OpenAI_GetEmbeddings(Val Result, Val Option)

    ExpectsThat(Result["model"]).Заполнено();
    ExpectsThat(Result["object"]).Равно("list");
    ExpectsThat(Result["data"]).ИмеетТип("Array").Заполнено();

    Return Result;

EndFunction

Function Check_OpenAI_CreateAssistant(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["model"]).Заполнено();
    ExpectsThat(Result["id"]).Заполнено();
    ExpectsThat(Result["object"]).Равно("assistant");
    ExpectsThat(Result["name"]).Равно("Math tutor");

    AssistantID = Result["id"];
    WriteParameter("OpenAI_Assistant", AssistantID);
    OPI_Tools.AddField("OpenAI_Assistant", AssistantID, "String", Parameters);

    Return Result;

EndFunction

Function Check_OpenAI_DeleteAssistant(Val Result, Val Option, AssistantID = "")

    ExpectsThat(Result["id"]).Равно(AssistantID);
    ExpectsThat(Result["object"]).Равно("assistant.deleted");
    ExpectsThat(Result["deleted"]).Равно(True);

    Return Result;

EndFunction

Function Check_OpenAI_RetrieveAssistant(Val Result, Val Option)

    ExpectsThat(Result["model"]).Заполнено();
    ExpectsThat(Result["id"]).Заполнено();
    ExpectsThat(Result["object"]).Равно("assistant");
    ExpectsThat(Result["name"]).Равно("Math tutor");

    Return Result;

EndFunction

Function Check_OpenAI_GetAssistantsList(Val Result, Val Option)

    ExpectsThat(Result["data"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_OpenAI_UploadFile(Val Result, Val Option, Parameters = "", FileName = "", Size = "")

    ExpectsThat(Result["id"]).Заполнено();
    ExpectsThat(Result["object"]).Равно("file");
    ExpectsThat(Result["filename"]).Равно(FileName);
    ExpectsThat(Result["bytes"]).Равно(Size);
    ExpectsThat(Result["purpose"]).Равно("assistants");

    FileID = Result["id"];
    WriteParameter("OpenAI_File", FileID);
    OPI_Tools.AddField("OpenAI_File", FileID, "String", Parameters);

    Return Result;

EndFunction

Function Check_OpenAI_DeleteFile(Val Result, Val Option, FileID = "")

    ExpectsThat(Result["id"]).Равно(FileID);
    ExpectsThat(Result["object"]).Равно("file");
    ExpectsThat(Result["deleted"]).Равно(True);

    Return Result;

EndFunction

Function Check_OpenAI_GetFileInformation(Val Result, Val Option)

    ExpectsThat(Result["id"]).Заполнено();
    ExpectsThat(Result["object"]).Равно("file");

    Return Result;

EndFunction

Function Check_OpenAI_GetFilesList(Val Result, Val Option)

    ExpectsThat(Result["data"]).ИмеетТип("Array");

    Return Result;

EndFunction

Function Check_OpenAI_DownloadFile(Val Result, Val Option, Parameters = "")

    File = Parameters["Picture"];
    OPI_TypeConversion.GetBinaryData(File);

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() >= File.Size() + 2).Равно(True);

    Return Result;

EndFunction

Function Check_OpenAI_GetMessageStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_OpenAI_GetImageMessageStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_OpenAI_GenerateSpeech(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() >= 137516).Равно(True);

    //@skip-check missing-temporary-file-deletion
    TFN = GetTempFileName("wav");
    Result.Write(TFN);

    WriteParameter("OpenAI_Speech", TFN);
    OPI_Tools.AddField("OpenAI_Speech", TFN, "String", Parameters);

    Return Result;

EndFunction

Function Check_OpenAI_CreateTranscription(Val Result, Val Option)

    Text = Lower(Result["text"]);
    ExpectsThat(StrFind(Text, "attack") > 0).Равно(True);
    ExpectsThat(StrFind(Text, "fire") > 0).Равно(True);
    ExpectsThat(StrFind(Text, "orion") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_OpenAI_GetImages(Val Result, Val Option)

    ExpectsThat(Result["data"]).Заполнено();
    ExpectsThat(Result["created"]).Заполнено();

    Return Result;

EndFunction

Function Check_OpenAI_GetModelList(Val Result, Val Option)

    ExpectsThat(Result["object"]).Равно("list");
    ExpectsThat(Result["data"]).ИмеетТип("Array").Заполнено();

    Return Result;

EndFunction

Function Check_OpenAI_GetAssistantMessage(Val Result, Val Option, Check = "")

    ExpectsThat(Result).Равно(Check);

    Return Result;

EndFunction

Function Check_OpenAI_GetUserMessage(Val Result, Val Option, Check = "")

    ExpectsThat(Result).Равно(Check);

    Return Result;

EndFunction

Function Check_OpenAI_GetSystemMessage(Val Result, Val Option, Check = "")

    ExpectsThat(Result).Равно(Check);

    Return Result;

EndFunction

Function Check_MSSQL_Extended_ExecuteQueryWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "not connected") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_MSSQL_Extended_ConnectionWithoutString(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "empty connection") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_MSSQL_Extended_Reconnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsRetry = StrFind(ErrorText, "already") > 0
        Or StrFind(ErrorText, "initialized") > 0
        Or StrFind(ErrorText, "connected") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsRetry).Равно(True);

    Return Result;

EndFunction

Function Check_MSSQL_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_MSSQL_GenerateConnectionString(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("String").Заполнено();

    Return Result;

EndFunction

Function Check_MSSQL_CreateConnection(Val Result, Val Option)

    Result = String(TypeOf(Result));
    ExpectsThat(Result).Равно("AddIn.OPI_MSSQL.Main");

    Return Result;

EndFunction

Function Check_MSSQL_CloseConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MSSQL_IsConnector(Val Result, Val Option)

    ExpectsThat(Result).Равно(True);

    Return Result;

EndFunction

Function Check_MSSQL_ExecuteSQLQuery(Val Result, Val Option, Image = "")

    If Option = "Connection" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_MSSQL.Main");

    ElsIf ValueIsFilled(Option) Then

        ExpectsThat(Result["result"]).Равно(True);

    Else

        Blob = Result["data"][0]["Data"];

        Result["data"][0]["Data"] = "Binary";
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Blob.Size()).Равно(Image.Size());

    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_GetTLSSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_MSSQL_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_CreateDatabase(Val Result, Val Option)

    If Option = "Openning" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_MSSQL.Main");

    ElsIf Option = "Existing" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_CreateTable(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then
        ExpectsThat(Result["result"]).Равно(True);
    Else
        ExpectsThat(Result["result"]).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_AddRecords(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MSSQL_GetRecords(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Not ValueIsFilled(Option) Then

        If ValueIsFilled(Result["data"]) Then

            Result["data"][0]["varbinary_field"] = "Binary";

        EndIf;

    Else
        ExpectsThat(Result["data"].Count()).Равно(5);
    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_UpdateRecords(Val Result, Val Option, Count = "", FieldsStructure = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        ExpectsThat(Result["data"].Count()).Равно(Count);

        For N = 0 To Result["data"].UBound() Do

            For Each Value In FieldsStructure Do
                Result["data"][N][Value.Key] = Value.Value;
            EndDo;

        EndDo;
    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_DeleteRecords(Val Result, Val Option, Count = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then
        ExpectsThat(Result["data"].Count()).Равно(Count);
    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_DeleteTable(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MSSQL_DeleteDatabase(Val Result, Val Option)

    If Option = "Openning" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_MSSQL.Main");

    ElsIf Option = "Error" Or Option = "Connection error" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_ClearTable(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then
        ExpectsThat(Result["data"].Count()).Равно(0);
    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_GetTableInformation(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then
        ExpectsThat(Result["data"].Count()).Равно(16);
    Else
        ExpectsThat(Result["data"].Count()).Равно(0);
    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_AddTableColumn(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        Found = False;

        For Each Column In Result["data"] Do

            If Column["column_name"] = "new_field" Then

                ExpectsThat(Lower(Column["data_type"])).Равно("bigint");
                Found = True;
            EndIf;

        EndDo;

        ExpectsThat(Found).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_DeleteTableColumn(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        Found = False;

        For Each Column In Result["data"] Do

            If Column["column_name"] = "new_field" Then
                Found = True;
            EndIf;

        EndDo;

        ExpectsThat(Found).Равно(False);

    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_EnsureTable(Val Result, Val Option, ColoumnsStruct = "")

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        ExpectsThat(Result["data"].Count()).Равно(ColoumnsStruct.Count());

        For Each Column In Result["data"] Do
            ExpectsThat(Lower(Column["data_type"])).Равно(Lower(ColoumnsStruct[Column["column_name"]]));
        EndDo;

    Else
        ExpectsThat(Result["commit"]["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_EnsureRecords(Val Result, Val Option)

    If Option = "Insertion" Or Option = "Updating" Then

        ExpectsThat(Result["result"]).Равно(True);

    ElsIf Option = "Insertion check" Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count()).Равно(2);

    ElsIf Option = "Updating check" Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count()).Равно(3);

        Found = False;

        For Each Record In Result["data"] Do
            If Record["id"] = 1 Then
                ExpectsThat(Record["name"]).Равно("Vitaly Updated");
                ExpectsThat(Record["salary"]).Равно(1500.50);
                Found = True;
            EndIf;
        EndDo;

        ExpectsThat(Found).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MSSQL_GetRecordsFilterStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_FTP_Extended_GetGreetingWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "not connected") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_FTP_Extended_ConnectionWithoutAddress(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "empty address") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_FTP_Extended_Reconnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsRetry = StrFind(ErrorText, "already") > 0
        Or StrFind(ErrorText, "initialized") > 0
        Or StrFind(ErrorText, "connected") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsRetry).Равно(True);

    Return Result;

EndFunction

Function Check_FTP_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_FTP_CreateConnection(Val Result, Val Option)

    Result = String(TypeOf(Result));
    ExpectsThat(Result).Равно("AddIn.OPI_FTP.Main");

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_GetWelcomeMessage(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]).Заполнено();

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_GetProtocolFeatureList(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]).Заполнено();

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_Ping(Val Result, Val Option)

    If IsCLITest() Then
        ExpectsThat(Lower(Result)).Равно("true");
    Else
        ExpectsThat(Result).Равно(True);
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_ExecuteCustomCommand(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["status"]).Заполнено();
    ExpectsThat(Result["data"]).Заполнено();

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_ExecuteArbitraryCommand(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["status"]).Заполнено();
    ExpectsThat(Result["data"]).Заполнено();

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_GetCurrentDirectory(Val Result, Val Option, Parameters = "")

    Path = Result["path"];

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Path).Заполнено();

    WriteParameter("FTP_RootPath", Path);
    OPI_Tools.AddField("FTP_RootPath", Path, "String", Parameters);

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_ChangeCurrentDirectory(Val Result, Val Option, Path = "")

    ExpectsThat(Result["result"]).Равно(True);

    If StrFind(Option, "Check") And Not IsCLITest() Then
        ExpectsThat(StrEndsWith(Result["path"], Path)).Равно(True);
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_GetConnectionConfiguration(Val Result, Val Option, Parameters = "")

    If StrFind(Option, "Check") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]).Заполнено();
        ExpectsThat(Result["close_connection"]["result"]).Равно(True);

    Else

        UseProxy = Parameters["Proxy"];
        FTPS = Parameters["TLS"];

        If TypeOf(Result) = Type("Structure") Then

            ExpectsThat(Result.Property("set")).Равно(True);
            Result["set"]["password"] = "***";

            If FTPS Then
                ExpectsThat(Result.Property("tls")).Равно(True);
            EndIf;

            If UseProxy Then
                ExpectsThat(Result.Property("proxy")).Равно(True);
                Result["proxy"]["password"] = "***";
            EndIf;

        Else

            ExpectsThat(Result["set"] <> Undefined).Равно(True);
            Result["set"]["password"] = "***";

            If FTPS Then
                ExpectsThat(Result["tls"] <> Undefined).Равно(True);
            EndIf;

            If UseProxy Then
                ExpectsThat(Result["proxy"] <> Undefined).Равно(True);
                Result["proxy"]["password"] = "***";
            EndIf;

        EndIf;

    EndIf;

    Return Result;

EndFunction

Function Check_FTP_CloseConnection(Val Result, Val Option)

    If StrFind(Option, "Openning") > 0 Then
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_FTP.Main");
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_IsConnector(Val Result, Val Option)

    If StrFind(Option, "Openning") > 0 Then
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_FTP.Main");
    Else
        ExpectsThat(Result).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_GetConnectionSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Result["password"] = "***";

    Return Result;

EndFunction

Function Check_FTP_GetProxySettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Result["password"] = "***";

    Return Result;

EndFunction

Function Check_FTP_GetTLSSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_FTP_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_FTP_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_FTP_CreateNewDirectory(Val Result, Val Option, Primary = False)

    If StrFind(Option, "Deletion") > 0 Then
        Return Result;
    EndIf;

    If Primary Or StrFind(Option, "Nested") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);

    ElsIf StrFind(Option, "Check 1") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]).ИмеетТип("Array").ИмеетДлину(1);
        ExpectsThat(Result["data"][0]["name"]).Равно("another_one");

    ElsIf StrFind(Option, "Check 2") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]).ИмеетТип("Array").ИмеетДлину(1);
        ExpectsThat(Result["data"][0]["objects"]).ИмеетТип("Array").ИмеетДлину(1);

    Else

        ExpectsThat(Result["result"]).Равно(False);

    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_ListObjects(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If StrFind(Option, "File") > 0 Then
        ExpectsThat(Result["data"]).ИмеетТип("Array").ИмеетДлину(0);
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_UploadFile(Val Result, Val Option, Size = "")

    ExpectsThat(Result["bytes"]).Равно(Size);

    If Not StrFind(Option, "Size 1") >  0 Or StrFind(Option, "Size 2") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);

    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_DeleteFile(Val Result, Val Option)

    If StrFind(Option, "Nonexistent") > 0 Then

        ExpectsThat(Result["result"]).Равно(False);

    ElsIf StrFind(Option, "Check") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]).ИмеетТип("Array").ИмеетДлину(1);

    Else

        ExpectsThat(Result["result"]).Равно(True);

    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_DeleteDirectory(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_ClearDirectory(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If StrFind(Option, "Check") > 0 Then
        ExpectsThat(Result["data"]).ИмеетТип("Array").ИмеетДлину(0);
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_GetObjectSize(Val Result, Val Option)

    If StrFind(Option, "Nonexistent") > 0 Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_UpdatePath(Val Result, Val Option)

    If StrFind(Option, "List, back") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]).ИмеетТип("Array").ИмеетДлину(1);
        ExpectsThat(Result["data"][0]["path"]).Равно("new_dir");
        ExpectsThat(Result["data"][0]["objects"][0]["path"]).Равно("new_dir/pic_from_disk.png");

    ElsIf StrFind(Option, "List") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]).ИмеетТип("Array").ИмеетДлину(1);
        ExpectsThat(Result["data"][0]["path"]).Равно("brand_new_dir");
        ExpectsThat(Result["data"][0]["objects"][0]["path"]).Равно("brand_new_dir/pic_copy.png");

    ElsIf StrFind(Option, "Check, old") > 0 Then

        ExpectsThat(Result["result"]).Равно(False);

    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_SaveFile(Val Result, Val Option, ResultSize = "", CheckSize = "")

    If StrFind(Option, "File size") > 0 Then
        ExpectsThat(Result).Равно(ResultSize);
        ExpectsThat(Result).Равно(CheckSize);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_FTP_GetFileData(Val Result, Val Option, CheckSize = "")

    If StrFind(Option, "File size") > 0 Then
        ExpectsThat(Result).Равно(CheckSize);
    ElsIf StrFind(Option, "Size") > 0 Then
        ExpectsThat(Result["result"]).Равно(True);
    Else
        ExpectsThat(Result).ИмеетТип("BinaryData");
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_SSH_CreateConnection(Val Result, Val Option)

    Result = String(TypeOf(Result));
    ExpectsThat(Result).Равно("AddIn.OPI_SSH.Main");

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_SSH_ExecuteCommand(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["stderr"]).Равно("");
    ExpectsThat(Result["exit_code"]).Равно("0");

    Return Result;

EndFunction

Function Check_SSH_GetConnectionConfiguration(Val Result, Val Option)

    If StrFind(Option, "Check") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["stderr"]).Равно("");
        ExpectsThat(Result["stdout"]).Заполнено();
        ExpectsThat(Result["exit_code"]).Равно("0");
        ExpectsThat(Result["close_connection"]["result"]).Равно(True);

    Else

        ExpectsThat(Result["set"]).Заполнено();

        If OPI_Tools.CollectionFieldExists(Result["set"], "password") Then
            Result["set"]["password"] = "***";
        EndIf;

        If OPI_Tools.CollectionFieldExists(Result["set"], "key_path") Then
            Result["set"]["key_path"] = "./ssh_key";
            Result["set"]["pub_path"] = "./ssh_key.pub";
        EndIf;

        If OPI_Tools.CollectionFieldExists(Result, "proxy") Then

            ExpectsThat(Result["proxy"]).Заполнено();
            Result["proxy"]["password"] = "***";

        EndIf;

    EndIf;

    Return Result;

EndFunction

Function Check_SSH_CloseConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_SSH_IsConnector(Val Result, Val Option)

    If StrFind(Option, "Error") Then
        ExpectsThat(Result).Равно(False);
    Else
        ExpectsThat(Result).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SSH_Extended_ExecuteCommandWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "no session") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_SSH_Extended_ConnectionWithoutSettings(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsSettingsError = StrFind(ErrorText, "no configuration") > 0
        Or StrFind(ErrorText, "no settings") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsSettingsError).Равно(True);

    Return Result;

EndFunction

Function Check_SSH_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_SSH_GetSettingsLoginPassword(Val Result, Val Option)

    ExpectsThat(Result["auth_type"]).Равно("password");
    ExpectsThat(Result["host"]).Заполнено();
    ExpectsThat(Result["port"]).Заполнено();
    ExpectsThat(Result["username"]).Заполнено();
    ExpectsThat(Result["password"]).Заполнено();

    Result["password"] = "***";

    Return Result;

EndFunction

Function Check_SSH_GetSettingsPrivateKey(Val Result, Val Option)

    ExpectsThat(Result["auth_type"]).Равно("private_key");
    ExpectsThat(Result["host"]).Заполнено();
    ExpectsThat(Result["port"]).Заполнено();
    ExpectsThat(Result["username"]).Заполнено();
    ExpectsThat(Result["key_path"]).Заполнено();
    ExpectsThat(Result["pub_path"]).Заполнено();

    Result["key_path"] = "./ssh_key";
    Result["pub_path"] = "./ssh_key.pub";

    Return Result;

EndFunction

Function Check_SSH_GetSettingsViaAgent(Val Result, Val Option)

    ExpectsThat(Result["auth_type"]).Равно("agent");
    ExpectsThat(Result["host"]).Заполнено();
    ExpectsThat(Result["port"]).Заполнено();
    ExpectsThat(Result["username"]).Заполнено();

    Return Result;

EndFunction

Function Check_SSH_GetSettingsKI(Val Result, Val Option)

    ExpectsThat(Result["auth_type"]).Равно("keyboard_interactive");
    ExpectsThat(Result["host"]).Заполнено();
    ExpectsThat(Result["port"]).Заполнено();
    ExpectsThat(Result["username"]).Заполнено();
    ExpectsThat(Result["keyboard_responses"]).Заполнено();

    Result["keyboard_responses"][1] = "***";

    Return Result;

EndFunction

Function Check_SSH_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_SSH_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_SSH_GetProxySettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Result["password"] = "***";

    Return Result;

EndFunction

Function Check_SFTP_Extended_GetListWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "no session") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_SFTP_Extended_ConnectionWithoutSettings(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsSettingsError = StrFind(ErrorText, "no configuration") > 0
        Or StrFind(ErrorText, "no settings") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsSettingsError).Равно(True);

    Return Result;

EndFunction

Function Check_SFTP_Extended_Reconnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsRetry = StrFind(ErrorText, "already") > 0
        Or StrFind(ErrorText, "initialized") > 0
        Or StrFind(ErrorText, "connected") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsRetry).Равно(True);

    Return Result;

EndFunction

Function Check_SFTP_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_SFTP_CreateConnection(Val Result, Val Option)

    Result = String(TypeOf(Result));
    ExpectsThat(Result).Равно("AddIn.OPI_SSH.Main");

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_CreateNewDirectory(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_SFTP_DeleteDirectory(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_SFTP_GetCurrentDirectory(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["path"]).Заполнено();

    Return Result;

EndFunction

Function Check_SFTP_ListObjects(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]).ИмеетТип("Array").Заполнено();
    ExpectsThat(Result["data"][0]["uid"]).Заполнено();
    ExpectsThat(Result["data"][0]["is_directory"]).Равно(True);

    If StrFind(Option, "No recursion") = 0 Then

        ExpectsThat(Result["data"][0]["objects"].Count()).Равно(3);
        ExpectsThat(Result["data"][0]["objects"][1]["objects"].Count()).Равно(1);
        ExpectsThat(Result["data"][0]["objects"][2]["objects"].Count()).Равно(2);

        ExpectsThat(Result["data"][0]["objects"][0]["objects"]).Равно(Undefined);

    Else

        ExpectsThat(Result["data"][0]["objects"]).Равно(Undefined);

    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_ChangeCurrentDirectory(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If StrFind(Option, "Check") > 0 Then
        ExpectsThat(Result["path"]).Равно("/config/test_folder");
    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_UploadFile(Val Result, Val Option, Size = "")

    If StrFind(Option, "File size") > 0 Then

        ExpectsThat(Result).Равно(Size);

    Else

        ExpectsThat(Result["bytes"]).Равно(Size);
        ExpectsThat(Result["result"]).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_DeleteFile(Val Result, Val Option)

    If StrFind(Option, "Nonexistent") > 0 Then

        ExpectsThat(Result["result"]).Равно(False);

    ElsIf StrFind(Option, "Check") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]).ИмеетТип("Array").ИмеетДлину(0);

    Else

        ExpectsThat(Result["result"]).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_IsConnector(Val Result, Val Option)

    If StrFind(Option, "Error") Then
        ExpectsThat(Result).Равно(False);
    Else
        ExpectsThat(Result).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_GetSettingsLoginPassword(Val Result, Val Option)

    ExpectsThat(Result["auth_type"]).Равно("password");
    ExpectsThat(Result["host"]).Заполнено();
    ExpectsThat(Result["port"]).Заполнено();
    ExpectsThat(Result["username"]).Заполнено();
    ExpectsThat(Result["password"]).Заполнено();

    Result["password"] = "***";

    Return Result;

EndFunction

Function Check_SFTP_GetSettingsPrivateKey(Val Result, Val Option)

    ExpectsThat(Result["auth_type"]).Равно("private_key");
    ExpectsThat(Result["host"]).Заполнено();
    ExpectsThat(Result["port"]).Заполнено();
    ExpectsThat(Result["username"]).Заполнено();
    ExpectsThat(Result["key_path"]).Заполнено();
    ExpectsThat(Result["pub_path"]).Заполнено();

    Result["key_path"] = "./ssh_key";
    Result["pub_path"] = "./ssh_key.pub";

    Return Result;

EndFunction

Function Check_SFTP_GetSettingsViaAgent(Val Result, Val Option)

    ExpectsThat(Result["auth_type"]).Равно("agent");
    ExpectsThat(Result["host"]).Заполнено();
    ExpectsThat(Result["port"]).Заполнено();
    ExpectsThat(Result["username"]).Заполнено();

    Return Result;

EndFunction

Function Check_SFTP_GetSettingsKI(Val Result, Val Option)

    ExpectsThat(Result["auth_type"]).Равно("keyboard_interactive");
    ExpectsThat(Result["host"]).Заполнено();
    ExpectsThat(Result["port"]).Заполнено();
    ExpectsThat(Result["username"]).Заполнено();
    ExpectsThat(Result["keyboard_responses"]).Заполнено();

    Result["keyboard_responses"][1] = "***";

    Return Result;

EndFunction

Function Check_SFTP_GetProxySettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Result["password"] = "***";

    Return Result;

EndFunction

Function Check_SFTP_GetConnectionConfiguration(Val Result, Val Option)

    If StrFind(Option, "Check") > 0 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["stderr"]).Равно("");
        ExpectsThat(Result["stdout"]).Заполнено();
        ExpectsThat(Result["exit_code"]).Равно("0");
        ExpectsThat(Result["close_connection"]["result"]).Равно(True);

    Else

        ExpectsThat(Result["set"]).Заполнено();

        If OPI_Tools.CollectionFieldExists(Result["set"], "password") Then
            Result["set"]["password"] = "***";
        EndIf;

        If OPI_Tools.CollectionFieldExists(Result["set"], "key_path") Then
            Result["set"]["key_path"] = "./ssh_key";
            Result["set"]["pub_path"] = "./ssh_key.pub";
        EndIf;

        If OPI_Tools.CollectionFieldExists(Result, "proxy") Then

            ExpectsThat(Result["proxy"]).Заполнено();
            Result["proxy"]["password"] = "***";

        EndIf;

    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_CloseConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_SFTP_SaveFile(Val Result, Val Option, CheckSize = "")

    If StrFind(Option, "File size") > 0 Then
        ExpectsThat(Result).Равно(CheckSize);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_GetFileData(Val Result, Val Option, CheckSize = "")

    If StrFind(Option, "File size") > 0 Then
        ExpectsThat(Result).Равно(CheckSize);
    ElsIf StrFind(Option, "Size") > 0 Then
        ExpectsThat(Result["result"]).Равно(True);
    Else
        ExpectsThat(Result).ИмеетТип("BinaryData");
    EndIf;

    If StrFind(Option, "HTTP") Then
        OPI_Tools.Pause(2);
    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_UpdatePath(Val Result, Val Option)

    If StrFind(Option, "Check, Old") Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_SFTP_GetFileInformation(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]).Заполнено();
    ExpectsThat(Result["data"]["size"]).Заполнено();
    ExpectsThat(Result["data"]["modified"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenMax_FormAccessParameters(Val Result, Val Option)

    Result.Insert("apiTokenInstance", "***");
    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_GetAuthorizationCode(Val Result, Val Option)

    ExpectsThat(Result["data"]["reason"]).Равно("already_registered");
    Return Undefined;

EndFunction

Function Check_GreenMax_LogoutInstance(Val Result, Val Option)

    ExpectsThat(Result["isLogout"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_SendAuthorizationCode(Val Result, Val Option)

    Return Undefined;

EndFunction

Function Check_GreenMax_GetInstanceStatus(Val Result, Val Option)

    ExpectsThat(Result["stateInstance"]).Равно("authorized");

    Return Result;

EndFunction

Function Check_GreenMax_RebootInstance(Val Result, Val Option)

    ExpectsThat(Result["isReboot"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_GetInstanceSettingsStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_GreenMax_GetInstanceSettings(Val Result, Val Option, Parameters = "")

    Try
        JSON = OPI_Tools.JSONString(Result);
        JSON = StrReplace(JSON, Parameters["GreenMax_AccountID"], "1234567890@c.us");

        Result = OPI_Tools.JsonToStructure(JSON, True);
    Except
        Message("JSON Error");
    EndTry;

    ExpectsThat(Result["delaySendMessagesMilliseconds"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenMax_SetInstanceSettings(Val Result, Val Option)

    ExpectsThat(Result["saveSettings"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_SetProfilePicture(Val Result, Val Option)

    ExpectsThat(Result["setProfilePicture"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_GetAccountInformation(Val Result, Val Option)

    ExpectsThat(Result["chatId"]).Заполнено();
    ExpectsThat(Result["phone"]).Заполнено();

    Result["chatId"] = "***";
    Result["phone"] = "***";

    Return Result;

EndFunction

Function Check_GreenMax_CheckAccount(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["chatId"]).Заполнено();
    ExpectsThat(Result["exist"]).Равно(True);

    ContactID = Result["chatId"];
    WriteParameter("GreenMax_MyID", ContactID);
    Parameters.Insert("GreenMax_MyID", ContactID);

    Result["chatId"] = "***";

    Return Result;

EndFunction

Function Check_GreenMax_GetContactList(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Array");
    ExpectsThat(Result[0]["chatId"]).Заполнено();

    ContactID = Result[0]["chatId"];
    WriteParameter("GreenMax_ContactID", ContactID);
    Parameters.Insert("GreenMax_ContactID", ContactID);

    Result[0]["chatId"] = "***";
    Result[0]["phoneNumber"] = "***";

    Return Result;

EndFunction

Function Check_GreenMax_GetContactInformation(Val Result, Val Option)

    ExpectsThat(Result["chatId"]).Заполнено();
    ExpectsThat(Result["name"]).Заполнено();
    ExpectsThat(Result["avatar"]).Заполнено();

    Result["chatId"] = "***";
    Result["phoneNumber"] = "***";

    Return Result;

EndFunction

Function Check_GreenMax_GetChatList(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Array");
    ExpectsThat(Result[0]["chatId"]).Заполнено();

    For Each Chat In Result Do
        Chat["phoneNumber"] = "***";
        Chat["chatId"] = "***";
    EndDo;

    Return Result;

EndFunction

Function Check_GreenMax_GetChatAvatar(Val Result, Val Option)

    ExpectsThat(Result["urlAvatar"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenMax_CreateGroup(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["chatId"]).Заполнено();
    ExpectsThat(Result["created"]).Равно(True);

    GroupID = Result["chatId"];
    WriteParameter("GreenMax_GroupID", GroupID);
    Parameters.Insert("GreenMax_GroupID", GroupID);

    Return Result;

EndFunction

Function Check_GreenMax_RemoveGroupMember(Val Result, Val Option)

    ExpectsThat(Result["removeParticipant"] <> Undefined).Равно(True);

    Return Undefined;

EndFunction

Function Check_GreenMax_AddGroupMember(Val Result, Val Option)

    ExpectsThat(Result["addParticipant"] <> Undefined).Равно(True);

    Return Undefined;

EndFunction

Function Check_GreenMax_LeaveGroup(Val Result, Val Option)

    ExpectsThat(Result["leaveGroup"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_UpdateGroupName(Val Result, Val Option)

    ExpectsThat(Result["updateGroupName"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_GetGroupInformation(Val Result, Val Option)

    ExpectsThat(Result["creation"]).Заполнено();
    ExpectsThat(Result["subject"]).Равно("New group");

    Result["chatId"] = "***";

    For Each Member In Result["participants"] Do
        Member["chatId"] = "***";
    EndDo;

    Return Result;

EndFunction

Function Check_GreenMax_ChangeGroupSettings(Val Result, Val Option)

    ExpectsThat(Result["updateGroupSettings"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_GetGroupSettingsStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_GreenMax_SetAdminRights(Val Result, Val Option)

    ExpectsThat(Result["setGroupAdmin"] <> Undefined).Равно(True);

    Return Undefined;

EndFunction

Function Check_GreenMax_RevokeAdminRights(Val Result, Val Option)

    ExpectsThat(Result["removeAdmin"] <> Undefined ).Равно(True);

    Return Undefined;

EndFunction

Function Check_GreenMax_SetGroupPicture(Val Result, Val Option)

    ExpectsThat(Result["setGroupPicture"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_SendTextMessage(Val Result, Val Option, Val Parameters = "")

    ExpectsThat(Result["idMessage"]).Заполнено();

    MessageID = Result["idMessage"];
    WriteParameter("GreenMax_MessageID", MessageID);
    Parameters.Insert("GreenMax_MessageID", MessageID);

    Return Result;

EndFunction

Function Check_GreenMax_SendFile(Val Result, Val Option, Val Parameters = "")

    ExpectsThat(Result["idMessage"]).Заполнено();

    If Not ValueIsFilled(Option) Then
        MessageID = Result["idMessage"];
        WriteParameter("GreenMax_FileMessageID", MessageID);
        Parameters.Insert("GreenMax_FileMessageID", MessageID);
    EndIf;

    Return Result;

EndFunction

Function Check_GreenMax_SendFileByURL(Val Result, Val Option)

    ExpectsThat(Result["idMessage"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenMax_GetNotification(Val Result, Val Option, Val Parameters = "")

    ExpectsThat(Result["receiptId"]).Заполнено();
    ExpectsThat(Result["body"]).Заполнено();

    If Not ValueIsFilled(Option) Then
        MessageID = Result["receiptId"];
        WriteParameter("GreenMax_ReceiptID", MessageID);
        Parameters.Insert("GreenMax_ReceiptID", MessageID);
    EndIf;

    Return Result;

EndFunction

Function Check_GreenMax_DeleteNotification(Val Result, Val Option, Val Parameters = "")

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_MarkMessagesAsRead(Val Result, Val Option)

    ExpectsThat(Result["setRead"]).ИмеетТип("Boolean");

    Return Result;

EndFunction

Function Check_GreenMax_GetChatMessageHistory(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result).ИмеетТип("Array").ИмеетДлину(3);

    MessageID = Result[0]["idMessage"];
    WriteParameter("GreenMax_MainMessageID", MessageID);
    Parameters.Insert("GreenMax_MainMessageID", MessageID);

    Return Result;

EndFunction

Function Check_GreenMax_GetChatMessage(Val Result, Val Option, MessageID = "")

    ExpectsThat(Result["idMessage"]).Равно(MessageID);
    ExpectsThat(Result["chatId"]).Заполнено();

    Return Result;

EndFunction

Function Check_GreenMax_GetIncomingMessageLog(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result)).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_GetOutgoingMessageLog(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result)).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_GetOutgoingMessageCount(Val Result, Val Option)

    ExpectsThat(Result["count"]).ИмеетТип("Number");

    Return Result;

EndFunction

Function Check_GreenMax_GetOutgoingMessageQueue(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result)).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_ClearOutgoingMessageQueue(Val Result, Val Option)

    ExpectsThat(Result["isCleared"]).Равно(True);

    Return Result;

EndFunction

Function Check_GreenMax_GetIncomingNotificationCount(Val Result, Val Option)

    ExpectsThat(Result["count"]).ИмеетТип("Number");

    Return Result;

EndFunction

Function Check_GreenMax_ClearIncomingNotificationQueue(Val Result, Val Option)

    ExpectsThat(Result["isCleared"]).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_Extended_ExecuteCommandWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "not connected") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_Extended_ConnectionWithoutString(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "empty connection") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_Extended_Reconnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsRetry = StrFind(ErrorText, "already") > 0
        Or StrFind(ErrorText, "initialized") > 0
        Or StrFind(ErrorText, "connected") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsRetry).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_GenerateConnectionString(Val Result, Val Option, Parameters = "")

    Address = "127.0.0.1:1234";
    Login = Parameters["MongoDB_User"];
    Password = Parameters["MongoDB_Password"];
    Base = Parameters["MongoDB_DB"];

    StringTemplate = "mongodb://%1:" + "%2@%3/%4?authSource=admin";
    CheckString = StrTemplate(StringTemplate, Login, Password, Address, Base);
    ReturnString = StrTemplate(StringTemplate, Login, "***", Address, Base);
    ExpectsThat(CheckString).Равно(Result);

    Return ReturnString;

EndFunction

Function Check_MongoDB_CreateConnection(Val Result, Val Option)

    If Option = "Closing" Then
        ExpectsThat(Result["result"]).Равно(True);
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_MongoDB.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_CloseConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_IsConnector(Val Result, Val Option)

    ExpectsThat(Result).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_ExecuteCommand(Val Result, Val Option)

    If Option = "Connection" Then
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_MongoDB.Main");
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_GetDatabase(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]["ok"]).Равно(1);
    ExpectsThat(Result["data"]["db"]).Равно("test_db");

    Return Result;

EndFunction

Function Check_MongoDB_GetListOfBases(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]["databases"]).ИмеетТип("Array").Заполнено();

    Return Result;

EndFunction

Function Check_MongoDB_CreateCollection(Val Result, Val Option)

    If Option = "Existing" Then
        ExpectsThat(Result["result"]).Равно(False);
        ExpectsThat(StrFind(Result["error"], "already exists") > 0).Равно(True);
    Else
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]["ok"]).Равно(1);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_DeleteCollection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]["ok"]).Равно(1);
    ExpectsThat(Result["data"]["ns"]).Равно("test_database.test_collection");

    Return Result;

EndFunction

Function Check_MongoDB_GetCollectionList(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]["ok"]).Равно(1);

    Return Result;

EndFunction

Function Check_MongoDB_InsertDocuments(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]["ok"]).Равно(1);
    Return Result;

EndFunction

Function Check_MongoDB_GetDocuments(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count() > 0).Равно(True);
        ExpectsThat(Result["data"][0]["stringField"]).Равно("Text");

    ElsIf Option = 1 Then
        // Category and price range filter
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"].Count() > 0).Равно(True);

        For Each Document In Result["data"] Do
            ExpectsThat(Document["category"]).Равно("electronics");
            ExpectsThat(Document["price"] >= 100).Равно(True);
            ExpectsThat(Document["price"] <= 400).Равно(True);
        EndDo;

        If Result["data"].Count() > 1 Then
            ExpectsThat(Result["data"][0]["price"] <= Result["data"][1]["price"]).Равно(True);
        EndIf;

    ElsIf Option = 2 Then
        ExpectsThat(Result["result"]).Равно(True);

        For Each Document In Result["data"] Do
            ExpectsThat(Document["inStock"]).Равно(True);
            ExpectsThat(Document["rating"] >= 4).Равно(True);
        EndDo;

        If Result["data"].Count() > 1 Then
            ExpectsThat(Result["data"][0]["rating"] >= Result["data"][1]["rating"]).Равно(True);
        EndIf;

    ElsIf Option = 3 Then
        ExpectsThat(Result["result"]).Равно(True);

        For Each Document In Result["data"] Do

            Found = False;
            For Each Tag In Document["tags"] Do
                If StrFind(Tag, "sale") > 0 Then
                    Found = True;
                    Break;
                EndIf;
            EndDo;

            ExpectsThat(Found).Равно(True);

        EndDo;

    ElsIf Option = 4 Then

        ExpectsThat(Result["result"]).Равно(True);

        For Each Document In Result["data"] Do
            ExpectsThat(Document["details"]["supplier"]).Равно("Supplier A");
            ExpectsThat(Document["details"]["weightKg"] < 3).Равно(True);
        EndDo;

    ElsIf Option = 5 Then

        ExpectsThat(Result["result"]).Равно(True);

        For Each Document In Result["data"] Do
            ExpectsThat(Document["productName"] = Undefined).Равно(False);
            ExpectsThat(Document["price"] = Undefined).Равно(False);
            ExpectsThat(Document["rating"] = Undefined).Равно(False);
            ExpectsThat(Document["category"]).Равно(Undefined);
            ExpectsThat(Document["inStock"]).Равно(Undefined);
            ExpectsThat(Document["details"]).Равно(Undefined);
        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_GetCursor(Val Result, Val Option)

    If Not ValueIsFilled(Option) Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]["cursor"]["firstBatch"].Count()).Равно(1);
        ExpectsThat(Result["data"]["cursor"]["id"] > 0).Равно(True);

    ElsIf Option = 1 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]["cursor"]["firstBatch"].Count() <= 3).Равно(True);

        For Each Document In Result["data"]["cursor"]["firstBatch"] Do
            ExpectsThat(Document["inStock"]).Равно(True);
        EndDo;

    ElsIf Option = 2 Then

        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["data"]["cursor"]["firstBatch"].Count() <= 2).Равно(True);

        For Each Document In Result["data"]["cursor"]["firstBatch"] Do
            ExpectsThat(Document["category"]).Равно("clothing");
        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_GetDocumentBatch(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    Return Result;

EndFunction

Function Check_MongoDB_UpdateDocuments(Val Result, Val Option)

    Option = String(Option);

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);
        ExpectsThat(Result["data"][0]["doubleField"]).Равно(999);

    ElsIf Option = "Check 1" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);

        For Each Doc In Result["data"] Do

            ExpectsThat(Doc["price"]).Равно(777);
            ExpectsThat(Doc["inStock"]).Равно(False);
            ExpectsThat(Doc["rating"]).Равно(5);

        EndDo;

    ElsIf Option = "Check 2" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);
        ExpectsThat(Result["data"][0]["quantity"] > 10).Равно(True);

    ElsIf Option = "Check 3" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);

        For Each Doc In Result["data"] Do

            Found = False;

            For Each Tag In Doc["tags"] Do
                If Tag = "updated" Then
                    Found = True;
                    Break;
                EndIf;
            EndDo;

            ExpectsThat(Found).Равно(True);

        EndDo;

    ElsIf Option = "Check 4" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);

        For Each Doc In Result["data"] Do

            ExpectsThat(Doc["details"]["supplier"]).Равно("Supplier A+");
            ExpectsThat(Doc["details"]["weightKg"]).Равно(2.5);

        EndDo;

    ElsIf Option = "Check 5" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);
        ExpectsThat(Result["data"][0]["productName"]).Равно("New product");
        ExpectsThat(Result["data"][0]["price"]).Равно(1999);

    ElsIf Option = "Check 6" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);

        For Each Doc In Result["data"] Do
            ExpectsThat(Doc["rating"]).Равно(Undefined);
        EndDo;

    ElsIf Option = "Check 7" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);

        For Each Doc In Result["data"] Do

            ExpectsThat(Doc["inStock"]).Равно(False);

            Found = False;

            For Each Tag In Doc["tags"] Do
                If Tag = "discount" Then
                    Found = True;
                    Break;
                EndIf;
            EndDo;

            ExpectsThat(Found).Равно(True);

        EndDo;

    ElsIf Option = "Check 8_1" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);

        For Each Doc In Result["data"] Do

            ExpectsThat(Doc["price"]).Равно(888);
            ExpectsThat(Doc["discounted"]).Равно(True);

        EndDo;

    ElsIf Option = "Check 8_2" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);

        For Each Doc In Result["data"] Do

            Found = False;

            For Each Tag In Doc["tags"] Do
                If Tag = "mass_update" Then
                    Found = True;
                    Break;
                EndIf;
            EndDo;

            ExpectsThat(Found).Равно(True);

        EndDo;

    ElsIf Option = "Check 8_3" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);
        ExpectsThat(Result["data"][0]["productName"]).Равно("Special item from array");
        ExpectsThat(Result["data"][0]["price"]).Равно(1111);

    ElsIf Option = "Check 8_4" Then

        ExpectsThat(Result["data"].Count() > 0).Равно(True);
        For Each Doc In Result["data"] Do
            ExpectsThat(Doc["needsImprovement"]).Равно(True);
        EndDo;

    ElsIf Option = "Obtaining" Then

        ExpectsThat(Result["data"].Count()).Равно(0);

    ElsIf Option = "Getting new" Then

        For Each Element In Result["data"] Do
            ExpectsThat(Element["doubleField"]).Равно(999);
        EndDo;

    ElsIf Option = "5" Then

        ExpectsThat(Result["data"]["upserted"].Count() > 0 Or Result["data"]["nModified"] > 0).Равно(True);

    Else
        ExpectsThat(Result["data"]["nModified"] > 0).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_GetDocumentUpdateStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_DeleteDocuments(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then
        ExpectsThat(Result["data"].Count()).Равно(1);
    ElsIf Option = "Precheck" Then
        ExpectsThat(Result["data"].Count()).Равно(2);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_CreateUser(Val Result, Val Option)

    If Option = "Existing" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_UpdateUser(Val Result, Val Option)

    If Option = "Nonexistent" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_DeleteUser(Val Result, Val Option)

    If Option = "Again" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_GetUsers(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Not ValueIsFilled(Option) Then
        ExpectsThat(Result["data"].Count()).Равно(2);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_GetDatabaseUsers(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]["users"].Count()).Равно(1);

    Return Result;

EndFunction

Function Check_MongoDB_DeleteDatabase(Val Result, Val Option)

    If Option = "Non-existent" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_CreateRole(Val Result, Val Option)

    If Option = "Existing" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_UpdateRole(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_DeleteRole(Val Result, Val Option)

    If Option = "Again" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_MongoDB_GrantRoles(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_RevokeRoles(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_GetRoles(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"]["roles"].Count()).Равно(1);

    Return Result;

EndFunction

Function Check_MongoDB_GetRolePrivilegeStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_MongoDB_GetDocumentDeletionStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_Extended_CallMethodWithoutConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ErrorText = Lower(Result["error"]);
    IsError = StrFind(ErrorText, "not connected") > 0
        Or StrFind(ErrorText, "connection not initialized") > 0;

    ExpectsThat(IsError).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_Extended_ConnectionWithoutAddress(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "empty server") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_Extended_Reconnection(Val Result, Val Option)

    ErrorText = Lower(Result["error"]);
    IsRetry = StrFind(ErrorText, "already") > 0
        Or StrFind(ErrorText, "initialized") > 0
        Or StrFind(ErrorText, "connected") > 0;

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(IsRetry).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_Extended_CallMethodMultipleBinaryFields(Val Result, Val Option, SentData = Undefined)

    ExpectsThat(Result["result"]).Равно(True);

    ResponseData = Result["data"];

    ExpectsThat(ResponseData["f_string"]).Равно(SentData["f_string"]);
    ExpectsThat(ResponseData["f_int32"]).Равно(SentData["f_int32"]);
    ExpectsThat(ResponseData["f_bool"]).Равно(SentData["f_bool"]);

    CheckBinaryDataJanx(ResponseData["f_bytes"], SentData["f_bytes"]);

    ExpectedArray = SentData["f_bytess"];
    ActualArray = ResponseData["f_bytess"];

    ExpectsThat(ActualArray.Count()).Равно(ExpectedArray.Count());

    For Index = 0 To ExpectedArray.UBound() Do
        CheckBinaryDataJanx(ActualArray[Index], ExpectedArray[Index]);
    EndDo;

    Return Result;

EndFunction

Function Check_GRPC_Extended_GetLogOnConnection(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_CreateConnection(Val Result, Val Option)

    If Option = "Closing" Then
        ExpectsThat(Result["result"]).Равно(True);
    ElsIf Option = "Error" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_GRPC.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_GRPC_CloseConnection(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_IsConnector(Val Result, Val Option)

    ExpectsThat(Result).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_GetConnectionParameters(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_GetTlsSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_GetServiceList(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"].Count()).Равно(1);
    Return Result;

EndFunction

Function Check_GRPC_GetMethodList(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"].Count() > 3).Равно(True);
    Return Result;

EndFunction

Function Check_GRPC_GetMethod(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    Return Result;

EndFunction

Function Check_GRPC_ExecuteMethod(Val Result, Val Option, Data = Undefined)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Meta" Then

        ResultAsString = OPI_Tools.JSONString(Result);
        ExpectsThat(StrFind(ResultAsString, "somekey") > 0).Равно(True);

    ElsIf Option = "Meta 2" Then

        ResultAsString = OPI_Tools.JSONString(Result);
        ExpectsThat(StrFind(ResultAsString, "somekey") = 0).Равно(True);
        ExpectsThat(StrFind(ResultAsString, "anotherkey") > 0).Равно(True);

    ElsIf Option = "Empty" Or Option = "Select" Then
        // Successful unary only without comparing response body

    ElsIf OPI_Tools.ThisIsCollection(Data, True) Then

        ResponseData = Result["data"];
        Excluded = StrSplit("f_bytes,f_bytess,f_float", ",");
        ExpectsThat(OPI_Tools.CompareTwoCollections(ResponseData, Data, Excluded)).Равно(True);
        ExpectsThat(Left(String(ResponseData["f_float"]), 4)).Равно(Left(String(Data["f_float"]), 4));
        CheckBinaryDataJanx(ResponseData["f_bytes"], Data["f_bytes"]);

    EndIf;

    Return Result;

EndFunction

Function Check_GRPC_SetMetadata(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    If Option = "Check" Then

        ResultAsString = OPI_Tools.JSONString(Result);
        ExpectsThat(StrFind(ResultAsString, "somekey") > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_GRPC_InitializeServerStream(Val Result, Val Option)

    If Option = "Array" Then
        ExpectsThat(Result.Count() > 0).Равно(True);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_GRPC_InitializeClientStream(Val Result, Val Option, SendCount = Undefined)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(SendCount).Равно(10);

    Return Result;

EndFunction

Function Check_GRPC_InitializeBidirectionalStream(Val Result, Val Option, ResultArray = Undefined)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(ResultArray.Count()).Равно(10);

    For N = 0 To ResultArray.Count() - 1 Do
        ExpectsThat(ResultArray[N]["f_int32"]).Равно(N + 1);
    EndDo;

    Return Result;

EndFunction

Function Check_GRPC_SendMessage(Val Result, Val Option, Closing = Undefined)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Closing["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_GetMessage(Val Result, Val Option, Closing = Undefined, Data = Undefined)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Closing["result"]).Равно(True);

    FieldList = StrSplit("f_bytes,f_bytess,f_float", ",");
    ExpectsThat(Left(String(Result["message"]["f_float"]) , 4)).Равно(Left(String(Data["f_float"]), 4));
    ExpectsThat(OPI_Tools.CompareTwoCollections(Result["message"], Data , FieldList)).Равно(True);

    Return Result;

EndFunction

Function Check_GRPC_CloseStream(Val Result, Val Option)

    If Option = "Sending" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_GRPC_ProcessServerStream(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"].Count()).Равно(3);

    Return Result;

EndFunction

Function Check_GRPC_ProcessClientStream(Val Result, Val Option)

    If Option = "Error" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_GRPC_ProcessBidirectionalStream(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data"].Count()).Равно(10);

    Return Result;

EndFunction

Function Check_GRPC_GetLoggingSettings(Val Result, Val Option)

    If Option = "File" Then

        ExpectsThat(Result["mode"]).Равно("file");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);

    ElsIf Option = "Memory" Then

        ExpectsThat(Result["mode"]).Равно("memory");
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    Else

        ExpectsThat(Result["mode"]).Равно("both");
        ExpectsThat(ValueIsFilled(Result["file_path"])).Равно(True);
        ExpectsThat(ValueIsFilled(Result["max_entries"])).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_GRPC_GetLog(Val Result, Val Option, LogFile = "")

    If Option = "AsString" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("String"));
        ExpectsThat(StrLen(Result) > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    Else

        ExpectsThat(Result["result"]).Равно(True);

        ExpectsThat(Result["logs"]).ИмеетТип("Array");
        ExpectsThat(Result["logs"].Count() > 0).Равно(True);

        LogObject = New File(LogFile);
        ExpectsThat(LogObject.Exists()).Равно(True);
        ExpectsThat(LogObject.Size() > 0).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_GRPC_CompleteSend(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_ClickHouse_ExecuteRequest(Val Result, Val Option)

    If TypeOf(Result["body"]) = Type("BinaryData") Then
        Result.Insert("body", GetStringFromBinaryData(Result["body"]));
    EndIf;

    If Option = "TableCreation" Or Option = "DataInsert" Then

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["status"]).Равно(200);

    ElsIf Option = "JSONSelection" Or Option = "JSONCompactSelection" Then

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["status"]).Равно(200);
        ExpectsThat(Result["body"]).ИмеетТип("Map");

    ElsIf Option = "CSVSelection" Or Option = "TSVSelection" Then

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["status"]).Равно(200);
        ExpectsThat(Result["body"]).ИмеетТип("String");

    ElsIf Option = "ExternalTable" Then

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["body"]).ИмеетТип("Map");
        ExpectsThat(Result["body"]["rows"]).Равно(2);

    ElsIf Option = "AdditionalSettings" Then

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["body"]).ИмеетТип("Map");

    ElsIf Option = "SessionCreation" Or Option = "SessionInsert" Then

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["status"]).Равно(200);

    Else

        // Primary variant - Selection from session temporary table
        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(Result["body"]).ИмеетТип("Map");
        ExpectsThat(Result["body"]["rows"]).Равно(2);

    EndIf;

    Return Result;

EndFunction

Function Check_ClickHouse_CreateGRPCConnection(Val Result, Val Option)

    If Option = "Openning" Then

        Result = String(TypeOf(Result));
        ExpectsThat(Result).Равно("AddIn.OPI_GRPC.Main");

    ElsIf Option = "TableCreation" Or Option = "DataInsert" Then

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);

    ElsIf Option = "Selection" Then

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);

    Else

        ExpectsThat(Result).ИмеетТип("Map").Заполнено();
        ExpectsThat(Result["result"]).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_ClickHouse_GetHTTPConnectionSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "address")).Равно(True);
    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "transport")).Равно(True);
    ExpectsThat(Result["transport"]).Равно("http");

    If Option = "NoAuthorization" Then

        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "auth_type")).Равно(False);

    ElsIf Option = "BasicAuthorization" Then

        ExpectsThat(Result["auth_type"]).Равно("basic");
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "user")).Равно(True);
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "password")).Равно(True);

    ElsIf Option = "JWTAuthorization" Then

        ExpectsThat(Result["auth_type"]).Равно("jwt");
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "token")).Равно(True);

    ElsIf Not ValueIsFilled(Option) Then

        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "headers")).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_ClickHouse_GetGRPCConnectionSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result , True)).Равно(True);
    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "address")).Равно(True);
    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "transport")).Равно(True);
    ExpectsThat(Result["transport"]).Равно("grpc");

    If Option = "NoAuthorization" Then

        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "auth_type")).Равно(False);

    ElsIf Option = "BasicAuthorization" Then

        ExpectsThat(Result["auth_type"]).Равно("basic");
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "user")).Равно(True);
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "password")).Равно(True);

    ElsIf Option = "JWTAuthorization" Then

        ExpectsThat(Result["auth_type"]).Равно("jwt");
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "token")).Равно(True);

    ElsIf Option = "WithMetadata" Then

        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "metadata")).Равно(True);

    ElsIf Not ValueIsFilled(Option) Then

        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "tls")).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_ClickHouse_GetRequestSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result , True)).Равно(True);
    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "query")).Равно(True);

    If Option = "Minimal" Then

        ExpectsThat(Result["query"]).Равно("SELECT 1");

    Else

        ExpectsThat(Result["database"]).Равно("default");
        ExpectsThat(Result["id"]).Заполнено();
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "data")).Равно(True);
        ExpectsThat(Result["format"]).Равно("CSV");
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "external_tables")).Равно(True);
        ExpectsThat(Result["external_tables"]).ИмеетТип("Array");
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "settings")).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_ClickHouse_GetExternalTableStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result , True)).Равно(True);
    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "name")).Равно(True);
    ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "cols")).Равно(True);
    ExpectsThat(Result["name"]).Равно("external_data");

    If Option = "Minimal" Then

        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "data")).Равно(False);

    ElsIf Option = "TSV" Or Not ValueIsFilled(Option) Then

        ExpectsThat(Result["format"]).Равно("TSV");
        ExpectsThat(OPI_Tools.CollectionFieldExists(Result, "data")).Равно(True);

    EndIf;

    Return Result;

EndFunction

Function Check_ClickHouse_GetSessionSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["id"]).ИмеетТип("String").Заполнено();
    ExpectsThat(Result["check"]).Равно(True);
    ExpectsThat(Result["timeout"]).Равно(120);

    Return Result;

EndFunction

Function Check_ClickHouse_GetTlsSettings(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    Return Result;

EndFunction

Function Check_ClickHouse_OpenGRPCStream(Val Result, Val Option)

    If Option = "Final" Then

        ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
        ExpectsThat(Result["result"]).Равно(True);

    ElsIf Option = "Selection" Then

        ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
        ExpectsThat(Result["result"]).Равно(True);

        ResponseBody = Result["data"]["output"];
        ExpectsThat(OPI_Tools.ThisIsCollection(ResponseBody , True)).Равно(True);
        ExpectsThat(OPI_Tools.CollectionFieldExists(ResponseBody, "data")).Равно(True);

        Data = ResponseBody["data"];
        ExpectsThat(TypeOf(Data)).Равно(Type("Array"));
        ExpectsThat(Data.Count()).Равно(5);

        For Counter = 0 To 4 Do
            Record = Data[Counter];
            ExpectsThat(Record["id"]).Равно(String(Counter + 1));
            ExpectsThat(Record["user_id"]).Равно(100 + Counter);
            ExpectsThat(Record["event_type"]).Равно("stream_test");
        EndDo;

    Else
        ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
        ExpectsThat(Result["result"]).Равно(True);
        ExpectsThat(ValueIsFilled(Result["streamId"])).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_ClickHouse_SendGRPCMessage(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_ClickHouse_SendGRPCData(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_ClickHouse_GetGRPCMessage(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    ExpectsThat(Result["rows"]).Равно(1);
    ExpectsThat(ValueIsFilled(Result["data"])).Равно(True);

    Return Result;

EndFunction

Function Check_ClickHouse_CompleteGRPCSending(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Sending" Then
        ExpectsThat(Result["result"]).Равно(False);
    Else
        ExpectsThat(Result["result"]).Равно(True);
    EndIf;

    Return Result;

EndFunction

Function Check_ClickHouse_CloseGRPCStream(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["result"]).Равно(True);

    Return Result;

EndFunction

Function Check_ClickHouse_ProcessGRPCSending(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["data_sending"].Count()).Равно(4);
    ExpectsThat(Result["received_message"]["message"]["exception"]["code"]).Равно(0);

    Return Result;

EndFunction

Function Check_ClickHouse_ProcessGRPCReceiving(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["messages"].Count() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_RSS_CreateFeedRSS(Val Result, Val Option, Parameters = "")

    ExpectsThat(TypeOf(Result)).Равно(Type("String"));
    ExpectsThat(Result).Заполнено();
    ExpectsThat(StrFind(Result, "<?xml") > 0).Равно(True);
    ExpectsThat(StrFind(Result, "<rss") > 0).Равно(True);
    ExpectsThat(StrFind(Result, "<channel>") > 0).Равно(True);
    ExpectsThat(StrFind(Result, "<item>") > 0).Равно(True);

    TFN = GetTempFileName("xml");
    GetBinaryDataFromString(Result).Write(TFN);

    WriteParameter("RSS_FeedXML", TFN);
    Parameters.Insert("RSS_FeedXML", TFN);

    Return Result;

EndFunction

Function Check_RSS_GetFeedItemStructureRSS(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then
        ExpectsThat(Result["title"]).Равно("");
        ExpectsThat(Result["description"]).Равно("");
        ExpectsThat(Result["link"]).Равно("");
    ElsIf Option = "Map" Then
        ExpectsThat(TypeOf(Result)).Равно(Type("Map"));
    Else
        ExpectsThat(Result["title"]).Заполнено();
        ExpectsThat(Result["description"]).Заполнено();
        ExpectsThat(Result["link"]).Заполнено();
    EndIf;

    Return Result;

EndFunction

Function Check_RSS_ParseFeedRSS(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["title"]).Заполнено();
    ExpectsThat(Result["description"]).Заполнено();
    ExpectsThat(Result["link"]).Заполнено();
    ExpectsThat(Result["items"]).ИмеетТип("Array");
    ExpectsThat(Result["items"].Count() > 0).Равно(True);

    FirestElement = Result["items"][0];
    ExpectsThat(FirestElement["title"]).Заполнено();
    ExpectsThat(FirestElement["description"]).Заполнено();
    ExpectsThat(FirestElement["link"]).Заполнено();

    Return Result;

EndFunction

Function Check_RSS_CreateFeedAtom(Val Result, Val Option, Parameters = "")

    ExpectsThat(TypeOf(Result)).Равно(Type("String"));
    ExpectsThat(Result).Заполнено();
    ExpectsThat(StrFind(Result, "<?xml") > 0).Равно(True);
    ExpectsThat(StrFind(Result, "<feed") > 0).Равно(True);
    ExpectsThat(StrFind(Result, "xmlns=""http://www.w3.org/2005/Atom""") > 0).Равно(True);
    ExpectsThat(StrFind(Result, "<entry>") > 0).Равно(True);

    TFN = GetTempFileName("xml");
    GetBinaryDataFromString(Result).Write(TFN);

    WriteParameter("RSS_AtomFeedXML", TFN);
    Parameters.Insert("RSS_AtomFeedXML", TFN);

    Return Result;

EndFunction

Function Check_RSS_GetFeedItemStructureAtom(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then
        ExpectsThat(Result["title"]).Равно("");
        ExpectsThat(Result["id"]).Равно("");
        ExpectsThat(Result["link"]).Равно("");
    ElsIf Option = "Map" Then
        ExpectsThat(TypeOf(Result)).Равно(Type("Map"));
    Else
        ExpectsThat(Result["title"]).Заполнено();
        ExpectsThat(Result["id"]).Заполнено();
        ExpectsThat(Result["link"]).Заполнено();
    EndIf;

    Return Result;

EndFunction

Function Check_RSS_ParseFeedAtom(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["title"]).Заполнено();
    ExpectsThat(Result["id"]).Заполнено();
    ExpectsThat(Result["link"]).Заполнено();
    ExpectsThat(Result["entries"]).ИмеетТип("Array");
    ExpectsThat(Result["entries"].Count() > 0).Равно(True);

    FirstRecord = Result["entries"][0];
    ExpectsThat(FirstRecord["title"]).Заполнено();
    ExpectsThat(FirstRecord["id"]).Заполнено();
    ExpectsThat(FirstRecord["link"]).Заполнено();

    Return Result;

EndFunction

Function Check_MessagePack_SerializeData(Val Result, Val Option, Restored = Undefined, InitialValue = Undefined)

    ExpectsThat(TypeOf(Result)).Равно(Type("BinaryData"));

    Hex = Lower(GetHexStringFromBinaryData(Result));

    If Option = "EmptyString" Then

        ExpectsThat(Hex).Равно("a0");

    ElsIf Option = "StringFixstr" Then

        ExpectsThat(Hex).Равно("a161");

    ElsIf Option = "StringUTF8" Then

        ExpectsThat(Restored).Равно("Hello");

    ElsIf Option = "Integer0" Then

        ExpectsThat(Hex).Равно("00");

    ElsIf Option = "Integer127" Then

        ExpectsThat(Hex).Равно("7f");

    ElsIf Option = "Uint8" Then

        ExpectsThat(Hex).Равно("cc80");

    ElsIf Option = "NegativeFixint" Then

        ExpectsThat(Hex).Равно("ff");

    ElsIf Option = "Int8" Then

        ExpectsThat(Hex).Равно("d0df");

    ElsIf Option = "Float" Then

        CheckNumberMessagePack(Restored, InitialValue);

    ElsIf Option = "Nil" Then

        ExpectsThat(Hex).Равно("c0");

    ElsIf Option = "True" Then

        ExpectsThat(Hex).Равно("c3");

    ElsIf Option = "False" Then

        ExpectsThat(Hex).Равно("c2");

    ElsIf Option = "EmptyBinary" Then

        ExpectsThat(Hex).Равно("c400");

    ElsIf Option = "BinaryBin8" Then

        ExpectsThat(Hex).Равно("c403010203");

    ElsIf Option = "EmptyArray" Then

        ExpectsThat(Hex).Равно("90");

    ElsIf Option = "ArrayThreeNumbers" Then

        ExpectsThat(Hex).Равно("93010203");

    ElsIf Option = "EmptyMap" Then

        ExpectsThat(Hex).Равно("80");

    ElsIf Option = "MapOnePair" Then

        ExpectsThat(Hex).Равно("81a16101");

    ElsIf Option = "MapTwoPairs" Then

        ExpectsThat(Restored["x"]).Равно(10);
        ExpectsThat(Restored["y"]).Равно(20);

    EndIf;

    Return Result;

EndFunction

Function Check_MessagePack_DeserializeData(Val Result, Val Option, ExpectedValue = Undefined)

    If Option = "Fixint0" Then

        ExpectsThat(Result).Равно(0);

    ElsIf Option = "StringFixstr" Then

        ExpectsThat(Result).Равно("a");

    ElsIf Option = "Nil" Then

        ExpectsThat(Result = Undefined).Равно(True);

    ElsIf Option = "True" Then

        ExpectsThat(Result).Равно(True);

    ElsIf Option = "False" Then

        ExpectsThat(Result).Равно(False);

    ElsIf Option = "EmptyBinary" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("BinaryData"));
        ExpectsThat(Result.Size()).Равно(0);

    ElsIf Option = "BinaryBin8" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("BinaryData"));
        ExpectsThat(Lower(GetHexStringFromBinaryData(Result))).Равно("010203");

    ElsIf Option = "EmptyArray" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("Array"));
        ExpectsThat(Result.Count()).Равно(0);

    ElsIf Option = "ArrayThreeNumbers" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("Array"));
        ExpectsThat(Result.Count()).Равно(3);
        ExpectsThat(Result[0]).Равно(1);
        ExpectsThat(Result[1]).Равно(2);
        ExpectsThat(Result[2]).Равно(3);

    ElsIf Option = "ArrayTwoStrings" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("Array"));
        ExpectsThat(Result.Count()).Равно(2);
        ExpectsThat(Result[0]).Равно("a");
        ExpectsThat(Result[1]).Равно("b");

    ElsIf Option = "EmptyMap" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("Map"));
        ExpectsThat(Result.Count()).Равно(0);

    ElsIf Option = "MapOnePair" Then

        ExpectsThat(TypeOf(Result)).Равно(Type("Map"));
        ExpectsThat(Result.Count()).Равно(1);
        ExpectsThat(Result["a"]).Равно(1);

    ElsIf Option = "RoundTrip" Then

        If TypeOf(ExpectedValue) = Type("Number") Then
            CheckNumberMessagePack(Result, ExpectedValue);
        ElsIf TypeOf(ExpectedValue) = Type("BinaryData") Then
            CheckMessagePackBinaryData(Result, ExpectedValue);
        ElsIf TypeOf(ExpectedValue) = Type("Array") Then
            CheckArrayMessagePack(Result, ExpectedValue);
        ElsIf TypeOf(ExpectedValue) = Type("Map")
            Or TypeOf(ExpectedValue) = Type("Structure") Then
            CheckMapMessagePack(Result, ExpectedValue);
        Else
            ExpectsThat(Result).Равно(ExpectedValue);
        EndIf;

    EndIf;

    Return Result;

EndFunction

Procedure CheckNumberMessagePack(Val Actual, Val Expected)

    Difference = Actual - Expected;

    If Difference < 0 Then
        Difference = -Difference;
    EndIf;

    ExpectsThat(Difference < 0.0000001).Равно(True);

EndProcedure

Procedure CheckMessagePackBinaryData(Val Actual, Val Expected)

    ExpectsThat(TypeOf(Actual)).Равно(Type("BinaryData"));
    ExpectsThat(Actual.Size()).Равно(Expected.Size());
    ExpectsThat(Lower(GetHexStringFromBinaryData(Actual))).Равно(Lower(GetHexStringFromBinaryData(Expected)));

EndProcedure

Procedure CheckArrayMessagePack(Val Actual, Val Expected)

    ExpectsThat(TypeOf(Actual)).Равно(Type("Array"));
    ExpectsThat(Actual.Count()).Равно(Expected.Count());

    For Index = 0 To Actual.UBound() Do

        ActualItem = Actual[Index];
        ExpectedItem = Expected[Index];

        If TypeOf(ActualItem) = Type("Number") Then
            CheckNumberMessagePack(ActualItem, ExpectedItem);
        ElsIf TypeOf(ActualItem) = Type("BinaryData") Then
            CheckMessagePackBinaryData(ActualItem, ExpectedItem);
        ElsIf TypeOf(ActualItem) = Type("Array") Then
            CheckArrayMessagePack(ActualItem, ExpectedItem);
        ElsIf TypeOf(ActualItem) = Type("Map") Then
            CheckMapMessagePack(ActualItem, ExpectedItem);
        ElsIf ActualItem = Undefined Then
            ExpectsThat(ExpectedItem = Undefined).Равно(True);
        Else
            ExpectsThat(ActualItem).Равно(ExpectedItem);
        EndIf;

    EndDo;

EndProcedure

Procedure CheckMapMessagePack(Val Actual, Val Expected)

    ExpectsThat(TypeOf(Actual)).Равно(Type("Map"));

    PairCount = 0;

    For Each Pair In Expected Do

        Key = String(Pair.Key);
        ExpectsThat(MapContainsKeyMessagePack(Actual, Key)).Равно(True);
        CheckMessagePackValue(Actual[Key], Pair.Value);
        PairCount = PairCount + 1;

    EndDo;

    ExpectsThat(Actual.Count()).Равно(PairCount);

EndProcedure

Function MapContainsKeyMessagePack(Val Map, Val Key)

    For Each Pair In Map Do

        If String(Pair.Key) = Key Then
            Return True;
        EndIf;

    EndDo;

    Return False;

EndFunction

Procedure CheckMessagePackValue(Val Actual, Val Expected)

    If TypeOf(Expected) = Type("Number") Then
        CheckNumberMessagePack(Actual, Expected);
    ElsIf TypeOf(Expected) = Type("BinaryData") Then
        CheckMessagePackBinaryData(Actual, Expected);
    ElsIf TypeOf(Expected) = Type("Array") Then
        CheckArrayMessagePack(Actual, Expected);
    ElsIf TypeOf(Expected) = Type("Map")
        Or TypeOf(Expected) = Type("Structure") Then
        CheckMapMessagePack(Actual, Expected);
    ElsIf Expected = Undefined Then
        ExpectsThat(Actual = Undefined).Равно(True);
    Else
        ExpectsThat(Actual).Равно(Expected);
    EndIf;

EndProcedure

Function Check_MessagePack_ReferenceCompatibility(Val Result, Val Option, Original = Undefined)

    If Option = "Health" Then

        ExpectsThat(Result["ok"]).Равно(True);
        ExpectsThat(Result["port"]).Заполнено();

    ElsIf Option = "OPIPackReferenceUnpack" Then

        Actual = ConvertReferenceValueMessagePack(Result);
        CheckMessagePackValue(Actual, Original);

    ElsIf Option = "ReferencePackOPIUnpack" Then

        CheckMessagePackValue(Result, Original);

    EndIf;

    Return Result;

EndFunction

Function ConvertReferenceValueMessagePack(Val Value)

    If OPI_Tools.ThisIsCollection(Value, True)
        And MapContainsKeyMessagePack(Value, "__msgpack_bytes__") Then

        Return Base64Value(Value["__msgpack_bytes__"]);

    ElsIf IsNodeJSMessagePackBuffer(Value) Then

        Return BinaryDataFromNodeJSMessagePackDataBuffer(Value);

    ElsIf TypeOf(Value) = Type("Array") Then

        Result = New Array;

        For Each Element In Value Do
            Result.Add(ConvertReferenceValueMessagePack(Element));
        EndDo;

        Return Result;

    ElsIf OPI_Tools.ThisIsCollection(Value, True) Then

        Result = New Map;

        For Each Pair In Value Do
            Result.Insert(Pair.Key, ConvertReferenceValueMessagePack(Pair.Value));
        EndDo;

        Return Result;

    Else

        If Value = Null Then
            Return Undefined;
        EndIf;

        Return Value;

    EndIf;

EndFunction

Function IsNodeJSMessagePackBuffer(Val Value)

    If Not OPI_Tools.ThisIsCollection(Value, True) Then
        Return False;
    EndIf;

    If Not MapContainsKeyMessagePack(Value, "type")
        Or Not MapContainsKeyMessagePack(Value, "data") Then
        Return False;
    EndIf;

    Return Value["type"] = "Buffer"
        And TypeOf(Value["data"]) = Type("Array");

EndFunction

Function BinaryDataFromNodeJSMessagePackDataBuffer(Val Value)

    Bytes = Value["data"];
    Buffer = New BinaryDataBuffer(Bytes.Count());

    For Index = 0 To Bytes.Count() - 1 Do
        Buffer.Set(Index, Bytes[Index]);
    EndDo;

    Return GetBinaryDataFromBinaryDataBuffer(Buffer);

EndFunction

Function Check_MessagePack_Benchmark(Val Result, Val Option, Original = Undefined)

    CheckMapMessagePack(Result["JsonRestored"] , Original);
    CheckMapMessagePack(Result["MessagePackRestored"], Original);

    LogServiceInformation(
        StrTemplate("%1 ms", Result["JsonSerializationMs"])
        , "JSON serialization"
        , "MessagePack");

    LogServiceInformation(
        StrTemplate("%1 ms", Result["JsonDeserializationMs"])
        , "JSON deserialization"
        , "MessagePack");

    LogServiceInformation(
        StrTemplate("%1 ms", Result["MessagePackSerializationMs"])
        , "MessagePack serialization"
        , "MessagePack");

    LogServiceInformation(
        StrTemplate("%1 ms", Result["MessagePackDeserializationMs"])
        , "MessagePack deserialization"
        , "MessagePack");

    LogServiceInformation(
        StrTemplate("JSON: %1 characters | MessagePack: %2 bytes"
            , StrLen(Result["JsonString"])
            , Result["MessagePackData"].Size())
        , "Size of serialized data"
        , "MessagePack");

    Return StrTemplate(
        "JSON ser %1 ms, des %2 ms | MessagePack ser %3 ms, des %4 ms | JSON %5 chars, MP %6 bytes"
        , Result["JsonSerializationMs"]
        , Result["JsonDeserializationMs"]
        , Result["MessagePackSerializationMs"]
        , Result["MessagePackDeserializationMs"]
        , StrLen(Result["JsonString"])
        , Result["MessagePackData"].Size());

EndFunction

Function Check_Lua_Extended_CodeExecutionError(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(ValueIsFilled(Result["error"])).Равно(True);

    Return Result;

EndFunction

Function Check_Lua_Extended_GetLogWithoutInitialization(Val Result, Val Option)

    ExpectsThat(Result["result"]).Равно(False);
    ExpectsThat(StrFind(Lower(Result["error"]), "logger not initialized") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_Lua_Extended_PassComplexData(Val Result, Val Option, InitialValue = Undefined)

    ExpectsThat(Result["alpha"]).Равно(GetStringFromBinaryData(InitialValue["alpha"], "UTF-8"));
    ExpectsThat(Result["beta"]).Равно(GetStringFromBinaryData(InitialValue["beta"], "UTF-8"));
    ExpectsThat(Result["gamma"]).Равно(GetStringFromBinaryData(InitialValue["gamma"], "UTF-8"));

    ExpectsThat(Result["nested"]["label"]).Равно(InitialValue["nested"]["label"]);
    ExpectsThat(Result["nested"]["inner"]).Равно(GetStringFromBinaryData(InitialValue["nested"]["inner"], "UTF-8"));

    CheckArrayJanx(Result["meta"], InitialValue["meta"]);

    Return Result;

EndFunction

Function Check_Lua_Extended_PassArrayOfMixedTypes(Val Result, Val Option, InitialValue = Undefined)

    ExpectsThat(TypeOf(Result)).Равно(Type("Array"));
    ExpectsThat(Result.Count()).Равно(InitialValue.Count());

    ExpectsThat(Result[0]).Равно(1);
    ExpectsThat(Result[1]).Равно("text");
    ExpectsThat(Result[2]).Равно(GetStringFromBinaryData(InitialValue[2], "UTF-8"));

    ExpectsThat(Result[3]["k"]).Равно("v");
    ExpectsThat(Result[3]["bin"]).Равно(GetStringFromBinaryData(InitialValue[3]["bin"], "UTF-8"));

    ExpectsThat(Result[4][0]).Равно(False);
    ExpectsThat(Result[4][1]).Равно(GetStringFromBinaryData(InitialValue[4][1], "UTF-8"));

    Return Result;

EndFunction

Function Check_Lua_Extended_GetLogOnExecution(Val Result, Val Option, LogFile = "")

    ExpectsThat(Result["result"]).Равно(True);
    ExpectsThat(Result["logs"]).ИмеетТип("Array");
    ExpectsThat(Result["logs"].Count() > 0).Равно(True);

    LogObject = New File(LogFile);
    ExpectsThat(LogObject.Exists()).Равно(True);
    ExpectsThat(LogObject.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_Lua_CreateVM(Val Result, Val Option)

    If Option = "LuaJIT" Then
        ExpectsThat(String(TypeOf(Result))).Равно("AddIn.OPI_LuaJIT.Main");
    Else
        ExpectsThat(String(TypeOf(Result))).Равно("AddIn.OPI_Lua54.Main");
    EndIf;

    Return Result;

EndFunction

Function Check_Lua_IsVM(Val Result, Val Option)

    If Option = "Lua54" Then
        ExpectsThat(Result).Равно(True);
    Else
        ExpectsThat(Result).Равно(False);
    EndIf;

    Return Result;

EndFunction

Function Check_Lua_ExecuteCodeFromString(Val Result, Val Option)

    ExpectsThat(Result).Равно(42);

    Return Result;

EndFunction

Function Check_Lua_ExecuteCodeFromFile(Val Result, Val Option)

    ExpectsThat(Result).Равно(7);

    Return Result;

EndFunction

Function Check_Lua_CallFunction(Val Result, Val Option)

    ExpectsThat(Result).Равно(3);

    Return Result;

EndFunction

Function Check_Lua_CompileCodeFromString(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_Lua_CompileCodeFromFile(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("BinaryData");
    ExpectsThat(Result.Size() > 0).Равно(True);

    Return Result;

EndFunction

Function Check_Lua_ExecuteBytecode(Val Result, Val Option)

    ExpectsThat(Result).Равно(11);

    Return Result;

EndFunction

Function Check_Lua_ExecuteBytecodeFromFile(Val Result, Val Option)

    ExpectsThat(Result).Равно(13);

    Return Result;

EndFunction

Function Check_Janx_Extended_RoundRobin(Val Result, Val Option, Restored = Undefined, InitialValue = Undefined)

    ExpectsThat(TypeOf(Result)).Равно(Type("BinaryData"));
    CheckPrefixJanx(Result);

    If TypeOf(InitialValue) = Type("Array")
        Or StrFind(Option, "MixedArray") > 0 Then
        CheckArrayJanx(Restored, InitialValue);
    Else
        CheckMapJanx(Restored, InitialValue);
    EndIf;

    Return Result;

EndFunction

Function Check_Janx_SerializeData(Val Result, Val Option, Restored = Undefined, InitialValue = Undefined)

    ExpectsThat(TypeOf(Result)).Равно(Type("BinaryData"));

    If Option = "String" Then

        ExpectsThat(Restored).Равно(InitialValue);

    ElsIf Option = "Number" Then

        ExpectsThat(Restored).Равно(InitialValue);

    ElsIf Option = "EmptyBinary" Then

        CheckBinaryDataJanx(Restored, InitialValue);

    ElsIf Option = "BinaryOne" Then

        CheckBinaryDataJanx(Restored, InitialValue);

    ElsIf Option = "MapWithBinary" Then

        CheckMapJanx(Restored, InitialValue);

    ElsIf Option = "ArrayWithBinary" Then

        CheckArrayJanx(Restored, InitialValue);

    EndIf;

    CheckPrefixJanx(Result);

    Return Result;

EndFunction

Function Check_Janx_DeserializeData(Val Result, Val Option, ExpectedValue = Undefined)

    If Option = "String" Then

        ExpectsThat(Result).Равно(ExpectedValue);

    ElsIf Option = "BinaryOne" Then

        CheckBinaryDataJanx(Result, ExpectedValue);

    ElsIf Option = "MapWithBinary" Then

        CheckMapJanx(Result, ExpectedValue);

    ElsIf Option = "Prefix" Then

        CheckPrefixJanx(ExpectedValue);

    EndIf;

    Return Result;

EndFunction

Procedure CheckPrefixJanx(Val Data)

    Reading = New DataReader(Data);

    ExpectsThat(Reading.ReadInt16(ByteOrder.BigEndian)).Равно(1);

    JSONSize = Reading.ReadInt32(ByteOrder.BigEndian);

    ExpectsThat(Reading.ReadInt32(ByteOrder.BigEndian) >= 0).Равно(True);

    Reading.Close();

    ExpectsThat(10 + JSONSize <= Data.Size()).Равно(True);

EndProcedure

Procedure CheckBinaryDataJanx(Val Actual, Val Expected)

    ExpectsThat(TypeOf(Actual)).Равно(Type("BinaryData"));
    ExpectsThat(GetHexStringFromBinaryData(Actual)).Равно(GetHexStringFromBinaryData(Expected));

EndProcedure

Procedure CheckArrayJanx(Val Actual, Val Expected)

    ExpectsThat(TypeOf(Actual)).Равно(Type("Array"));
    ExpectsThat(Actual.Count()).Равно(Expected.Count());

    For Index = 0 To Expected.UBound() Do
        CheckValueJanx(Actual[Index], Expected[Index]);
    EndDo;

EndProcedure

Procedure CheckMapJanx(Val Actual, Val Expected)

    ExpectsThat(TypeOf(Actual)).Равно(Type("Map"));
    ExpectsThat(Actual.Count()).Равно(Expected.Count());

    For Each Pair In Expected Do

        Key = String(Pair.Key);
        ExpectsThat(MapContainsKeyJanx(Actual, Key)).Равно(True);
        CheckValueJanx(Actual[Key], Pair.Value);

    EndDo;

EndProcedure

Function MapContainsKeyJanx(Val Map, Val Key)

    For Each Pair In Map Do

        If String(Pair.Key) = Key Then
            Return True;
        EndIf;

    EndDo;

    Return False;

EndFunction

Procedure CheckValueJanx(Val Actual, Val Expected)

    If TypeOf(Expected) = Type("Number") Then
        CheckNumberJanx(Actual, Expected);
    ElsIf TypeOf(Expected) = Type("BinaryData") Then
        CheckBinaryDataJanx(Actual, Expected);
    ElsIf TypeOf(Expected) = Type("Array") Then
        CheckArrayJanx(Actual, Expected);
    ElsIf OPI_Tools.ThisIsCollection(Expected, True) Then
        CheckMapJanx(Actual, Expected);
    Else
        ExpectsThat(Actual).Равно(Expected);
    EndIf;

EndProcedure

Procedure CheckNumberJanx(Val Actual, Val Expected)

    ExpectsThat(TypeOf(Actual)).Равно(Type("Number"));

    If Actual = Expected Then
        Return;
    EndIf;

    Difference = Actual - Expected;

    If Difference < 0 Then
        Difference = -Difference;
    EndIf;

    ExpectsThat(Difference <= 0.000000000001).Равно(True);

EndProcedure

Function Check_Janx_Benchmark(Val Result, Val Option, Original = Undefined)

    CheckMapJanx(Result["JsonRestored"], OriginalJsonFromJanxBenchmark(Original));
    CheckMapJanx(Result["JanxRestored"], Original);

    LogServiceInformation(
        StrTemplate("%1 ms", Result["JsonSerializationMs"])
        , "JSON serialization (without bin)"
        , "Janx");

    LogServiceInformation(
        StrTemplate("%1 ms", Result["JsonDeserializationMs"])
        , "JSON deserialization (without bin)"
        , "Janx");

    LogServiceInformation(
        StrTemplate("%1 ms", Result["JanxSerializationWithoutBinMs"])
        , "Janx serialization (without bin)"
        , "Janx");

    LogServiceInformation(
        StrTemplate("%1 ms", Result["JanxDeserializationWithoutBinMs"])
        , "Janx deserialization (without bin)"
        , "Janx");

    LogServiceInformation(
        StrTemplate("%1 ms", Result["JanxSerializationMs"])
        , "Janx serialization (with bin)"
        , "Janx");

    LogServiceInformation(
        StrTemplate("%1 ms", Result["JanxDeserializationMs"])
        , "Janx deserialization (with bin)"
        , "Janx");

    Return StrTemplate(
        "JSON ser %1 ms, des %2 ms | Janx ser %3 ms, des %4 ms | JSON %5 chars, Janx %6 B (app %7 B)"
        , Result["JsonSerializationMs"]
        , Result["JsonDeserializationMs"]
        , Result["JanxSerializationMs"]
        , Result["JanxDeserializationMs"]
        , StrLen(Result["JsonString"])
        , Result["JanxData"].Size()
        , Result["AppendixSize"]);

EndFunction

Function OriginalJsonFromJanxBenchmark(Val Original)

    JsonItems = New Array;

    For Each Element In Original.items Do

        JsonItem = New Structure;
        JsonItem.Insert("index", Element.index);
        JsonItem.Insert("flag" , Element.flag);
        JsonItem.Insert("title", Element.title);
        JsonItem.Insert("ratio", Element.ratio);

        If Element.Property("note") Then
            JsonItem.Insert("note", Element.note);
        EndIf;

        JsonItem.Insert("values", Element.values);
        JsonItem.Insert("attrs" , Element.attrs);
        JsonItems.Add(JsonItem);

    EndDo;

    OriginalJson = New Structure;
    OriginalJson.Insert("version", Original.version);
    OriginalJson.Insert("label" , Original.label);
    OriginalJson.Insert("root" , Original.root);
    OriginalJson.Insert("items" , JsonItems);

    Return OriginalJson;

EndFunction

Function Check_ReportPortal_GetTemporaryToken(Val Result, Val Option, Parameters = "")

    Token = Result["access_token"];

    ExpectsThat(Token).Заполнено();

    WriteParameter("RPortal_TempToken", Token);
    Parameters.Insert("RPortal_TempToken", Token);

    Return Result;

EndFunction

Function Check_ReportPortal_GetPermanentToken(Val Result, Val Option, Parameters = "")

    Token = Result["api_key"];
    UID = Result["id"];

    ExpectsThat(Token).Заполнено();

    WriteParameter("RPortal_TestApiKey", Token);
    Parameters.Insert("RPortal_TestApiKey", Token);

    WriteParameter("RPortal_TestKeyID", UID);
    Parameters.Insert("RPortal_TestKeyID", UID);

    Return Result;

EndFunction

Function Check_ReportPortal_DeletePermanentToken(Val Result, Val Option)

    Response = Result["message"];
    ExpectsThat(StrEndsWith(Response, "was successfully deleted.")).Равно(True);

    Return Result;

EndFunction

Function Check_ReportPortal_GetUserTokens(Val Result, Val Option)

    ExpectsThat(Result["items"]).ИмеетТип("Array");

    If Result["items"].Count() > 0 Then
        FirstToken = Result["items"][0];
        ExpectsThat(FirstToken["id"]).Заполнено();
        ExpectsThat(FirstToken["name"]).Заполнено();
    EndIf;

    Return Result;

EndFunction

Function Check_ReportPortal_CreateLaunch(Val Result, Val Option, Parameters = "")

    LaunchID = Result["id"];

    ExpectsThat(LaunchID).Заполнено();

    WriteParameter("RPortal_TestLaunch", LaunchID);
    Parameters.Insert("RPortal_TestLaunch", LaunchID);

    Return Result;

EndFunction

Function Check_ReportPortal_FinishLaunch(Val Result, Val Option)

    LaunchID = Result["id"];
    ExpectsThat(LaunchID).Заполнено();

    Return Result;

EndFunction

Function Check_ReportPortal_CreateItem(Val Result, Val Option, Parameters = "")

    LaunchID = Result["id"];

    ExpectsThat(LaunchID).Заполнено();

    WriteParameter("RPortal_TestItem", LaunchID);
    Parameters.Insert("RPortal_TestItem", LaunchID);

    Return Result;

EndFunction

Function Check_ReportPortal_FinishItem(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully finished") > 0).Равно(True);
    Return Result;

EndFunction

Function Check_ReportPortal_GetLaunchStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_ReportPortal_GetItemStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_ReportPortal_GetItemCompletionStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_ReportPortal_GetLaunchCompletionStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["status"]).Равно("passed");
    ExpectsThat(Result["description"]).Равно("Some test");
    ExpectsThat(Result["attributes"]).Равно("key1:value1, key2:value2");

    Return Result;

EndFunction

Function Check_ReportPortal_WriteLog(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["id"]).Заполнено();

    LogID = Result["id"];
    WriteParameter("RPortal_TestLog", LogID);
    Parameters.Insert("RPortal_TestLog", LogID);

    Return Result;

EndFunction

Function Check_ReportPortal_GetLogStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);
    ExpectsThat(Result["message"]).Равно("Some log");

    Return Result;

EndFunction

Function Check_ReportPortal_GetLog(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["message"]).Равно("Some log 1");

    LogID = Result["id"];
    WriteParameter("RPortal_TestLogId", LogID);
    Parameters.Insert("RPortal_TestLogId", LogID);

    Return Result;

EndFunction

Function Check_ReportPortal_DeleteLog(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully deleted") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_ReportPortal_CreateProject(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["id"]).Заполнено();

    ProjectID = Result["id"];
    WriteParameter("RPortal_TestProject", ProjectID);
    Parameters.Insert("RPortal_TestProject", ProjectID);

    Return Result;

EndFunction

Function Check_ReportPortal_DeleteProject(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully deleted") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_ReportPortal_GetProject(Val Result, Val Option)

    ExpectsThat(Result["projectId"]).Заполнено();
    ExpectsThat(Result["projectName"]).Равно("testproject");

    Return Result;

EndFunction

Function Check_ReportPortal_GetProjects(Val Result, Val Option)

    ExpectsThat(Result["content"]).ИмеетТип("Array");
    ExpectsThat(Result["page"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_ReportPortal_AddUsersToProject(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_ReportPortal_ExcludeUsersFromProject(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_ReportPortal_GetLaunch(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["id"]).Заполнено();

    LogID = Result["id"];
    WriteParameter("RPortal_TestLaunchId", LogID);
    Parameters.Insert("RPortal_TestLaunchId", LogID);

    Return Result;

EndFunction

Function Check_ReportPortal_GetLaunchItems(Val Result, Val Option)

    ExpectsThat(Result["content"]).ИмеетТип("Array");
    ExpectsThat(Result["page"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_ReportPortal_GetItem(Val Result, Val Option, Parameters = "")

    ExpectsThat(Result["id"]).Заполнено();

    LogID = Result["id"];
    WriteParameter("RPortal_TestItemId", LogID);
    Parameters.Insert("RPortal_TestItemId", LogID);

    Return Result;

EndFunction

Function Check_ReportPortal_GetItemLogs(Val Result, Val Option)

    ExpectsThat(Result["content"]).ИмеетТип("Array");
    ExpectsThat(Result["page"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_ReportPortal_UpdateLaunch(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully") > 0).Равно(True);
    Return Result;

EndFunction

Function Check_ReportPortal_UpdateItem(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully") > 0).Равно(True);
    Return Result;

EndFunction

Function Check_ReportPortal_DeleteLaunch(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully") > 0).Равно(True);
    Return Result;

EndFunction

Function Check_ReportPortal_DeleteItem(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully") > 0).Равно(True);
    Return Result;

EndFunction

Function Check_ReportPortal_GetLaunchReport(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("String");
    Return Result;

EndFunction

Function Check_ReportPortal_CreateUser(Val Result, Val Option, Parameters = "")

    UserID = Result["id"];

    ExpectsThat(UserID).Заполнено();

    WriteParameter("RPortal_TestUser", UserID);
    Parameters.Insert("RPortal_TestUser", UserID);

    Return Result;

EndFunction

Function Check_ReportPortal_DeleteUser(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully") > 0).Равно(True);
    Return Result;

EndFunction

Function Check_ReportPortal_GetUserFieldsStructure(Val Result, Val Option)

    ExpectsThat(OPI_Tools.ThisIsCollection(Result, True)).Равно(True);

    If Option = "Clear" Then

        For Each Element In Result Do

            If OPI_Tools.IsPrimitiveType(Element.Value) Then
                ExpectsThat(ValueIsFilled(Element.Value)).Равно(False);
            EndIf;

        EndDo;

    EndIf;

    Return Result;

EndFunction

Function Check_ReportPortal_UpdateUser(Val Result, Val Option)

    ExpectsThat(StrFind(Result["message"], "successfully") > 0).Равно(True);

    Return Result;

EndFunction

Function Check_ReportPortal_GetCurrentUser(Val Result, Val Option)

    ExpectsThat(Result["userId"]).Заполнено();
    ExpectsThat(Result["email"]).Заполнено();

    Return Result;

EndFunction

Function Check_ReportPortal_GetUser(Val Result, Val Option)

    ExpectsThat(Result["userId"]).Заполнено();
    ExpectsThat(Result["email"]).Заполнено();
    ExpectsThat(Result["fullName"]).Заполнено();

    Return Result;

EndFunction

Function Check_ReportPortal_GetUsers(Val Result, Val Option)

    ExpectsThat(Result["content"]).ИмеетТип("Array");
    ExpectsThat(Result["page"]).ИмеетТип("Map");

    Return Result;

EndFunction

Function Check_ReportPortal_GetUserProjects(Val Result, Val Option)

    ExpectsThat(Result).ИмеетТип("Map");

    If Result.Count() > 0 Then
        For Each Project In Result Do
            ExpectsThat(Project.Value["projectRole"]).Заполнено();
            Break;
        EndDo;
    EndIf;

    Return Result;

EndFunction

#EndRegion

#Region ReportPortal

Procedure WriteMissingTests()

    AllTests = GetFullTestList();
    ExecutedTests = New ValueList;
    ExecutedTests.LoadValues(GetExecutedTestsList());

    If ExecutedTests.Count() / AllTests.Count() > 0.8 Then

        For Each Test In AllTests Do

            If ValueIsFilled(Test["variant"]) Then
                TestFunctionName = StrTemplate("%1_%2_%3", Test["lib"], Test["name"], Test["variant"]);
            Else
                TestFunctionName = StrTemplate("%1_%2" , Test["lib"], Test["name"]);
            EndIf;

            If ExecutedTests.FindByValue(TestFunctionName) = Undefined Then
                WriteMissingTest(Test["lib"], Test["name"], Test["variant"]);
            EndIf;

        EndDo;

    EndIf;

EndProcedure

Procedure WriteMissingTest(Val Library, Val Method, Val Option)

    Data = GetExistingLaunch();

    If Data = Undefined Then
        Return;
    EndIf;

    SetID = CreateLaunchSet(Library);
    ElementID = CreateTestElement(SetID, Library, Method, Option);

    Token = GetParameter("RPortal_Token");
    Project = GetParameter("RPortal_MainProject");
    URL = GetParameter("RPortal_URL");

    CurrentDate = GetLaunchTime();

    ElementStructure = New Structure;

    ElementStructure.Insert("endTime" , CurrentDate);
    ElementStructure.Insert("launchUuid", Data["id"]);
    ElementStructure.Insert("status" , "skipped");

    ReportPortal().FinishItem(URL, Token, Project, ElementID, ElementStructure);

EndProcedure

Procedure WriteTestLog(Val Test, Val Text, Val Level)

    Data = GetExistingLaunch();

    If Data = Undefined Then
        Return;
    EndIf;

    CurrentDate = GetLaunchTime();

    Token = GetParameter("RPortal_Token");
    Project = GetParameter("RPortal_MainProject");
    URL = GetParameter("RPortal_URL");

    LogStructure = New Structure;
    LogStructure.Insert("launchUuid", Data["id"]);
    LogStructure.Insert("itemUuid" , Test);
    LogStructure.Insert("time" , CurrentDate);
    LogStructure.Insert("message" , Text);
    LogStructure.Insert("level" , Level);

    ReportPortal().WriteLog(URL, Token, Project, LogStructure);

EndProcedure

Procedure FinishTestElement(Val UUID, Val Status, Val Attributes = Undefined)

    Data = GetExistingLaunch();

    If Data = Undefined Then
        Return;
    EndIf;

    Token = GetParameter("RPortal_Token");
    Project = GetParameter("RPortal_MainProject");
    URL = GetParameter("RPortal_URL");

    CurrentDate = GetLaunchTime();

    ElementStructure = New Structure;

    ElementStructure.Insert("endTime" , CurrentDate);
    ElementStructure.Insert("launchUuid", Data["id"]);
    ElementStructure.Insert("status" , Status);

    If Attributes <> Undefined Then
        ElementStructure.Insert("attributes", Attributes);
    EndIf;

    ReportPortal().FinishItem(URL, Token, Project, UUID, ElementStructure);

    FoundTest = Data["items"].Get(UUID);

    If ValueIsFilled(FoundTest) Then
        Data["tests"].Add(FoundTest);
    EndIf;

    WriteLaunchFile(Data);

EndProcedure

Procedure WriteLaunchFile(Val Data)

    LaunchFile = GetParameter("RPortal_MainLaunch");
    OPI_Tools.WriteJSONFile(LaunchFile, Data);

EndProcedure

Procedure CreateLaunchFile(Val UUID)

    TFN = GetTempFileName();

    DataStructure = New Structure;
    DataStructure.Insert("id" , UUID);
    DataStructure.Insert("ended" , False);
    DataStructure.Insert("suites", New Map);
    DataStructure.Insert("tests" , New Array);
    DataStructure.Insert("items" , New Map);

    OPI_Tools.WriteJSONFile(TFN, DataStructure);
    WriteParameter("RPortal_MainLaunch", TFN);

EndProcedure

Function GetExistingLaunch()

    Data = ReadLaunchFile();
    UID = Data["id"];
    Completed = Data["ended"];

    If Not ValueIsFilled(UID) Or Completed Then
        Return Undefined;
    Else
        Return Data;
    EndIf;

EndFunction

Function GetLaunchTime()

    Shift = ?(OPI_Tools.IsWindows(), 3600 * 3, 0);
    CurrentDate = OPI_Tools.GetCurrentDate() - Shift;

    Return CurrentDate;

EndFunction

Function ReadLaunchFile()

    LaunchFile = GetParameter("RPortal_MainLaunch");

    LaunchObject = New File(LaunchFile);

    If Not ValueIsFilled(LaunchFile) Or Not LaunchObject.Exists() Then
        Return New Map;
    EndIf;

    Data = OPI_Tools.ReadJSONFile(LaunchFile, True);
    Return Data;

EndFunction

Function ReportPortal()

    Try

        // BSLLS:CommonModuleAssign-off

        //@skip-check property-not-writable
        //@skip-check bsl-legacy-check-static-feature-access
        OPI_ReportPortal = Undefined;

        // BSLLS:CommonModuleAssign-on

        CurrentDirectory = StrReplace(CurrentScript().Path, "\", "/");
        PathArray = StrSplit(CurrentDirectory, "/");
        PathArray.Delete(PathArray.UBound());
        PathArray.Delete(PathArray.UBound());
        PathArray.Add("api");
        PathArray.Add("Modules");
        PathArray.Add("OPI_ReportPortal.os");
        AttachScript(StrConcat(PathArray, "/"), "ReportPortal");
        OPI_ReportPortal = New("ReportPortal");

        Return OPI_ReportPortal;

    Except

        Return OPI_ReportPortal;

    EndTry;

EndFunction

#EndRegion

#Region Miscellaneous

Procedure ProcessTestingResult(Val Result
    , Val Method
    , Val Library
    , Val Option = ""
    , AddParam1 = Undefined
    , AddParam2 = Undefined
    , AddParam3 = Undefined)

    // BSLLS:UnusedLocalVariable-off
    //
    //@skip-check module-unused-local-variable
    Result_ = ?(OPI_Tools.ThisIsCollection(Result), OPI_Tools.CopyCollection(Result), Result);

    // BSLLS:UnusedLocalVariable-on

    IsVariant = ValueIsFilled(Option);
    LogsMethod = ?(IsVariant, StrTemplate("%1 (%2)", Method, Option), Method);

    SetID = CreateLaunchSet(Library);
    ElementID = CreateTestElement(SetID, Library, Method, Option);

    Try

        ParameterArray = New Array;
        ParameterArray.Add("Result_");
        ParameterArray.Add("Option");

        If AddParam1 <> Undefined Then
            ParameterArray.Add("AddParam1");
        EndIf;

        If AddParam2 <> Undefined Then
            ParameterArray.Add("AddParam2");
        EndIf;

        If AddParam3 <> Undefined Then
            ParameterArray.Add("AddParam3");
        EndIf;

        CheckTemplate = "CheckResult = Check_%1_%2(%3)";

        CheckCall = StrTemplate(CheckTemplate, Library, Method, StrConcat(ParameterArray, ", "));
        CheckResult = Undefined;

        //@skip-check server-execution-safe-mode
        Execute(CheckCall);

        Text = PrintLog(Result, LogsMethod, Library);

        If Not ValueIsFilled(Option) Then

            ResultString = TypeOf(CheckResult) = Type("String");
            Overwrite = Not ?(ResultString, CheckResult = "", CheckResult = Undefined);

            If Overwrite Then
                WriteLogFile(CheckResult, Method, Library);
            Else
                WriteLogFile(Result , Method, Library, False);
            EndIf;

        EndIf;

        WriteTestLog(ElementID, Text, "info");
        FinishTestElement(ElementID, "passed");

    Except

        ErrInfo = DetailErrorDescription(ErrorInfo());
        Text = PrintLog(Result, LogsMethod, Library, ErrInfo);

        WriteTestLog(ElementID, Text, "error");
        FinishTestElement(ElementID, "failed");

        Raise ErrInfo;

    EndTry;

EndProcedure

Function GetValueFromFile(Parameter, Path)

    Values = OPI_Tools.ReadJSONFile(Path);
    Return ?(Values.Property(Parameter), Values[Parameter], "");

EndFunction

Function DataFilePath()

    Path = "";
    PossiblePaths = New Array;
    PossiblePaths.Add("./data.json");
    PossiblePaths.Add("C:\GDrive\My Drive\data.json");
    PossiblePaths.Add("G:\My Drive\data.json");

    For Each PossiblePath In PossiblePaths Do

        RepositoryFile = New File(PossiblePath);

        If RepositoryFile.Exists() Then
            Path = PossiblePath;
            Break;
        EndIf;

    EndDo;

    Return Path;

EndFunction

Function GetCommonModule(Val Name)

    //@skip-check server-execution-safe-mode
    Module = Eval(Name);
    Return Module;

EndFunction

Function GetCLIFormedValue(Val Value, Val Embedded = False, AddOptions = "")

    CurrentType = TypeOf(Value);
    CurrentTypeString = String(CurrentType);
    Cover = False;

    If CurrentType = Type("Number") Then

        If Not Embedded Then
            Value = OPI_Tools.NumberToString(Value);
        EndIf;

    ElsIf CurrentType = Type("String") Or CurrentType = Type("UUID") Then

        Value = OPI_Tools.NumberToString(Value);

        If Not Embedded Then

            Value = StrReplace(Value, Chars.LF, "\n");
            Cover = True;

        EndIf;

        If OPI_Tools.IsWindows() Then
            Value = StrReplace(Value, "%", "%%");
        EndIf;

    ElsIf CurrentType = Type("Date") Then

        If Not Embedded Then
            Value = OPI_ToolsServerCall.GetXMLString(Value);
            Cover = True;
        EndIf;

    ElsIf CurrentType = Type("Structure") Or CurrentType = Type("Map") Or CurrentType = Type("Array") Then

        If CurrentType = Type("Structure") Or CurrentType = Type("Map") Then

            Value_ = New (CurrentTypeString);

            For Each KeyValue In Value Do
                Value_.Insert(KeyValue.Key, GetCLIFormedValue(KeyValue.Value, True, AddOptions));
            EndDo;

            Value = Value_;

        EndIf;

        If CurrentType = Type("Map") Then

            Value_ = New Map;

            For Each KeyValue In Value Do
                Value_.Insert(GetCLIFormedValue(KeyValue.Key, True, AddOptions), KeyValue.Value);
            EndDo;

            Value = Value_;

        EndIf;

        JSONWriter = New JSONWriter;

        If CurrentType = Type("Array") Or Embedded Then

            If CurrentType = Type("Array") Then
                For N = 0 To Value.UBound() Do
                    Value[N] = GetCLIFormedValue(Value[N], True, AddOptions);
                EndDo;
            EndIf;

            If Not Embedded Then
                WriterSettings = New JSONWriterSettings(JSONLineBreak.None, , False);
                JSONWriter.SetString(WriterSettings);
                WriteJSON(JSONWriter, Value);

                Value = JSONWriter.Close();
                Cover = True;
            EndIf;

        Else

            // BSLLS:MissingTemporaryFileDeletion-off

            //@skip-check missing-temporary-file-deletion
            TFN = GetTempFileName("json");

            // BSLLS:MissingTemporaryFileDeletion-on

            OPI_Tools.WriteJSONFile(TFN, Value);

            Value = TFN;
            Cover = True;

        EndIf;

    ElsIf CurrentType = Type("Boolean") Then

        If Not Embedded Then
            Value = ?(Value, "true", "false");
            Cover = False;
        EndIf;

    ElsIf CurrentType = Type("BinaryData") Then

        // BSLLS:MissingTemporaryFileDeletion-off

        //@skip-check missing-temporary-file-deletion
        TFN = GetTempFileName();
        Value.Write(TFN);
        Value = TFN;
        Cover = Not Embedded;

        // BSLLS:MissingTemporaryFileDeletion-on

    ElsIf StrStartWith(CurrentTypeString, "AddIn") Then

        Value = ProcessAddInParamCLI(Value, CurrentTypeString, AddOptions);
        Cover = Not Embedded;

    ElsIf CurrentType = Type("Undefined") And Embedded Then

        Value = Undefined;

    Else

        Raise "Invalid type " + CurrentTypeString;

    EndIf;

    If Not OPI_Tools.IsWindows() And Not Embedded Then
        Value = StrReplace(Value, """", """'""");
    EndIf;

    If Cover Then
        Value = """" + Value + """";
    EndIf;

    Return Value;

EndFunction

Function ProcessAddInParamCLI(Val Value, Val ValeType, AddOptions)

    AddInName = Upper(StrSplit(ValeType, ".")[1]);

    If AddInName = "OPI_POSTGRESQL" Or AddInName = "OPI_MYSQL" Or AddInName = "OPI_MSSQL" Then

        If AddInName = "OPI_MSSQL" Then

            TLS = New Structure("use_tls, accept_invalid_certs, ca_cert_path", True, True, "");
            AddOptions.Insert("tls", TLS);

        Else

            TLS = Value.GetTLSSettings();

            If ValueIsFilled(TLS) Then
                OPI_TypeConversion.GetCollection(TLS);
                AddOptions.Insert("tls", TLS);
            EndIf;

        EndIf;

        Value = Value["ConnectionString"];

    ElsIf AddInName = "OPI_MONGODB" Then

        Value = Value["ConnectionString"];

    ElsIf AddInName = "OPI_SQLITE" Then

        Value = Value["Database"];

    ElsIf AddInName = "OPI_TCPCLIENT" Then

        Value = Value["Address"];

    ElsIf AddInName = "OPI_RCON" Or AddInName = "OPI_GRPC" Then

        Value = Value.GetSettings();

        Message(Value);

        OPI_TypeConversion.GetKeyValueCollection(Value);
        TFN = GetTempFileName();
        OPI_Tools.WriteJSONFile(TFN, Value);

        Value = TFN;

    ElsIf AddInName = "OPI_FTP" Then

        Value = Value.GetConfiguration();
        OPI_TypeConversion.GetKeyValueCollection(Value);

        Data = Value["data"];
        Configuration = New Structure;

        Configuration.Insert("set", Data["ftp_settings"]);

        If ValueIsFilled(Data["tls_settings"]) Then
            Configuration.Insert("tls", Data["tls_settings"]);
        EndIf;

        If ValueIsFilled(Data["proxy_settings"]) Then
            Configuration.Insert("proxy", Data["proxy_settings"]);
        EndIf;

        TFN = GetTempFileName();
        OPI_Tools.WriteJSONFile(TFN, Configuration);

        Value = TFN;

    ElsIf AddInName = "OPI_SSH" Then

        Value = Value.GetConfiguration();
        OPI_TypeConversion.GetKeyValueCollection(Value);

        Value = Value["conf"];

        TFN = GetTempFileName();
        OPI_Tools.WriteJSONFile(TFN, Value);

        Value = TFN;

    Else
        Raise "Invalid type " + ValeType;
    EndIf;

    Return Value;

EndFunction

Function FormOption(Val Name, Val Value, Embedded = False)

    SecretsArray = GetSecretKeyArray();

    ExceptionsList = New ValueList;
    ExceptionsList.Add("passive");
    ExceptionsList.Add("keyboard");

    ReplaceStructure = New Map;
    ReplaceStructure.Insert("host.docker.internal", "127.0.0.1");

    Cover = False;

    If TypeOf(Value) = Type("String") Then

        For Each SecretKey In SecretsArray Do

            If StrFind(Lower(Name), SecretKey) <> 0 And ExceptionsList.FindByValue(Lower(Name)) = Undefined Then

                Value = "***";
                Cover = True;

            EndIf;

        EndDo;

        For Each ReplaceValue In ReplaceStructure Do
            Value = StrReplace(Value, ReplaceValue.Key, ReplaceValue.Value);
        EndDo;

        ValueAsString = Value;

        If Not Embedded And StrStartWith(ValueAsString, """") And StrEndsWith(ValueAsString, """") Then

            ValueAsString = Left(ValueAsString, StrLen(ValueAsString) - 1);
            ValueAsString = Right(ValueAsString, StrLen(ValueAsString) - 1);

            Cover = True;

        EndIf;

        Value = ValueAsString;
        OPI_TypeConversion.GetCollection(Value, False);

    Else
        ValueAsString = "-----------!!!!№№№---------------";
    EndIf;

    If TypeOf(Value) = Type("Array") Then

        If Not Value.Count() = 0 Then

            If String(Value[0]) = ValueAsString Then
                Value = ValueAsString;
            Else

                For N = 0 To Value.UBound() Do
                    Value[N] = FormOption("", Value[N], True);
                EndDo;

            EndIf;

        EndIf;

    ElsIf OPI_Tools.ThisIsCollection(Value, True) Then

        Value_ = New (TypeOf(Value));

        For Each KeyValue In Value Do
            Value_.Insert(KeyValue.Key, FormOption(KeyValue.Key, KeyValue.Value, True));
        EndDo;

        Value = Value_;

    Else

        OPI_TypeConversion.GetLine(Value);

    EndIf;

    If Embedded Then
        Return Value;
    Else

        If Not TypeOf(Value) = Type("String") Then
            Try
                Value = OPI_Tools.JSONString(Value, , False, False);
            Except
                Value = String(Value);
            EndTry;
        EndIf;

        Value = ?(Cover, StrTemplate("""%1""", Value), Value);
        Return "--" + Name + " " + Value;

    EndIf;

EndFunction

Function ReadCLIResponse(Val ResultFile)

    Try

        // BSLLS:ExternalAppStarting-off
        JSONReader = New JSONReader;
        JSONReader.OpenFile(ResultFile);
        Result = ReadJSON(JSONReader, True);
        JSONReader.Close();
        // BSLLS:ExternalAppStarting-on

    Except

        Message(DetailErrorDescription(ErrorInfo()));

        Try
            Result = New BinaryData(ResultFile);

            If Result.Size() < 10000 Then
                Result = GetStringFromBinaryData(Result);
            EndIf;

        Except
            Result = Null;
        EndTry;

    EndTry;

    Return Result;

EndFunction

Function PrintLog(Val Result, Val Method, Val Library, Val ErrorDescription = Undefined)

    Header = String(OPI_Tools.GetCurrentDate()) + " | " + Method;

    Data = TestResultAsText(Result);

    Text = Header + Chars.LF + Chars.LF;

    If ValueIsFilled(ErrorDescription) Then
        Text = Text + ErrorDescription + Chars.LF + Chars.LF + "---------------------------------" + Chars.LF
            + Chars.LF;
    EndIf;

    Text = Text + Data + Chars.LF + Chars.LF + "---------------------------------" + Chars.LF;

    Message(Text);

    Return Text;

EndFunction

Function TestResultAsText(Val Result)

    Try
        Data = OPI_Tools.JSONString(Result);
    Except
        Data = String(Result);
    EndTry;

    Data = TrimAll(Data);

    Return Data;

EndFunction

Function ReplaceSecretsRecursively(Value, Val Indicators, Val Hide = False)

    If TypeOf(Value) = Type("Array") Then

        Value_ = New Array;

        For Each Element In Value Do
            Value_.Add(ReplaceSecretsRecursively(Element, Indicators, Hide));
        EndDo;

    ElsIf OPI_Tools.ThisIsCollection(Value, True) Then

        Value_ = New(TypeOf(Value));

        For Each Element In Value Do

            CurrentKey = Element.Key;
            CurrentValue = Element.Value;

            If OPI_Tools.ThisIsCollection(CurrentValue) Then
                CurrentValue = ReplaceSecretsRecursively(CurrentValue, Indicators);
            Else

                For Each Indication In Indicators Do

                    CurrentKeyN = Lower(CurrentKey);
                    AttributeN = Lower(Indication);

                    If StrFind(CurrentKeyN, AttributeN) > 0 Then
                        CurrentValue = ReplaceSecretsRecursively(CurrentValue, Indicators, True);
                        Break;
                    EndIf;

                EndDo;

            EndIf;

            TruncateString(CurrentValue, 100);

            Value_.Insert(CurrentKey, CurrentValue);

        EndDo;

    Else

        If Hide Then
            Value_ = "***";
        Else
            Value_ = Value;
        EndIf;

        TruncateString(Value_, 100);

    EndIf;

    Return Value_;

EndFunction

Function GetSecretKeyArray()

    SecretsArray = New Array;
    SecretsArray.Add("token");
    SecretsArray.Add("key");
    SecretsArray.Add("secret");
    SecretsArray.Add("pass");
    SecretsArray.Add("password");
    SecretsArray.Add("client");
    SecretsArray.Add("api");
    SecretsArray.Add("refresh");
    SecretsArray.Add("phone");
    SecretsArray.Add("idInstance");
    SecretsArray.Add("wid");
    SecretsArray.Add("sender");
    SecretsArray.Add("chat");
    SecretsArray.Add("invite");
    SecretsArray.Add("origin");
    SecretsArray.Add("bayselonarrend");

    Return SecretsArray;

EndFunction

Function GetAICheckAttributes(Val Result)

    OPI_TypeConversion.GetLine(Result);
    Result_ = Lower(Result);

    KeyWordArray = New Array;
    KeyWordArray.Add("error");
    KeyWordArray.Add("exception");
    KeyWordArray.Add("failed");

    NeedCheck = False;

    For Each KeyWord In KeyWordArray Do
        If StrFind(Result_, KeyWord) > 0 Then
            NeedCheck = True;
            Break;
        EndIf;
    EndDo;

    If Not NeedCheck Then
        Return Undefined;
    EndIf;

    Prompt = "You need to check the received service response and determine whether it is an error message from the
    |server that could not process it (regardless of the reason) or found issues with the request.
    |Return only one word ""error"" if an error is found or one word ""success"" if there was no error
    |
    |Service response:
    |%1";

    Prompt = StrTemplate(Prompt, Result);

    Token = GetParameter("CI_AI_Token");
    URL = GetParameter("CI_AI_URL");
    Model = GetParameter("CI_AI_Model");

    Message = OPI_OpenAI.GetMessageStructure("user", Prompt);

    AttributeTemplate = "ai_check: %1";
    Skip = StrTemplate(AttributeTemplate, "skipped");

    Try
        Response = OPI_OpenAI.GetResponse(URL, Token, Model, Message);
    Except
        Return Skip;
    EndTry;

    If OPI_Tools.ThisIsCollection(Response) Then

        Try
            ResponseValue = Response["choices"][0]["message"]["content"];
            Attribute = StrTemplate(AttributeTemplate, ResponseValue);
        Except
            Attribute = Skip;
        EndTry;

    Else
        Attribute = Skip;
    EndIf;

    Return Attribute;

EndFunction

Procedure NewTest(ArrayOfTests, TestModule, Val Method, Val Synonym, Val Section)

    If Not ValueIsFilled(TestModule) Or TestModule = Section Then

        NewTest = New Structure("Method,Synonym,Section");
        NewTest.Method = Method;
        NewTest.Synonym = Synonym;
        NewTest.Section = Section;

        ArrayOfTests.Add(NewTest);

    EndIf;

EndProcedure

Procedure WriteParameterToFile(Val Parameter, Val Value, Val Path)

    Values = OPI_Tools.ReadJSONFile(Path);
    Values.Insert(Parameter, Value);

    // BSLLS:ExternalAppStarting-off
    Record = New JSONWriter;
    JSONWriterSettings = New JSONWriterSettings(JSONLineBreak.Auto, Chars.Tab);
    Record.OpenFile(Path, , , JSONWriterSettings);
    WriteJSON(Record, Values);
    Record.Close();
    // BSLLS:ExternalAppStarting-on

EndProcedure

Procedure WriteCLICall(Val Library, Val Method, Val Options)

    If Not OPI_Tools.IsOneScript() Then
        Return;
    EndIf;

    CatalogExample = "./docs/en/cli/" + Library;
    FileExample = New File(CatalogExample);

    If Not FileExample.Exists() Then
        CreateDirectory(CatalogExample);
    EndIf;

    MethodCatalog = CatalogExample + "/" + Method;
    MethodFile = New File(MethodCatalog);

    If Not MethodFile.Exists() Then
        CreateDirectory(MethodCatalog);
    EndIf;

    OptionsArray = New Array;
    FindJSON = False;

    For Each Option In Options Do

        CurrentOption = Option.Value;

        ProcessSpecialOptionsSecrets(Library, Option.Key, CurrentOption);

        CurrentOption = FormOption(Option.Key, CurrentOption);

        If Not FindJSON Then
            FindJSON = StrFind(CurrentOption, "{") > 0 And StrFind(CurrentOption, "}") > 0;
        EndIf;

        OptionsArray.Add(CurrentOption);

    EndDo;

    Start = "oint ";

    If FindJSON Then

        Information = "JSON data can also be passed as a path to a .json file";

        StartBat = ":: " + Information + Chars.LF + Chars.LF + Start;
        StartBash = "# " + Information + Chars.LF + Chars.LF + Start;

    Else

        StartBat = Start;
        StartBash = Start;

    EndIf;

    BatSeparator = " ^" + Chars.LF + "  ";
    BashSeparator = " \" + Chars.LF + "  ";

    BatString = StartBat + Library + " " + Method + BatSeparator + StrConcat(OptionsArray, BatSeparator);
    BashString = StartBash + Library + " " + Method + BashSeparator + StrConcat(OptionsArray, BashSeparator);

    GetBinaryDataFromString(BatString).Write(MethodCatalog + "/bat.txt");
    GetBinaryDataFromString(BashString).Write(MethodCatalog + "/bash.txt");

EndProcedure

Procedure WriteLogFile(Val Data, Val Method, Val Library, Val Overwrite = True)

    If Not OPI_Tools.IsOneScript() Then
        Return;
    EndIf;

    Try

        LogPath = "./docs/en/results";
        LibraryLogPath = LogPath + "/" + Library;
        FilePath = LibraryLogPath + "/" + Method + ".log";

        If Not Overwrite Then

            LogObject = New File(FilePath);

            If LogObject.Exists() Then
                Return;
            EndIf;

        EndIf;

        LogDirectory = New File(LogPath);

        If Not LogDirectory.Exists() Then
            CreateDirectory(LogPath);
        EndIf;

        LibraryLogCatalog = New File(LibraryLogPath);

        If Not LibraryLogCatalog.Exists() Then
            CreateDirectory(LibraryLogPath);
        EndIf;

        If OPI_Tools.ThisIsCollection(Data) Then

            SecretsArray = GetSecretKeyArray();
            Data = ReplaceSecretsRecursively(Data, SecretsArray);

        EndIf;

        DataText = TestResultAsText(Data);

        LogDocument = New TextDocument;
        LogDocument.SetText(DataText);
        LogDocument.Write(FilePath);

    Except
        Message("Failed to write log file!: " + ErrorDescription());
    EndTry;

EndProcedure

Procedure TruncateString(Value, Val SymbolCount)

    If TypeOf(Value) = Type("String") Then
        If StrLen(Value) > SymbolCount Then
            Value = Left(Value, SymbolCount) + "...";
        EndIf;
    EndIf;

EndProcedure

Procedure ProcessSpecialOptionsSecrets(Val Library, Val Option, Value)

    Value_ = Value;

    If Library = "bitrix24" Then

        ProcessSecretsBitrix24(Option, Value);

    ElsIf Library = "postgres" Then

        ProcessSecretsPostgreSQL(Option, Value);

    ElsIf Library = "mysql" Then

        ProcessSecretsMySQL(Option, Value);

    ElsIf Library = "mssql" Then

        ProcessSecretsMSSQL(Option, Value);

    ElsIf Library = "ollama" Then

        ProcessSecretsMySQLOllama(Option, Value);

    ElsIf Library = "vk" Then

        ProcessSecretsVK(Option, Value);

    Else
        Return;
    EndIf;

    If Not Value_ = Value Then
        Value = StrTemplate("""%1""", Value);
    EndIf;

EndProcedure

Procedure ProcessSecretsBitrix24(Val Option, Value)

    If Option = "url" Then

        Value = ?(StrFind(Value, "rest") > 0, "https://b24-ar17wx.bitrix24.by/rest/1/***", Value);

    EndIf;

EndProcedure

Procedure ProcessSecretsPostgreSQL(Val Option, Value)

    If Option = "dbc" Then

        Value = "postgresql://bayselonarrend:***@127.0.0.1:5432/";

    ElsIf Option = "addr" Then

        Value = "127.0.0.1";

    Else
        Return;
    EndIf;

EndProcedure

Procedure ProcessSecretsMySQL(Val Option, Value)

    If Option = "dbc" Then

        Value = "mysql://bayselonarrend:***@127.0.0.1:3306/";

    ElsIf Option = "addr" Then

        Value = "127.0.0.1";

    Else
        Return;
    EndIf;

EndProcedure

Procedure ProcessSecretsMSSQL(Val Option, Value)

    If Option = "dbc" Then

        Value = "Server=127.0.0.1;Database=***;User Id=SA;Password=***;";

    ElsIf Option = "addr" Then

        Value = "127.0.0.1";

    Else
        Return;
    EndIf;

EndProcedure

Procedure ProcessSecretsMySQLOllama(Val Option, Value)

    If Option = "headers" Then

        Value = OPI_Tools.JSONString(New Structure("Authorization", "***"));

    Else
        Return;
    EndIf;

EndProcedure

Procedure ProcessSecretsVK(Val Option, Value)

    If Option = "ct" Then

        Value = "***";

    EndIf;

EndProcedure

#EndRegion

#EndRegion

