public ChannelAdminBotTestFixture(TestsFixture fixture) { AddLifetime( initialize: async() => { _channelChatFixture = new(fixture, Constants.TestCollections.ChannelAdminBots); await _channelChatFixture.InitializeAsync(); // Save existing chat photo as byte[] to restore it later because Bot API 4.4+ invalidates old // file_ids after changing chat photo if (!string.IsNullOrEmpty(Chat.Photo?.BigFileId)) { await using MemoryStream stream = new(); await fixture.BotClient.GetInfoAndDownloadFileAsync(Chat.Photo.BigFileId, stream); _oldChatPhoto = stream.ToArray(); } }, dispose: async() => { // If chat had a photo before, reset the photo back. if (_oldChatPhoto is not null) { await using MemoryStream photoStream = new(_oldChatPhoto); await fixture.BotClient.SetChatPhotoAsync( chatId: Chat.Id, photo: photoStream ); } await _channelChatFixture.DisposeAsync(); } ); }
public async Task InitializeAsync() { ChannelChatFixture channelFixture = new ChannelChatFixture( _fixture, Constants.TestCollections.BadRequestException ); await channelFixture.InitializeAsync(); Chat = channelFixture.ChannelChat; // Save existing chat photo as byte[] to restore it later because Bot API 4.4+ invalidates old // file_ids after changing chat photo if (!string.IsNullOrEmpty(Chat.Photo?.BigFileId)) { await using MemoryStream stream = new MemoryStream(); await _fixture.BotClient .GetInfoAndDownloadFileAsync(Chat.Photo.BigFileId, stream); _oldChatPhoto = stream.ToArray(); await _fixture.BotClient.DeleteChatPhotoAsync(Chat); } }
public Fixture(TestsFixture fixture) { ChatId = new ChannelChatFixture(fixture, Constants.TestCollections.ChannelAdminBots).ChannelChatId; }
public ChannelAdminBotTestFixture(TestsFixture fixture) { _fixture = fixture; Chat = new ChannelChatFixture(fixture, Constants.TestCollections.ChannelAdminBots).ChannelChat; }