Skip to content

Commit

Permalink
Tests: load NumberToSendMessage in init process
Browse files Browse the repository at this point in the history
738a849 moves loading process for NumberToSendMessage into
SendMessage test even though there are 3 other tests that use
that variable thereby breaking all 3 tests because of
NumberToSendMessage being null.

This commit moves the load process back to init phase so
all 4 tests can use NumberToSendMessage.
  • Loading branch information
aarani committed May 13, 2021
1 parent 99aa273 commit 43a1e0d
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/TgSharp.Tests/TgSharpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ private void GatherTestConfiguration()
NumberToAddToChat = ConfigurationManager.AppSettings[nameof(NumberToAddToChat)];
if (string.IsNullOrEmpty(NumberToAddToChat))
Debug.WriteLine(appConfigMsgWarning, nameof(NumberToAddToChat));

NumberToSendMessage = ConfigurationManager.AppSettings[nameof(NumberToSendMessage)];
if (string.IsNullOrWhiteSpace(NumberToSendMessage))
Debug.WriteLine(appConfigMsgWarning, nameof(NumberToSendMessage));
else
NumberToSendMessage =
NumberToSendMessage.StartsWith("+") ?
NumberToSendMessage.Substring(1, NumberToSendMessage.Length - 1) :
NumberToSendMessage;

}

public virtual async Task AuthUser()
Expand Down Expand Up @@ -150,15 +160,6 @@ public virtual async Task AuthUser()

public virtual 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");

// 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();
Expand All @@ -167,7 +168,7 @@ public virtual async Task SendMessageTest()

var user = result.Users
.OfType<TLUser>()
.FirstOrDefault(x => x.Phone == normalizedNumber);
.FirstOrDefault(x => x.Phone == NumberToSendMessage);

if (user == null)
{
Expand Down

0 comments on commit 43a1e0d

Please sign in to comment.