public void OnEntityQueryResponse_should_add_received_responses_to_entity() { var entity = SetupTestEntity(); var emptyRequest = new WorldCommands.EntityQuery.Request(); var context = "Some context"; entityQueryStorage.CommandRequestsInFlight.Add(TestCommandRequestId, new CommandRequestStore <WorldCommands.EntityQuery.Request>(entity, emptyRequest, context, TestCommandRequestId)); using (var wrappedOp = WorkerOpFactory.CreateEntityQueryResponseOp(TestCommandRequestId)) { receiveSystem.OnEntityQueryResponse(wrappedOp.Op); Assert.IsTrue(entityManager.HasComponent <WorldCommands.EntityQuery.CommandResponses>(entity)); var responses = entityManager.GetComponentData <WorldCommands.EntityQuery.CommandResponses>(entity); var count = 0; Assert.DoesNotThrow(() => { count = responses.Responses.Count; }); Assert.AreEqual(1, count); var response = responses.Responses[0]; Assert.AreEqual(emptyRequest, response.RequestPayload); Assert.AreEqual(context, response.Context); Assert.AreEqual(TestCommandRequestId, response.RequestId); Assert.AreEqual(wrappedOp.Op.StatusCode, response.StatusCode); Assert.AreEqual(wrappedOp.Op.Message, response.Message); Assert.AreEqual(wrappedOp.Op.Result, response.Result); Assert.AreEqual(wrappedOp.Op.ResultCount, response.ResultCount); } }
public override void StartState() { var query = new WorldCommands.EntityQuery.Request { EntityQuery = new EntityQuery { Constraint = new ComponentConstraint(Session.ComponentId), ResultType = new SnapshotResultType() } }; requestId = commandSystem.SendCommand(query); }
public void OnEntityQueryResponse_should_log_if_corresponding_entity_not_found() { var emptyRequest = new WorldCommands.EntityQuery.Request(); entityQueryStorage.CommandRequestsInFlight.Add(TestCommandRequestId, new CommandRequestStore <WorldCommands.EntityQuery.Request>(Entity.Null, emptyRequest, null, TestCommandRequestId)); using (var wrappedOp = WorkerOpFactory.CreateEntityQueryResponseOp(TestCommandRequestId)) { using (var expectingScope = logDispatcher.EnterExpectingScope()) { expectingScope.Expect(LogType.Log, LoggingUtils.LoggerName, "Op"); receiveSystem.OnEntityQueryResponse(wrappedOp.Op); } } }
public void OnEntityQueryResponse_should_add_received_responses_to_entity() { var entity = SetupTestEntity(); var emptyRequest = new WorldCommands.EntityQuery.Request(); var context = "Some context"; entityQueryStorage.CommandRequestsInFlight.Add(TestCommandRequestId, new CommandRequestStore <WorldCommands.EntityQuery.Request>(entity, emptyRequest, context, TestCommandRequestId)); using (var wrappedOp = WorkerOpFactory.CreateEntityQueryResponseOp(TestCommandRequestId)) { receiveSystem.OnEntityQueryResponse(wrappedOp.Op); Assert.IsTrue(entityManager.HasComponent <WorldCommands.EntityQuery.CommandResponses>(entity)); var responses = entityManager.GetComponentData <WorldCommands.EntityQuery.CommandResponses>(entity); var count = 0; Assert.DoesNotThrow(() => { count = responses.Responses.Count; }); Assert.AreEqual(1, count); var response = responses.Responses[0]; Assert.AreEqual(emptyRequest, response.RequestPayload); Assert.AreEqual(context, response.Context); Assert.AreEqual(TestCommandRequestId, response.RequestId); Assert.AreEqual(wrappedOp.Op.StatusCode, response.StatusCode); Assert.AreEqual(wrappedOp.Op.Message, response.Message); Assert.AreEqual(wrappedOp.Op.ResultCount, response.ResultCount); // Check that the result and the op contain snapshots of the same entities // Or that they are both null if one of them is null // todo UTY-1361 clean this up if (wrappedOp.Op.Result == null) { Assert.IsNull(response.Result); } else { CollectionAssert.AreEquivalent(wrappedOp.Op.Result.Keys, response.Result.Keys); } } }
public void SendEntityQueryCommand(WorldCommands.EntityQuery.Request request, Action <WorldCommands.EntityQuery.ReceivedResponse> callback = null) { var requestId = commandSystem.SendCommand(request, entity); if (callback == null) { return; } Action <WorldCommands.EntityQuery.ReceivedResponse> wrappedCallback = response => { if (IsValid) { callback(response); } }; callbackSystem.RegisterCommandResponseCallback(requestId, wrappedCallback); }
public void AddRequest(WorldCommands.EntityQuery.Request request, Entity sendingEntity, CommandRequestId requestId) { entityQueryResponses.Add( new CommandRequestWithMetaData <WorldCommands.EntityQuery.Request>(request, sendingEntity, requestId)); }