Skip to content

Commit

Permalink
Items - DeactivateTwice
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Dec 12, 2018
1 parent fdb067b commit 641d234
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/src/Items.cs
Expand Up @@ -33,7 +33,13 @@ public void Activate()

public void Deactivate()
{
if (this.sub == null)
{
throw new InvalidOperationException("Cannot Deactivate before Activate.");
}

this.sub.Dispose();
this.sub = null;
}

public void Look()
Expand Down
13 changes: 13 additions & 0 deletions core/test/ItemsTest.cs
Expand Up @@ -202,6 +202,19 @@ public void ActivateTwice()
act.Should().Throw<InvalidOperationException>().WithMessage("Cannot Activate again.");
}

[Fact]
public void DeactivateTwice()
{
MessageBus bus = new MessageBus();
Items items = new Items(bus);

items.Activate();
items.Deactivate();
Action act = () => items.Deactivate();

act.Should().Throw<InvalidOperationException>().WithMessage("Cannot Deactivate before Activate.");
}

private sealed class TestItemNoActions : Item
{
public override string ShortDescription => "a dull item";
Expand Down

0 comments on commit 641d234

Please sign in to comment.