public void OnCreateEntityResponse_should_error_if_request_id_not_found()
 {
     using (var wrappedOp = WorkerOpFactory.CreateCreateEntityResponseOp(TestCommandRequestId))
     {
         Assert.Throws <UnknownRequestIdException>(() => { receiveSystem.OnCreateEntityResponse(wrappedOp.Op); });
     }
 }
        public void OnCreateEntityResponse_should_add_received_responses_to_entity()
        {
            var entity = SetupTestEntity();

            var emptyRequest = new WorldCommands.CreateEntity.Request();
            var context      = "Some context";

            createEntityStorage.CommandRequestsInFlight.Add(TestCommandRequestId,
                                                            new CommandRequestStore <WorldCommands.CreateEntity.Request>(entity,
                                                                                                                         emptyRequest, context, TestCommandRequestId));

            using (var wrappedOp = WorkerOpFactory.CreateCreateEntityResponseOp(TestCommandRequestId))
            {
                receiveSystem.OnCreateEntityResponse(wrappedOp.Op);

                Assert.IsTrue(entityManager.HasComponent <WorldCommands.CreateEntity.CommandResponses>(entity));

                var responses = entityManager.GetComponentData <WorldCommands.CreateEntity.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.EntityId, response.EntityId);
            }
        }
        public void OnCreateEntityResponse_should_log_if_corresponding_entity_not_found()
        {
            var emptyRequest = new WorldCommands.CreateEntity.Request();

            createEntityStorage.CommandRequestsInFlight.Add(TestCommandRequestId,
                                                            new CommandRequestStore <WorldCommands.CreateEntity.Request>(Entity.Null,
                                                                                                                         emptyRequest, null, TestCommandRequestId));

            using (var wrappedOp = WorkerOpFactory.CreateCreateEntityResponseOp(TestCommandRequestId))
            {
                using (var expectingScope = logDispatcher.EnterExpectingScope())
                {
                    expectingScope.Expect(LogType.Log, LoggingUtils.LoggerName, "Op");
                    receiveSystem.OnCreateEntityResponse(wrappedOp.Op);
                }
            }
        }