public async Task CanShutdown() { var notifier = new FakeNotifier(); using var subject = CreateSubject(); var pipe = new System.IO.Pipelines.Pipe(); await subject.InitializeAsync(notifier, pipe.Reader.AsStream()); await subject.ShutdownAsync(); }
public async Task CanInitialize() { var notifier = new FakeNotifier(); var fakeIrcMiddleware = new FakeIrcMiddleware <TwitchChatConnectionParameters>(); using var subject = new ReconnectMiddleware(fakeIrcMiddleware); var result = await subject.InitializeAsync(notifier, new TwitchChatConnectionParameters("example.com", 6667, false, "bob", "bob")); result.ShouldBeTrue(); fakeIrcMiddleware.InitializeCount.ShouldBe(1); }
public async Task WriteLoop() { var notifier = new FakeNotifier(); using var subject = CreateSubject(); var pipe = new System.IO.Pipelines.Pipe(); await subject.InitializeAsync(notifier, pipe.Writer.AsStream()); await subject.WriteMessageAsync(new IrcMessage("TEST")); using var reader = new StreamReader(pipe.Reader.AsStream()); var s = await reader.ReadLineAsync(); s.ShouldBe("TEST"); notifier.ExceptionList.Count.ShouldBe(0); }
public async Task WillAttemptReconnect() { var notifier = new FakeNotifier(); var fakeIrcMiddleware = new FakeIrcMiddleware <TwitchChatConnectionParameters>(); using var subject = new ReconnectMiddleware(fakeIrcMiddleware); var result = await subject.InitializeAsync(notifier, new TwitchChatConnectionParameters("example.com", 6667, false, "bob", "bob")); fakeIrcMiddleware.RegisterWaitForInitialize(); await subject.HandleErrorAsync(new IOException("Test error", new SocketException((int)SocketError.ConnectionAborted))); fakeIrcMiddleware.WaitForInitialize(TimeSpan.FromSeconds(1)); fakeIrcMiddleware.ShutdownCount.ShouldBe(1); fakeIrcMiddleware.InitializeCount.ShouldBe(2); }
public async Task CanReadMessage() { var notifier = new FakeNotifier(); using var subject = CreateSubject(); var pipe = new System.IO.Pipelines.Pipe(); await subject.InitializeAsync(notifier, pipe.Reader.AsStream()); await pipe.Writer.WriteAsync(new Memory <byte>(Encoding.UTF8.GetBytes(":tmi.twitch.tv 001 drangrybot :Welcome, GLHF!\r\n"))); var message = notifier.WaitForMessages(1).First(); message.Command.ShouldBe("001"); message.Parameters.Count.ShouldBe(2); message.Parameters[0].ShouldBe("drangrybot"); message.Parameters[1].ShouldBe("Welcome, GLHF!"); notifier.ExceptionList.Count.ShouldBe(0); }