mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Remove Test Project
This commit is contained in:
parent
78e3a7794f
commit
f083fb9b30
|
|
@ -1,36 +0,0 @@
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
|
||||||
// set of attributes. Change these attribute values to modify the information
|
|
||||||
// associated with an assembly.
|
|
||||||
[assembly: AssemblyTitle("TLSharp.Tests")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("TLSharp.Tests")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
|
||||||
// to COM components. If you need to access a type in this assembly from
|
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|
||||||
[assembly: Guid("de5c0467-ee99-4734-95f2-eff7a0b99924")]
|
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
|
||||||
//
|
|
||||||
// Major Version
|
|
||||||
// Minor Version
|
|
||||||
// Build Number
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
|
||||||
// by using the '*' as shown below:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{DE5C0467-EE99-4734-95F2-EFF7A0B99924}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>TLSharp.Tests</RootNamespace>
|
|
||||||
<AssemblyName>TLSharp.Tests</AssemblyName>
|
|
||||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
|
||||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
|
||||||
<IsCodedUITest>False</IsCodedUITest>
|
|
||||||
<TestProjectType>UnitTest</TestProjectType>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Configuration" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Choose>
|
|
||||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
|
||||||
</ItemGroup>
|
|
||||||
</When>
|
|
||||||
<Otherwise>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Otherwise>
|
|
||||||
</Choose>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="TLSharpTests.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="app.config" />
|
|
||||||
<None Include="packages.config" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\TLSharp.Core\TLSharp.Core.csproj">
|
|
||||||
<Project>{400d2544-1cc6-4d8a-a62c-2292d9947a16}</Project>
|
|
||||||
<Name>TLSharp.Core</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<Choose>
|
|
||||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
</When>
|
|
||||||
</Choose>
|
|
||||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
|
||||||
<Target Name="BeforeBuild">
|
|
||||||
</Target>
|
|
||||||
<Target Name="AfterBuild">
|
|
||||||
</Target>
|
|
||||||
-->
|
|
||||||
</Project>
|
|
||||||
|
|
@ -1,423 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Configuration;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
using TLSharp.Core;
|
|
||||||
using TLSharp.Core.Auth;
|
|
||||||
using TLSharp.Core.MTProto;
|
|
||||||
using TLSharp.Core.Network;
|
|
||||||
|
|
||||||
namespace TLSharp.Tests
|
|
||||||
{
|
|
||||||
[TestClass]
|
|
||||||
public class TLSharpTests
|
|
||||||
{
|
|
||||||
private string NumberToSendMessage { get; set; }
|
|
||||||
|
|
||||||
private string NumberToAuthenticate { get; set; }
|
|
||||||
|
|
||||||
private string NotRegisteredNumberToSignUp { get; set; }
|
|
||||||
|
|
||||||
private string UserNameToSendMessage { get; set; }
|
|
||||||
|
|
||||||
private string NumberToGetUserFull { get; set; }
|
|
||||||
|
|
||||||
private string NumberToAddToChat { get; set; }
|
|
||||||
|
|
||||||
private string apiHash = "";
|
|
||||||
|
|
||||||
private int apiId = 0;
|
|
||||||
|
|
||||||
[TestInitialize]
|
|
||||||
public void Init()
|
|
||||||
{
|
|
||||||
// Setup your phone numbers in app.config
|
|
||||||
NumberToAuthenticate = ConfigurationManager.AppSettings[nameof(NumberToAuthenticate)];
|
|
||||||
if (string.IsNullOrEmpty(NumberToAuthenticate))
|
|
||||||
Debug.WriteLine("NumberToAuthenticate not configured in app.config! Some tests may fail.");
|
|
||||||
|
|
||||||
NotRegisteredNumberToSignUp = ConfigurationManager.AppSettings[nameof(NotRegisteredNumberToSignUp)];
|
|
||||||
if (string.IsNullOrEmpty(NotRegisteredNumberToSignUp))
|
|
||||||
Debug.WriteLine("NotRegisteredNumberToSignUp not configured in app.config! Some tests may fail.");
|
|
||||||
|
|
||||||
NumberToSendMessage = ConfigurationManager.AppSettings[nameof(NumberToSendMessage)];
|
|
||||||
if (string.IsNullOrEmpty(NumberToSendMessage))
|
|
||||||
Debug.WriteLine("NumberToSendMessage not configured in app.config! Some tests may fail.");
|
|
||||||
|
|
||||||
UserNameToSendMessage = ConfigurationManager.AppSettings[nameof(UserNameToSendMessage)];
|
|
||||||
if (string.IsNullOrEmpty(UserNameToSendMessage))
|
|
||||||
Debug.WriteLine("UserNameToSendMessage not configured in app.config! Some tests may fail.");
|
|
||||||
|
|
||||||
NumberToGetUserFull = ConfigurationManager.AppSettings[nameof(NumberToGetUserFull)];
|
|
||||||
if (string.IsNullOrEmpty(NumberToGetUserFull))
|
|
||||||
Debug.WriteLine("NumberToGetUserFull not configured in app.config! Some tests may fail.");
|
|
||||||
|
|
||||||
NumberToAddToChat = ConfigurationManager.AppSettings[nameof(NumberToAddToChat)];
|
|
||||||
if (string.IsNullOrEmpty(NumberToAddToChat))
|
|
||||||
Debug.WriteLine("NumberToAddToChat not configured in app.config! Some tests may fail.");
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task AuthUser()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
var hash = await client.SendCodeRequest(NumberToAuthenticate);
|
|
||||||
var code = "93463"; // you can change code in debugger
|
|
||||||
|
|
||||||
var user = await client.MakeAuth(NumberToAuthenticate, hash, code);
|
|
||||||
|
|
||||||
Assert.IsNotNull(user);
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task SignUpNewUser()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
var hash = await client.SendCodeRequest(NotRegisteredNumberToSignUp);
|
|
||||||
var code = "";
|
|
||||||
|
|
||||||
var registeredUser = await client.SignUp(NotRegisteredNumberToSignUp, hash, code, "TLSharp", "User");
|
|
||||||
Assert.IsNotNull(registeredUser);
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var loggedInUser = await client.MakeAuth(NotRegisteredNumberToSignUp, hash, code);
|
|
||||||
Assert.IsNotNull(loggedInUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task CheckPhones()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
var result = await client.IsPhoneRegistered(NumberToAuthenticate);
|
|
||||||
Assert.IsTrue(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task ImportContactByPhoneNumber()
|
|
||||||
{
|
|
||||||
// User should be already authenticated!
|
|
||||||
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var res = await client.ImportContactByPhoneNumber(NumberToSendMessage);
|
|
||||||
|
|
||||||
Assert.IsNotNull(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task ImportByUserName()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var res = await client.ImportByUserName(UserNameToSendMessage);
|
|
||||||
|
|
||||||
Assert.IsNotNull(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task ImportByUserNameAndSendMessage()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var res = await client.ImportByUserName(UserNameToSendMessage);
|
|
||||||
|
|
||||||
Assert.IsNotNull(res);
|
|
||||||
|
|
||||||
await client.SendMessage(res.Value, "Test message from TelegramClient");
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task ImportContactByPhoneNumberAndSendMessage()
|
|
||||||
{
|
|
||||||
// User should be already authenticated!
|
|
||||||
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var res = await client.ImportContactByPhoneNumber(NumberToSendMessage);
|
|
||||||
|
|
||||||
Assert.IsNotNull(res);
|
|
||||||
|
|
||||||
await client.SendMessage(res.Value, "Test message from TelegramClient");
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task GetHistory()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var res = await client.ImportContactByPhoneNumber(NumberToSendMessage);
|
|
||||||
|
|
||||||
Assert.IsNotNull(res);
|
|
||||||
|
|
||||||
var hist = await client.GetMessagesHistoryForContact(res.Value, 0, 5);
|
|
||||||
|
|
||||||
Assert.IsNotNull(hist);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task UploadAndSendMedia()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var res = await client.ImportContactByPhoneNumber(NumberToSendMessage);
|
|
||||||
|
|
||||||
Assert.IsNotNull(res);
|
|
||||||
|
|
||||||
var file = File.ReadAllBytes("../../data/cat.jpg");
|
|
||||||
|
|
||||||
var mediaFile = await client.UploadFile("test_file.jpg", file);
|
|
||||||
|
|
||||||
Assert.IsNotNull(mediaFile);
|
|
||||||
|
|
||||||
var state = await client.SendMediaMessage(res.Value, mediaFile);
|
|
||||||
|
|
||||||
Assert.IsTrue(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task GetFile()
|
|
||||||
{
|
|
||||||
// Get uploaded file from last message (ie: cat.jpg)
|
|
||||||
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
await client.Connect();
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var res = await client.ImportContactByPhoneNumber(NumberToSendMessage);
|
|
||||||
Assert.IsNotNull(res);
|
|
||||||
|
|
||||||
// Get last message
|
|
||||||
var hist = await client.GetMessagesHistoryForContact(res.Value, 0, 1);
|
|
||||||
Assert.AreEqual(1, hist.Count);
|
|
||||||
|
|
||||||
var message = (MessageConstructor) hist[0];
|
|
||||||
Assert.AreEqual(typeof (MessageMediaPhotoConstructor), message.media.GetType());
|
|
||||||
|
|
||||||
var media = (MessageMediaPhotoConstructor) message.media;
|
|
||||||
Assert.AreEqual(typeof (PhotoConstructor), media.photo.GetType());
|
|
||||||
|
|
||||||
var photo = (PhotoConstructor) media.photo;
|
|
||||||
Assert.AreEqual(3, photo.sizes.Count);
|
|
||||||
Assert.AreEqual(typeof (PhotoSizeConstructor), photo.sizes[2].GetType());
|
|
||||||
|
|
||||||
var photoSize = (PhotoSizeConstructor) photo.sizes[2];
|
|
||||||
Assert.AreEqual(typeof (FileLocationConstructor), photoSize.location.GetType());
|
|
||||||
|
|
||||||
var fileLocation = (FileLocationConstructor) photoSize.location;
|
|
||||||
var file = await client.GetFile(fileLocation.volume_id, fileLocation.local_id, fileLocation.secret, 0, photoSize.size + 1024);
|
|
||||||
storage_FileType type = file.Item1;
|
|
||||||
byte[] bytes = file.Item2;
|
|
||||||
|
|
||||||
string name = "../../data/get_file.";
|
|
||||||
if (type.GetType() == typeof (Storage_fileJpegConstructor))
|
|
||||||
name += "jpg";
|
|
||||||
else if (type.GetType() == typeof (Storage_fileGifConstructor))
|
|
||||||
name += "gif";
|
|
||||||
else if (type.GetType() == typeof (Storage_filePngConstructor))
|
|
||||||
name += "png";
|
|
||||||
|
|
||||||
using (var fileStream = new FileStream(name, FileMode.Create, FileAccess.Write))
|
|
||||||
{
|
|
||||||
fileStream.Write(bytes, 4, photoSize.size); // The first 4 bytes seem to be the error code
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task TestConnection()
|
|
||||||
{
|
|
||||||
var store = new FakeSessionStore();
|
|
||||||
var client = new TelegramClient(store, "", apiId, apiHash);
|
|
||||||
|
|
||||||
Assert.IsTrue(await client.Connect());
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task AuthenticationWorks()
|
|
||||||
{
|
|
||||||
using (var transport = new TcpTransport("91.108.56.165", 443))
|
|
||||||
{
|
|
||||||
var authKey = await Authenticator.DoAuthentication(transport);
|
|
||||||
|
|
||||||
Assert.IsNotNull(authKey.AuthKey.Data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task GetUserFullRequest()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var res = await client.ImportContactByPhoneNumber(NumberToGetUserFull);
|
|
||||||
|
|
||||||
Assert.IsNotNull(res);
|
|
||||||
|
|
||||||
var userFull = await client.GetUserFull(res.Value);
|
|
||||||
|
|
||||||
Assert.IsNotNull(userFull);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task CreateChatRequest()
|
|
||||||
{
|
|
||||||
var client = await InitializeClient();
|
|
||||||
|
|
||||||
var chatName = Guid.NewGuid().ToString();
|
|
||||||
var statedMessage = await client.CreateChat(chatName, new List<string> {NumberToSendMessage});
|
|
||||||
|
|
||||||
var createdChat = GetChatFromStatedMessage(statedMessage);
|
|
||||||
|
|
||||||
Assert.AreEqual(chatName, createdChat.title);
|
|
||||||
Assert.AreEqual(2, createdChat.participants_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task AddChatUserRequest()
|
|
||||||
{
|
|
||||||
var client = await InitializeClient();
|
|
||||||
|
|
||||||
var chatName = Guid.NewGuid().ToString();
|
|
||||||
var statedMessageAfterCreation = await client.CreateChat(chatName, new List<string> { NumberToSendMessage });
|
|
||||||
|
|
||||||
var createdChat = GetChatFromStatedMessage(statedMessageAfterCreation);
|
|
||||||
|
|
||||||
var addUserId = await client.ImportContactByPhoneNumber(NumberToAddToChat);
|
|
||||||
|
|
||||||
var statedMessageAfterAddUser = await client.AddChatUser(createdChat.id, addUserId.Value);
|
|
||||||
var modifiedChat = GetChatFromStatedMessage(statedMessageAfterAddUser);
|
|
||||||
|
|
||||||
Assert.AreEqual(createdChat.id, modifiedChat.id);
|
|
||||||
Assert.AreEqual(3, modifiedChat.participants_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task LeaveChatRequest()
|
|
||||||
{
|
|
||||||
var client = await InitializeClient();
|
|
||||||
|
|
||||||
var chatName = Guid.NewGuid().ToString();
|
|
||||||
var statedMessageAfterCreation = await client.CreateChat(chatName, new List<string> { NumberToSendMessage });
|
|
||||||
|
|
||||||
var createdChat = GetChatFromStatedMessage(statedMessageAfterCreation);
|
|
||||||
|
|
||||||
var statedMessageAfterLeave = await client.LeaveChat(createdChat.id);
|
|
||||||
var modifiedChat = GetChatFromStatedMessage(statedMessageAfterLeave);
|
|
||||||
|
|
||||||
Assert.AreEqual(createdChat.id, modifiedChat.id);
|
|
||||||
Assert.AreEqual(1, modifiedChat.participants_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ChatConstructor GetChatFromStatedMessage(Messages_statedMessageConstructor message)
|
|
||||||
{
|
|
||||||
var serviceMessage = message.message as MessageServiceConstructor;
|
|
||||||
var peerChat = serviceMessage.to_id as PeerChatConstructor;
|
|
||||||
|
|
||||||
var createdChatId = peerChat.chat_id;
|
|
||||||
return message.chats.OfType<ChatConstructor>().Single(c => c.id == createdChatId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<TelegramClient> InitializeClient()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
if (!client.IsUserAuthorized())
|
|
||||||
{
|
|
||||||
var hash = await client.SendCodeRequest(NumberToAuthenticate);
|
|
||||||
|
|
||||||
var code = ""; // you can change code in debugger
|
|
||||||
Debugger.Break();
|
|
||||||
|
|
||||||
await client.MakeAuth(NumberToAuthenticate, hash, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task GetUpdates()
|
|
||||||
{
|
|
||||||
var store = new FileSessionStore();
|
|
||||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
|
||||||
await client.Connect();
|
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
|
||||||
|
|
||||||
var updatesState = await client.GetUpdatesState();
|
|
||||||
var initialState = updatesState as Updates_stateConstructor;
|
|
||||||
|
|
||||||
Assert.IsNotNull(initialState);
|
|
||||||
|
|
||||||
var difference = await client.GetUpdatesDifference(initialState.pts, initialState.date, initialState.qts);
|
|
||||||
Assert.IsNotNull(difference);
|
|
||||||
Assert.AreEqual(difference.Constructor, Constructor.updates_differenceEmpty);
|
|
||||||
|
|
||||||
var userIdToSendMessage = await client.ImportContactByPhoneNumber(NumberToSendMessage);
|
|
||||||
|
|
||||||
await client.SendMessage(userIdToSendMessage.Value, "test");
|
|
||||||
|
|
||||||
var differenceAfterMessage = await client.GetUpdatesDifference(initialState.pts, initialState.date, initialState.qts);
|
|
||||||
|
|
||||||
Assert.IsNotNull(differenceAfterMessage);
|
|
||||||
Assert.AreEqual(differenceAfterMessage.Constructor, Constructor.updates_difference);
|
|
||||||
|
|
||||||
var differenceUpdate = differenceAfterMessage as Updates_differenceConstructor;
|
|
||||||
Assert.IsNotNull(differenceUpdate);
|
|
||||||
Assert.AreEqual(1, differenceUpdate.new_messages.Count);
|
|
||||||
|
|
||||||
var messageUpdate = differenceUpdate.new_messages[0] as MessageConstructor;
|
|
||||||
Assert.IsNotNull(messageUpdate);
|
|
||||||
|
|
||||||
Assert.AreEqual("test", messageUpdate.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<configuration>
|
|
||||||
<appSettings>
|
|
||||||
<add key="NumberToAuthenticate" value="" />
|
|
||||||
<add key="NotRegisteredNumberToSignUp" value=""/>
|
|
||||||
<add key="NumberToSendMessage" value=""/>
|
|
||||||
<add key="UserNameToSendMessage" value=""/>
|
|
||||||
<add key="NumberToGetUserFull" value=""/>
|
|
||||||
<add key="NumberToAddToChat" value=""/>
|
|
||||||
</appSettings>
|
|
||||||
</configuration>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 20 KiB |
|
|
@ -1,3 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<packages>
|
|
||||||
</packages>
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 14
|
# Visual Studio 14
|
||||||
VisualStudioVersion = 14.0.23107.0
|
VisualStudioVersion = 14.0.24720.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TLSharp.Core", "TLSharp.Core\TLSharp.Core.csproj", "{400D2544-1CC6-4D8A-A62C-2292D9947A16}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TLSharp.Core", "TLSharp.Core\TLSharp.Core.csproj", "{400D2544-1CC6-4D8A-A62C-2292D9947A16}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TLSharp.Tests", "TLSharp.Tests\TLSharp.Tests.csproj", "{DE5C0467-EE99-4734-95F2-EFF7A0B99924}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
@ -17,10 +15,6 @@ Global
|
||||||
{400D2544-1CC6-4D8A-A62C-2292D9947A16}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{400D2544-1CC6-4D8A-A62C-2292D9947A16}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{400D2544-1CC6-4D8A-A62C-2292D9947A16}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{400D2544-1CC6-4D8A-A62C-2292D9947A16}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{400D2544-1CC6-4D8A-A62C-2292D9947A16}.Release|Any CPU.Build.0 = Release|Any CPU
|
{400D2544-1CC6-4D8A-A62C-2292D9947A16}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{DE5C0467-EE99-4734-95F2-EFF7A0B99924}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{DE5C0467-EE99-4734-95F2-EFF7A0B99924}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{DE5C0467-EE99-4734-95F2-EFF7A0B99924}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{DE5C0467-EE99-4734-95F2-EFF7A0B99924}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue