mirror of
https://github.com/sochix/TLSharp.git
synced 2026-04-06 06:55:06 +00:00
- fix file Uploader
- refactor file uploader - added test for file uploading
This commit is contained in:
parent
7fd0413c7e
commit
1d6035aeb7
4 changed files with 213 additions and 106 deletions
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?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>
|
||||
|
|
@ -68,6 +68,11 @@
|
|||
<Name>TLSharp.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="data\cat.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TeleSharp.TL;
|
||||
using TeleSharp.TL.Channels;
|
||||
|
|
@ -15,6 +16,8 @@ using TLSharp.Core;
|
|||
using TLSharp.Core.Auth;
|
||||
using TLSharp.Core.MTProto;
|
||||
using TLSharp.Core.Network;
|
||||
using TLSharp.Core.Requests;
|
||||
using TLSharp.Core.Utils;
|
||||
|
||||
namespace TLSharp.Tests
|
||||
{
|
||||
|
|
@ -37,7 +40,7 @@ namespace TLSharp.Tests
|
|||
|
||||
private int apiId = 0;
|
||||
|
||||
[TestInitialize]
|
||||
[TestInitialize]
|
||||
public void Init()
|
||||
{
|
||||
// Setup your phone numbers in app.config
|
||||
|
|
@ -117,7 +120,49 @@ namespace TLSharp.Tests
|
|||
await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestMethod]
|
||||
public async Task SendPhotoToContactTest()
|
||||
{
|
||||
var client = new TelegramClient(apiId, apiHash);
|
||||
|
||||
await client.ConnectAsync();
|
||||
|
||||
var result = await client.GetContactsAsync();
|
||||
|
||||
var user = result.users.lists
|
||||
.Where(x => x.GetType() == typeof(TLUser))
|
||||
.Cast<TLUser>()
|
||||
.FirstOrDefault(x => x.phone == NumberToSendMessage);
|
||||
|
||||
var fileResult = (TLInputFile)await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg"));
|
||||
await client.SendUploadedPhoto(new TLInputPeerUser() {user_id = user.id}, fileResult, "kitty");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task SendBigFileToContactTest()
|
||||
{
|
||||
var client = new TelegramClient(apiId, apiHash);
|
||||
|
||||
await client.ConnectAsync();
|
||||
|
||||
var result = await client.GetContactsAsync();
|
||||
|
||||
var user = result.users.lists
|
||||
.Where(x => x.GetType() == typeof(TLUser))
|
||||
.Cast<TLUser>()
|
||||
.FirstOrDefault(x => x.phone == NumberToSendMessage);
|
||||
|
||||
var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("C:\\PetProjects\\TelegramBotSample.zip"));
|
||||
|
||||
await client.SendUploadedDocument(
|
||||
new TLInputPeerUser() {user_id = user.id},
|
||||
fileResult,
|
||||
"some zips",
|
||||
"application/zip",
|
||||
new TLVector<TLAbsDocumentAttribute>());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task SignUpNewUser()
|
||||
{
|
||||
var client = new TelegramClient(apiId, apiHash);
|
||||
|
|
@ -143,6 +188,5 @@ namespace TLSharp.Tests
|
|||
var result = await client.IsPhoneRegisteredAsync(NumberToAuthenticate);
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue