Permalink
Browse files

SentenceParser - SendAfterDispose

  • Loading branch information...
bobbymcr committed Nov 29, 2018
1 parent fa65398 commit 6977bc7b3eae35d25beb7192a62245fa8b830aca
Showing with 25 additions and 2 deletions.
  1. +10 −2 core/src/SentenceParser.cs
  2. +15 −0 core/test/SentenceParserTest.cs
@@ -4,14 +4,22 @@

namespace Adventure
{
public sealed class SentenceParser
using System;

public sealed class SentenceParser : IDisposable
{
private readonly MessageBus bus;
private readonly IDisposable subscription;

public SentenceParser(MessageBus bus)
{
this.bus = bus;
this.bus.Subscribe<InputMessage>(m => this.ProcessInput(m.Line));
this.subscription = this.bus.Subscribe<InputMessage>(m => this.ProcessInput(m.Line));
}

public void Dispose()
{
this.subscription.Dispose();
}

private void ProcessInput(string line)
@@ -31,5 +31,20 @@ public void SendWords(string input, string output)

sentences.Should().ContainSingle().Which.Should().Be(output);
}

[Fact]
public void SendAfterDispose()
{
MessageBus bus = new MessageBus();
List<string> sentences = new List<string>();
Action<SentenceMessage> onSentence = m => sentences.Add(m.Verb + ":" + m.Noun);
bus.Subscribe(onSentence);
SentenceParser parser = new SentenceParser(bus);

parser.Dispose();
bus.Send(new InputMessage("hello"));

sentences.Should().BeEmpty();
}
}
}

0 comments on commit 6977bc7

Please sign in to comment.