fix null lookup bug in message manager
parent
a2171e9915
commit
fde3cfe9e3
|
@ -28,7 +28,9 @@ namespace Encompass
|
||||||
|
|
||||||
internal IEnumerable<TMessage> GetMessagesByType<TMessage>() where TMessage : struct, IMessage
|
internal IEnumerable<TMessage> GetMessagesByType<TMessage>() where TMessage : struct, IMessage
|
||||||
{
|
{
|
||||||
return messageTypeToMessages[typeof(TMessage)].Cast<TMessage>();
|
return messageTypeToMessages.ContainsKey(typeof(TMessage)) ?
|
||||||
|
messageTypeToMessages[typeof(TMessage)].Cast<TMessage>() :
|
||||||
|
Enumerable.Empty<TMessage>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,6 +227,29 @@ namespace Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static IEnumerable<MockMessage> emptyReadMessagesResult;
|
||||||
|
[Reads(typeof(MockMessage))]
|
||||||
|
class ReadMessagesWhenNoneExistEngine : Engine
|
||||||
|
{
|
||||||
|
public override void Update(float dt)
|
||||||
|
{
|
||||||
|
emptyReadMessagesResult = ReadMessages<MockMessage>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ReadMessagesWhenNoneHaveBeenEmitted()
|
||||||
|
{
|
||||||
|
var worldBuilder = new WorldBuilder();
|
||||||
|
worldBuilder.AddEngine<ReadMessagesWhenNoneExistEngine>();
|
||||||
|
|
||||||
|
var world = worldBuilder.Build();
|
||||||
|
|
||||||
|
world.Update(0.01f);
|
||||||
|
|
||||||
|
emptyReadMessagesResult.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void EmitUndeclaredMessage()
|
public void EmitUndeclaredMessage()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue