Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: load NumberToSendMessage in init process #45

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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