Permalink
Browse files

SentenceParser - SendOneWord

  • Loading branch information...
bobbymcr committed Nov 29, 2018
1 parent 67dae8a commit b442c02ee6bfb8ed29d2d39468ac891ffca52ca6
Showing with 68 additions and 0 deletions.
  1. +18 −0 core/src/SentenceMessage.cs
  2. +22 −0 core/src/SentenceParser.cs
  3. +28 −0 core/test/SentenceParserTest.cs
@@ -0,0 +1,18 @@
// <copyright file="SentenceMessage.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Adventure
{
public sealed class SentenceMessage
{
private readonly string line;

public SentenceMessage(string line)
{
this.line = line;
}

public override string ToString() => this.line;
}
}
@@ -0,0 +1,22 @@
// <copyright file="SentenceParser.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Adventure
{
public sealed class SentenceParser
{
private readonly MessageBus bus;

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

private void ProcessInput(string line)
{
this.bus.Send(new SentenceMessage(line));
}
}
}
@@ -0,0 +1,28 @@
// <copyright file="SentenceParserTest.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Adventure.Test
{
using System;
using System.Collections.Generic;
using FluentAssertions;
using Xunit;

public class SentenceParserTest
{
[Fact]
public void SendOneWord()
{
MessageBus bus = new MessageBus();
List<string> sentences = new List<string>();
Action<SentenceMessage> onSentence = m => sentences.Add(m.ToString());
bus.Subscribe(onSentence);
SentenceParser parser = new SentenceParser(bus);

bus.Send(new InputMessage("one"));

sentences.Should().ContainSingle().Which.Should().Be("one");
}
}
}

0 comments on commit b442c02

Please sign in to comment.