public void GameParametersHandlerOnlyHandlesGameParameterActions() { var cbk = Substitute.For <Action <JSONObject> >(); var uut = new GameParametersHandler(cbk); var t1 = Substitute.For <EventTrigger>(); t1.GetAction().Returns("imageMessage"); Expect(uut.Type(), Is.EqualTo("gameParameters")); Expect(uut.Handle(t1, store), Is.False); cbk.DidNotReceive().Invoke(Arg.Any <JSONObject>()); var t2 = Substitute.For <EventTrigger>(); t2.GetAction().Returns("gameParameters"); t2.GetResponse().Returns("{\"parameters\":{\"a\":1}}".Json()); Expect(uut.Handle(t2, store)); cbk.Received().Invoke(Arg.Is <JSONObject>(e => e.Json() == "{\"a\":1}")); var t3 = Substitute.For <EventTrigger>(); t3.GetAction().Returns("gameParameters"); t3.GetResponse().Returns("{}".Json()); Expect(uut.Handle(t3, store)); cbk.Received().Invoke(Arg.Is <JSONObject>(e => e.Json() == "{}")); }
public void GameParametersHandlerUsesPersistentActionAndRemovesIt() { var cbk = Substitute.For <Action <JSONObject> >(); var uut = new GameParametersHandler(cbk); var trigger = Substitute.For <EventTrigger>(); trigger.GetAction().Returns("gameParameters"); trigger.GetResponse().Returns("{\"parameters\":{\"a\":1}}".Json()); var persisted = "{\"b\":2}".Json(); store.Get(trigger).Returns(persisted); Expect(uut.Handle(trigger, store)); store.Received().Remove(Arg.Is(trigger)); cbk.Received().Invoke(Arg.Is <JSONObject>(e => e == persisted)); }