microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps.Testing/Plugins/TestPlugin.Stream.cs
59lines · modecode
| 1 | |
| 2 | using Microsoft.Teams.Api.Activities; |
| 3 | using Microsoft.Teams.Api.Entities; |
| 4 | using Microsoft.Teams.Apps.Plugins; |
| 5 | |
| 6 | namespace Microsoft.Teams.Apps.Testing.Plugins; |
| 7 | |
| 8 | public partial class TestPlugin |
| 9 | { |
| 10 | /// <summary> |
| 11 | /// a test implementation of an IStreamer |
| 12 | /// </summary> |
| 13 | public class Stream : IStreamer |
| 14 | { |
| 15 | public bool Closed { get; internal set; } |
| 16 | public int Count { get; internal set; } |
| 17 | public int Sequence { get; internal set; } |
| 18 | |
| 19 | public event IStreamer.OnChunkHandler OnChunk; |
| 20 | |
| 21 | protected MessageActivity? _activity; |
| 22 | |
| 23 | public void Emit(MessageActivity activity) |
| 24 | { |
| 25 | if (_activity is null) |
| 26 | { |
| 27 | _activity = activity; |
| 28 | } |
| 29 | |
| 30 | _activity.Merge(activity); |
| 31 | } |
| 32 | |
| 33 | public void Emit(TypingActivity activity) |
| 34 | { |
| 35 | if (_activity is null) return; |
| 36 | _activity.Merge(activity); |
| 37 | } |
| 38 | |
| 39 | public void Emit(string text) |
| 40 | { |
| 41 | Emit(new MessageActivity(text)); |
| 42 | } |
| 43 | |
| 44 | public void Update(string text) |
| 45 | { |
| 46 | Emit(new TypingActivity(text) { |
| 47 | ChannelData = new() { |
| 48 | StreamType = StreamType.Informative |
| 49 | } |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | public Task<MessageActivity?> Close() |
| 54 | { |
| 55 | Closed = true; |
| 56 | return Task.FromResult(_activity); |
| 57 | } |
| 58 | } |
| 59 | } |