Permalink
Browse files

TextConsole - add CancellationToken to Run

  • Loading branch information...
bobbymcr committed Nov 30, 2018
1 parent 1c33709 commit 558f97edf9a6f1ed6757352ba0172466454c49e9
Showing with 8 additions and 5 deletions.
  1. +2 −1 core/src/TextConsole.cs
  2. +4 −3 core/test/TextConsoleTest.cs
  3. +2 −1 sample/src/Game.cs
@@ -5,6 +5,7 @@
namespace Adventure
{
using System.IO;
using System.Threading;

public sealed class TextConsole
{
@@ -19,7 +20,7 @@ public TextConsole(MessageBus bus, TextReader reader, TextWriter writer)
this.writer = writer;
}

public void Run()
public void Run(CancellationToken token)
{
using (this.bus.Subscribe<OutputMessage>(m => this.writer.WriteLine(m.Text)))
{
@@ -7,6 +7,7 @@ namespace Adventure.Test
using System;
using System.IO;
using System.Text;
using System.Threading;
using FluentAssertions;
using Xunit;

@@ -17,7 +18,7 @@ public void RunNoInput()
{
TextConsole con = new TextConsole(new MessageBus(), TextReader.Null, TextWriter.Null);

Action act = () => con.Run();
Action act = () => con.Run(CancellationToken.None);

act.Should().NotThrow();
}
@@ -31,7 +32,7 @@ public void ReadsOneInputProducesOneOutput()
bus.Subscribe<InputMessage>(m => bus.Send(new OutputMessage($"I saw '{m.Line}'")));
TextConsole con = new TextConsole(bus, new StringReader("one line"), writer);

con.Run();
con.Run(CancellationToken.None);

output.ToString().Should().Be("I saw 'one line'\r\n");
}
@@ -44,7 +45,7 @@ public void ProducesNoOutputAfterRun()
StringWriter writer = new StringWriter(output);
TextConsole con = new TextConsole(bus, TextReader.Null, writer);

con.Run();
con.Run(CancellationToken.None);
bus.Send(new OutputMessage("do not print this"));

output.ToString().Should().BeEmpty();
@@ -5,6 +5,7 @@
namespace Adventure.Sample
{
using System.IO;
using System.Threading;

public sealed class Game
{
@@ -22,7 +23,7 @@ public void Run()
using (new SentenceParser(this.bus))
using (this.bus.Subscribe<SentenceMessage>(m => this.ProcessVerb(m.Verb)))
{
this.console.Run();
this.console.Run(CancellationToken.None);
}
}

0 comments on commit 558f97e

Please sign in to comment.