Skip to content

Commit

Permalink
Fix tests to not use obsolete code and therefore show warnings in con…
Browse files Browse the repository at this point in the history
…sole (#68)
  • Loading branch information
sierpinskid authored Oct 21, 2022
1 parent 52c6767 commit 1e9162b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public void TearDown()
Debug.Log("------------ TearDown");

DeleteTempChannels();

Client.Dispose();
Client = null;
TryCleanupClient();
}

// StreamTodo: replace with admin ids fetched from loaded data set
Expand All @@ -48,6 +46,7 @@ public void TearDown()
protected const string TestGuestId = TestUtils.TestGuestId;

protected IStreamChatClient Client { get; private set; }
protected OwnUser InitialLocalUser;

/// <summary>
/// Id of other user than currently logged one
Expand Down Expand Up @@ -151,7 +150,7 @@ public static async Task<Texture2D> DownloadTextureAsync(string url)
await Task.Delay(1);
}

if (www.isNetworkError || www.isHttpError)
if (www.error != null)
{
Debug.LogError($"{www.error}, URL:{www.url}");
return null;
Expand Down Expand Up @@ -201,13 +200,31 @@ private void InitClientAndConnect(string forcedAdminId = null)
OtherUserId = otherUserAuthCredentials.UserId;

Client = StreamChatClient.CreateDefaultClient(adminAuthCredentials);
Client.Connected += OnClientConnected;
Client.Connect();
}

private void TryCleanupClient()
{
if (Client == null)
{
return;
}

Client.Connected -= OnClientConnected;
Client.Dispose();
Client = null;
}

private void OnClientConnected(OwnUser localUser)
{
InitialLocalUser = localUser;
}

protected IEnumerator ReconnectClient()
{
var userId = Client.UserId;
Client.Dispose();
TryCleanupClient();
InitClientAndConnect(userId);

yield return Client.WaitForClientToConnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,9 @@ public IEnumerator Mark_many_read_with_specified_message_id()
yield return ReconnectClient();

//Should use Assert.AreEqual but there seems to be some delay with updating the values
Assert.GreaterOrEqual(Client.LocalUser.UnreadChannels, 2);
Assert.GreaterOrEqual(Client.LocalUser.TotalUnreadCount, 3);
Assert.IsNotNull(InitialLocalUser);
Assert.GreaterOrEqual(InitialLocalUser.UnreadChannels, 2);
Assert.GreaterOrEqual(InitialLocalUser.TotalUnreadCount, 3);
}

[UnityTest]
Expand Down

0 comments on commit 1e9162b

Please sign in to comment.