From 738a84937e6d9edb56727ee36ad6344aae5f1b86 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Thu, 3 Nov 2016 01:31:47 +0800 Subject: [PATCH 1/2] SendMessageTest: rather crash with meaningful exception Rather crash with meaningful exception than not passing the test and only giving a hint when debugging. --- TLSharp.Tests/TLSharpTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 8e6a604..2d93942 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -84,10 +84,6 @@ namespace TLSharp.Tests if (string.IsNullOrEmpty(NotRegisteredNumberToSignUp)) Debug.WriteLine(appConfigMsgWarning, nameof(NotRegisteredNumberToSignUp)); - NumberToSendMessage = ConfigurationManager.AppSettings[nameof(NumberToSendMessage)]; - if (string.IsNullOrEmpty(NumberToSendMessage)) - Debug.WriteLine(appConfigMsgWarning, nameof(NumberToSendMessage)); - UserNameToSendMessage = ConfigurationManager.AppSettings[nameof(UserNameToSendMessage)]; if (string.IsNullOrEmpty(UserNameToSendMessage)) Debug.WriteLine(appConfigMsgWarning, nameof(UserNameToSendMessage)); @@ -134,6 +130,10 @@ namespace TLSharp.Tests [TestMethod] public async Task SendMessageTest() { + NumberToSendMessage = ConfigurationManager.AppSettings[nameof(NumberToSendMessage)]; + if (string.IsNullOrWhiteSpace(NumberToSendMessage)) + throw new Exception($"Please fill the '{nameof(NumberToSendMessage)}' setting in app.config file first"); + var client = NewClient(); await client.ConnectAsync(); From adef68b7475014393424ea2f13e88bec4b373690 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Thu, 3 Nov 2016 01:33:56 +0800 Subject: [PATCH 2/2] SendNumberTest: remove the + from the phone number in app.config NumberToAuthenticate works fine for the AuthTest if we put a "+" before our international prefix when writing the number, but because this test compares the numbers we got from the Contacts List with the one in app.config, it could not find it due to this prefix. Let's rather be prepared for that. --- TLSharp.Tests/TLSharpTests.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 2d93942..3f7b594 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -134,6 +134,11 @@ namespace TLSharp.Tests if (string.IsNullOrWhiteSpace(NumberToSendMessage)) 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 client = NewClient(); await client.ConnectAsync(); @@ -143,7 +148,7 @@ namespace TLSharp.Tests var user = result.users.lists .Where(x => x.GetType() == typeof(TLUser)) .Cast() - .FirstOrDefault(x => x.phone == NumberToSendMessage); + .FirstOrDefault(x => x.phone == normalizedNumber); if (user == null) { @@ -153,7 +158,6 @@ namespace TLSharp.Tests await client.SendTypingAsync(new TLInputPeerUser() { user_id = user.id }); Thread.Sleep(3000); await client.SendMessageAsync(new TLInputPeerUser() { user_id = user.id }, "TEST"); - } [TestMethod]