Skip to content
Permalink
Browse files

InventoryAddedMessage -> TakeItemMessage

  • Loading branch information...
bobbymcr committed Dec 15, 2018
1 parent f8d3047 commit e751e7a4485e9ada6cf4b7e4d9601878975428d8
@@ -10,7 +10,7 @@ public sealed class Inventory : IDisposable
{
private readonly MessageBus bus;
private readonly IDisposable show;
private readonly IDisposable add;
private readonly IDisposable take;
private readonly IDisposable drop;
private readonly IDisposable look;
private readonly Items items;
@@ -19,7 +19,7 @@ public Inventory(MessageBus bus)
{
this.bus = bus;
this.show = bus.Subscribe<InventoryRequestedMessage>(m => this.Show());
this.add = bus.Subscribe<InventoryAddedMessage>(m => this.Add(m.Verb, m.Noun, m.Item));
this.take = bus.Subscribe<TakeItemMessage>(m => this.Take(m.Verb, m.Noun, m.Item));
this.drop = bus.Subscribe<DropItemMessage>(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);
@@ -30,7 +30,7 @@ public void Dispose()
{
this.items.Deactivate();
this.show.Dispose();
this.add.Dispose();
this.take.Dispose();
this.drop.Dispose();
this.look.Dispose();
}
@@ -50,7 +50,7 @@ private void Show()
}
}

private void Add(Word verb, Word noun, Item item)
private void Take(Word verb, Word noun, Item item)
{
this.Add(noun.Primary, item);
this.Output($"You {verb} the {noun}.");
@@ -143,7 +143,7 @@ private void TakeItem(Word verb, Word noun)
return;
}

this.bus.Send(new InventoryAddedMessage(verb, noun, taken));
this.bus.Send(new TakeItemMessage(verb, noun, taken));
}

private void Process(SentenceMessage message)
@@ -1,12 +1,12 @@
// <copyright file="InventoryAddedMessage.cs" company="Brian Rogers">
// <copyright file="TakeItemMessage.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Adventure
{
public sealed class InventoryAddedMessage
public sealed class TakeItemMessage
{
public InventoryAddedMessage(Word verb, Word noun, Item item)
public TakeItemMessage(Word verb, Word noun, Item item)
{
this.Verb = verb;
this.Noun = noun;
@@ -234,29 +234,29 @@ public void DropItemAfterDispose()
}

[Fact]
public void AddInventory()
public void TakeItem()
{
MessageBus bus = new MessageBus();
List<string> messages = new List<string>();
bus.Subscribe<OutputMessage>(m => messages.Add(m.Text));
using (Inventory inv = new Inventory(bus))
{
bus.Send(new InventoryAddedMessage(new Word("take", "GRAB"), new Word("key", "KEY"), new TestItem()));
bus.Send(new TakeItemMessage(new Word("take", "GRAB"), new Word("key", "KEY"), new TestItem()));
bus.Send(new InventoryRequestedMessage());

messages.Should().Equal("You GRAB the KEY.", "You are carrying:", "a key");
}
}

[Fact]
public void AddInventoryAfterDispose()
public void TakeItemAfterDispose()
{
MessageBus bus = new MessageBus();
List<string> messages = new List<string>();
bus.Subscribe<OutputMessage>(m => messages.Add(m.Text));
Inventory inv = new Inventory(bus);
inv.Dispose();
bus.Send(new InventoryAddedMessage(new Word("take", "GRAB"), new Word("key", "KEY"), new TestItem()));
bus.Send(new TakeItemMessage(new Word("take", "GRAB"), new Word("key", "KEY"), new TestItem()));

messages.Should().BeEmpty();
}
@@ -220,7 +220,7 @@ public void ProcessTakeAvailableItem()
List<string> messages = new List<string>();
bus.Subscribe<OutputMessage>(m => messages.Add(m.Text));
Item actualItem = null;
bus.Subscribe<InventoryAddedMessage>(m =>
bus.Subscribe<TakeItemMessage>(m =>
{
messages.Add($"You {m.Verb} the {m.Noun}!");
actualItem = m.Item;
@@ -251,7 +251,7 @@ public void ProcessTakeUnavailableItem()
List<string> messages = new List<string>();
bus.Subscribe<OutputMessage>(m => messages.Add(m.Text));
Item actualItem = null;
bus.Subscribe<InventoryAddedMessage>(m =>
bus.Subscribe<TakeItemMessage>(m =>
{
messages.Add($"You {m.Verb} the {m.Noun}!");
actualItem = m.Item;

0 comments on commit e751e7a

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