Skip to content
Permalink
Browse files

Inventory - ProcessLookItem

  • Loading branch information...
bobbymcr committed Dec 15, 2018
1 parent 22c8636 commit 826246c7f68e986d89c806f5de0850c9e754cd43
Showing with 25 additions and 1 deletion.
  1. +7 −0 core/src/Inventory.cs
  2. +18 −1 core/test/InventoryTest.cs
@@ -12,6 +12,7 @@ public sealed class Inventory : IDisposable
private readonly IDisposable show;
private readonly IDisposable add;
private readonly IDisposable drop;
private readonly IDisposable look;
private readonly Items items;

public Inventory(MessageBus bus)
@@ -20,6 +21,7 @@ public Inventory(MessageBus bus)
this.show = bus.Subscribe<InventoryRequestedMessage>(m => this.Show());
this.add = bus.Subscribe<InventoryAddedMessage>(m => this.Add(m.Verb, m.Noun, m.Item));
this.drop = bus.Subscribe<InventoryDropMessage>(m => this.Drop(m.Verb, m.Noun, m.Items));
this.look = bus.Subscribe<LookItemMessage>(m => this.Look(m.Noun));
this.items = new Items(this.bus);
this.items.Activate();
}
@@ -72,6 +74,11 @@ private void Drop(Word verb, Word noun, Items targetItems)
this.items.Add(noun.Primary, item);
}

private bool Look(Word noun)
{
return this.items.LookAt(noun);
}

private void Output(string text)
{
this.bus.Send(new OutputMessage(text));
@@ -109,6 +109,23 @@ public void ProcessCustomItemActionAfterDispose()
lastOutput.Should().BeNull();
}

[Fact]
public void ProcessLookItem()
{
MessageBus bus = new MessageBus();
string lastOutput = null;
bus.Subscribe<OutputMessage>(m => lastOutput = m.Text);
using (Inventory inv = new Inventory(bus))
{
inv.Add("key", new TestItem());
inv.Add("coin", new TestItem2());

bus.Send(new LookItemMessage(new Word("key", "KEY")));

lastOutput.Should().Be("It's a test key.");
}
}

[Fact]
public void DropAllowedItem()
{
@@ -218,7 +235,7 @@ public TestItem(bool canDrop = true)

public override string ShortDescription => "a key";

public override string LongDescription => throw new System.NotImplementedException();
public override string LongDescription => "It's a test key.";

protected override bool DropCore(MessageBus bus)
{

0 comments on commit 826246c

Please sign in to comment.
You can’t perform that action at this time.