mirror of
https://github.com/sochix/TLSharp.git
synced 2026-04-06 06:55:06 +00:00
apply resharper's code style
This commit is contained in:
parent
1697db9d7f
commit
7fad829dd2
776 changed files with 14393 additions and 24502 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
|
@ -33,4 +32,4 @@ using System.Runtime.InteropServices;
|
|||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
|
@ -1,23 +1,22 @@
|
|||
|
||||
using System;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using TeleSharp.TL;
|
||||
using TeleSharp.TL.Messages;
|
||||
using TLSharp.Core;
|
||||
using TLSharp.Core.Network;
|
||||
using TLSharp.Core.Requests;
|
||||
using TLSharp.Core.Utils;
|
||||
|
||||
namespace TLSharp.Tests
|
||||
{
|
||||
public class TLSharpTests
|
||||
{
|
||||
internal static Action<object> IsNotNullHanlder;
|
||||
internal static Action<bool> IsTrueHandler;
|
||||
private string NumberToSendMessage { get; set; }
|
||||
|
||||
private string NumberToAuthenticate { get; set; }
|
||||
|
|
@ -38,22 +37,6 @@ namespace TLSharp.Tests
|
|||
|
||||
private int ApiId { get; set; }
|
||||
|
||||
class Assert
|
||||
{
|
||||
static internal void IsNotNull(object obj)
|
||||
{
|
||||
IsNotNullHanlder(obj);
|
||||
}
|
||||
|
||||
static internal void IsTrue(bool cond)
|
||||
{
|
||||
IsTrueHandler(cond);
|
||||
}
|
||||
}
|
||||
|
||||
internal static Action<object> IsNotNullHanlder;
|
||||
internal static Action<bool> IsTrueHandler;
|
||||
|
||||
protected void Init(Action<object> notNullHandler, Action<bool> trueHandler)
|
||||
{
|
||||
IsNotNullHanlder = notNullHandler;
|
||||
|
|
@ -71,14 +54,15 @@ namespace TLSharp.Tests
|
|||
}
|
||||
catch (MissingApiConfigurationException ex)
|
||||
{
|
||||
throw new Exception($"Please add your API settings to the `app.config` file. (More info: {MissingApiConfigurationException.InfoUrl})",
|
||||
ex);
|
||||
throw new Exception(
|
||||
$"Please add your API settings to the `app.config` file. (More info: {MissingApiConfigurationException.InfoUrl})",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void GatherTestConfiguration()
|
||||
{
|
||||
string appConfigMsgWarning = "{0} not configured in app.config! Some tests may fail.";
|
||||
var appConfigMsgWarning = "{0} not configured in app.config! Some tests may fail.";
|
||||
|
||||
ApiHash = ConfigurationManager.AppSettings[nameof(ApiHash)];
|
||||
if (string.IsNullOrEmpty(ApiHash))
|
||||
|
|
@ -128,10 +112,9 @@ namespace TLSharp.Tests
|
|||
var hash = await client.SendCodeRequestAsync(NumberToAuthenticate);
|
||||
var code = CodeToAuthenticate; // you can change code in debugger too
|
||||
|
||||
if (String.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
throw new Exception("CodeToAuthenticate is empty in the app.config file, fill it with the code you just got now by SMS/Telegram");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(code))
|
||||
throw new Exception(
|
||||
"CodeToAuthenticate is empty in the app.config file, fill it with the code you just got now by SMS/Telegram");
|
||||
|
||||
TLUser user = null;
|
||||
try
|
||||
|
|
@ -143,12 +126,13 @@ namespace TLSharp.Tests
|
|||
var password = await client.GetPasswordSetting();
|
||||
var password_str = PasswordToAuthenticate;
|
||||
|
||||
user = await client.MakeAuthWithPasswordAsync(password,password_str);
|
||||
user = await client.MakeAuthWithPasswordAsync(password, password_str);
|
||||
}
|
||||
catch (InvalidPhoneCodeException ex)
|
||||
{
|
||||
throw new Exception("CodeToAuthenticate is wrong in the app.config file, fill it with the code you just got now by SMS/Telegram",
|
||||
ex);
|
||||
throw new Exception(
|
||||
"CodeToAuthenticate is wrong in the app.config file, fill it with the code you just got now by SMS/Telegram",
|
||||
ex);
|
||||
}
|
||||
Assert.IsNotNull(user);
|
||||
Assert.IsTrue(client.IsUserAuthorized());
|
||||
|
|
@ -158,12 +142,13 @@ namespace TLSharp.Tests
|
|||
{
|
||||
NumberToSendMessage = ConfigurationManager.AppSettings[nameof(NumberToSendMessage)];
|
||||
if (string.IsNullOrWhiteSpace(NumberToSendMessage))
|
||||
throw new Exception($"Please fill the '{nameof(NumberToSendMessage)}' setting in app.config file first");
|
||||
throw new Exception(
|
||||
$"Please fill the '{nameof(NumberToSendMessage)}' setting in app.config file first");
|
||||
|
||||
// this is because the contacts in the address come without the "+" prefix
|
||||
var normalizedNumber = NumberToSendMessage.StartsWith("+") ?
|
||||
NumberToSendMessage.Substring(1, NumberToSendMessage.Length - 1) :
|
||||
NumberToSendMessage;
|
||||
var normalizedNumber = NumberToSendMessage.StartsWith("+")
|
||||
? NumberToSendMessage.Substring(1, NumberToSendMessage.Length - 1)
|
||||
: NumberToSendMessage;
|
||||
|
||||
var client = NewClient();
|
||||
|
||||
|
|
@ -176,13 +161,11 @@ namespace TLSharp.Tests
|
|||
.FirstOrDefault(x => x.phone == normalizedNumber);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
throw new System.Exception("Number was not found in Contacts List of user: " + NumberToSendMessage);
|
||||
}
|
||||
throw new Exception("Number was not found in Contacts List of user: " + NumberToSendMessage);
|
||||
|
||||
await client.SendTypingAsync(new TLInputPeerUser() { user_id = user.id });
|
||||
await client.SendTypingAsync(new TLInputPeerUser {user_id = user.id});
|
||||
Thread.Sleep(3000);
|
||||
await client.SendMessageAsync(new TLInputPeerUser() { user_id = user.id }, "TEST");
|
||||
await client.SendMessageAsync(new TLInputPeerUser {user_id = user.id}, "TEST");
|
||||
}
|
||||
|
||||
public virtual async Task SendMessageToChannelTest()
|
||||
|
|
@ -196,7 +179,8 @@ namespace TLSharp.Tests
|
|||
.OfType<TLChannel>()
|
||||
.FirstOrDefault(c => c.title == "TestGroup");
|
||||
|
||||
await client.SendMessageAsync(new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value }, "TEST MSG");
|
||||
await client.SendMessageAsync(
|
||||
new TLInputPeerChannel {channel_id = chat.id, access_hash = chat.access_hash.Value}, "TEST MSG");
|
||||
}
|
||||
|
||||
public virtual async Task SendPhotoToContactTest()
|
||||
|
|
@ -211,8 +195,8 @@ namespace TLSharp.Tests
|
|||
.OfType<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");
|
||||
var fileResult = (TLInputFile) await client.UploadFile("cat.jpg", new StreamReader("data/cat.jpg"));
|
||||
await client.SendUploadedPhoto(new TLInputPeerUser {user_id = user.id}, fileResult, "kitty");
|
||||
}
|
||||
|
||||
public virtual async Task SendBigFileToContactTest()
|
||||
|
|
@ -227,10 +211,11 @@ namespace TLSharp.Tests
|
|||
.OfType<TLUser>()
|
||||
.FirstOrDefault(x => x.phone == NumberToSendMessage);
|
||||
|
||||
var fileResult = (TLInputFileBig)await client.UploadFile("some.zip", new StreamReader("<some big file path>"));
|
||||
var fileResult =
|
||||
(TLInputFileBig) await client.UploadFile("some.zip", new StreamReader("<some big file path>"));
|
||||
|
||||
await client.SendUploadedDocument(
|
||||
new TLInputPeerUser() { user_id = user.id },
|
||||
new TLInputPeerUser {user_id = user.id},
|
||||
fileResult,
|
||||
"some zips",
|
||||
"application/zip",
|
||||
|
|
@ -249,8 +234,8 @@ namespace TLSharp.Tests
|
|||
.OfType<TLUser>()
|
||||
.FirstOrDefault(x => x.phone == NumberToSendMessage);
|
||||
|
||||
var inputPeer = new TLInputPeerUser() { user_id = user.id };
|
||||
var res = await client.SendRequestAsync<TLMessagesSlice>(new TLRequestGetHistory() { peer = inputPeer });
|
||||
var inputPeer = new TLInputPeerUser {user_id = user.id};
|
||||
var res = await client.SendRequestAsync<TLMessagesSlice>(new TLRequestGetHistory {peer = inputPeer});
|
||||
var document = res.messages.lists
|
||||
.OfType<TLMessage>()
|
||||
.Where(m => m.media != null)
|
||||
|
|
@ -261,14 +246,14 @@ namespace TLSharp.Tests
|
|||
.First();
|
||||
|
||||
var resFile = await client.GetFile(
|
||||
new TLInputDocumentFileLocation()
|
||||
new TLInputDocumentFileLocation
|
||||
{
|
||||
access_hash = document.access_hash,
|
||||
id = document.id,
|
||||
version = document.version
|
||||
},
|
||||
document.size);
|
||||
|
||||
|
||||
Assert.IsTrue(resFile.bytes.Length > 0);
|
||||
}
|
||||
|
||||
|
|
@ -283,18 +268,18 @@ namespace TLSharp.Tests
|
|||
var user = result.users.lists
|
||||
.OfType<TLUser>()
|
||||
.FirstOrDefault(x => x.id == 5880094);
|
||||
|
||||
var photo = ((TLUserProfilePhoto)user.photo);
|
||||
|
||||
var photo = (TLUserProfilePhoto) user.photo;
|
||||
var photoLocation = (TLFileLocation) photo.photo_big;
|
||||
|
||||
var resFile = await client.GetFile(new TLInputFileLocation()
|
||||
var resFile = await client.GetFile(new TLInputFileLocation
|
||||
{
|
||||
local_id = photoLocation.local_id,
|
||||
secret = photoLocation.secret,
|
||||
volume_id = photoLocation.volume_id
|
||||
}, 1024);
|
||||
|
||||
var res = await client.GetUserDialogsAsync();
|
||||
var res = await client.GetUserDialogsAsync();
|
||||
|
||||
Assert.IsTrue(resFile.bytes.Length > 0);
|
||||
}
|
||||
|
|
@ -326,8 +311,7 @@ namespace TLSharp.Tests
|
|||
|
||||
public virtual async Task FloodExceptionShouldNotCauseCannotReadPackageLengthError()
|
||||
{
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
for (var i = 0; i < 50; i++)
|
||||
try
|
||||
{
|
||||
await CheckPhones();
|
||||
|
|
@ -337,14 +321,14 @@ namespace TLSharp.Tests
|
|||
Console.WriteLine($"FLOODEXCEPTION: {floodException}");
|
||||
Thread.Sleep(floodException.TimeToWait);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task SendMessageByUserNameTest()
|
||||
{
|
||||
UserNameToSendMessage = ConfigurationManager.AppSettings[nameof(UserNameToSendMessage)];
|
||||
if (string.IsNullOrWhiteSpace(UserNameToSendMessage))
|
||||
throw new Exception($"Please fill the '{nameof(UserNameToSendMessage)}' setting in app.config file first");
|
||||
throw new Exception(
|
||||
$"Please fill the '{nameof(UserNameToSendMessage)}' setting in app.config file first");
|
||||
|
||||
var client = NewClient();
|
||||
|
||||
|
|
@ -368,13 +352,24 @@ namespace TLSharp.Tests
|
|||
}
|
||||
|
||||
if (user == null)
|
||||
throw new Exception("Username was not found: " + UserNameToSendMessage);
|
||||
|
||||
await client.SendTypingAsync(new TLInputPeerUser {user_id = user.id});
|
||||
Thread.Sleep(3000);
|
||||
await client.SendMessageAsync(new TLInputPeerUser {user_id = user.id}, "TEST");
|
||||
}
|
||||
|
||||
private class Assert
|
||||
{
|
||||
internal static void IsNotNull(object obj)
|
||||
{
|
||||
throw new System.Exception("Username was not found: " + UserNameToSendMessage);
|
||||
IsNotNullHanlder(obj);
|
||||
}
|
||||
|
||||
await client.SendTypingAsync(new TLInputPeerUser() { user_id = user.id });
|
||||
Thread.Sleep(3000);
|
||||
await client.SendMessageAsync(new TLInputPeerUser() { user_id = user.id }, "TEST");
|
||||
internal static void IsTrue(bool cond)
|
||||
{
|
||||
IsTrueHandler(cond);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="ApiHash" value="" />
|
||||
<add key="ApiId" value="" />
|
||||
<add key="NumberToAuthenticate" value="" />
|
||||
<add key="CodeToAuthenticate" value="" />
|
||||
<add key="PasswordToAuthenticate" value=""/>
|
||||
<add key="NotRegisteredNumberToSignUp" value=""/>
|
||||
<add key="NumberToSendMessage" value=""/>
|
||||
<add key="UserNameToSendMessage" value=""/>
|
||||
<add key="NumberToGetUserFull" value=""/>
|
||||
<add key="NumberToAddToChat" value=""/>
|
||||
<add key="PasswordToAuthenticate" value="" />
|
||||
<add key="NotRegisteredNumberToSignUp" value="" />
|
||||
<add key="NumberToSendMessage" value="" />
|
||||
<add key="UserNameToSendMessage" value="" />
|
||||
<add key="NumberToGetUserFull" value="" />
|
||||
<add key="NumberToAddToChat" value="" />
|
||||
</appSettings>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
</packages>
|
||||
Loading…
Add table
Add a link
Reference in a new issue