Skip to content
Permalink
Browse files

Inventory - ProcessInventoryAction

  • Loading branch information...
bobbymcr committed Dec 22, 2018
1 parent f5e3892 commit 135168b4b48992096688c94d2ff18ddd2dbcdbeb
Showing with 35 additions and 0 deletions.
  1. +2 −0 core/src/Inventory.cs
  2. +18 −0 core/src/Messages/InventoryActionMessage.cs
  3. +15 −0 core/test/InventoryTest.cs
@@ -14,6 +14,7 @@ public sealed class Inventory : IDisposable
private readonly IDisposable take;
private readonly IDisposable drop;
private readonly IDisposable look;
private readonly IDisposable act;
private readonly Items items;

public Inventory(MessageBus bus)
@@ -23,6 +24,7 @@ public Inventory(MessageBus bus)
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.act = bus.Subscribe<InventoryActionMessage>(m => m.Act(this));
this.items = new Items(this.bus);
this.items.Activate();
}
@@ -0,0 +1,18 @@
// <copyright file="InventoryActionMessage.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Adventure.Messages
{
using System;

public sealed class InventoryActionMessage
{
public InventoryActionMessage(Action<Inventory> act)
{
this.Act = act;
}

public Action<Inventory> Act { get; }
}
}
@@ -301,6 +301,21 @@ public void RemoveMissingItem()
}
}

[Fact]
public void ProcessInventoryAction()
{
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 InventoryActionMessage(i => i.Add("key", new TestItem(bus))));
bus.Send(new ShowInventoryMessage());

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

private sealed class TestItem : Item
{
private readonly bool canDrop;

0 comments on commit 135168b

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