public OperationSystem(OperationMap map, ISerializationService serializer, IOperationTransport transport, Func <Type, IOperationHandler> handlerFactory) { var writer = new NetworkOperationWriter(map, serializer, transport); var reader = new NetworkOperationReader(map, serializer); var activeOperations = new ActiveOperationsManager(); Dispatcher = new OperationDispatcher(activeOperations, writer); Processor = new OperationProcessor(new OperationService(activeOperations, writer, handlerFactory), reader); }
public void ShouldReadPromiseId() { var writer = new NetworkOperationWriter(_map, _serializer, _transport); var promise = new OperationPromise <TestResponse>(0, new TestOperationWithResponse()); writer.WriteOperationWithResponse(promise); var reader = new NetworkOperationReader(_map, _serializer); var promiseId = reader.ReadPromiseId(_transport.SentOperations.Single().Item2); promiseId.ShouldBe(promise.Id); }
public void ShouldWriteContextInitialization() { var writer = new NetworkOperationWriter(_map, new SerializationService(new BinarySerializer()), _transport); writer.WriteContextInitialization(ContextType.InstanceServer); var sentOperation = _transport.SentOperations.SingleOrDefault(); sentOperation.ShouldNotBeNull(); sentOperation.Item1.ShouldBe(OperationCode.SetupContext); sentOperation.Item2.ShouldContainKeyAndValue((byte)OperationParameterCode.ContextType, ContextType.InstanceServer); }
public void ShouldReadResponse() { var writer = new NetworkOperationWriter(_map, _serializer, _transport); var response = new TestResponse { Data = "test_data" }; writer.WriteResponse(new TestOperationWithResponse(), response); var reader = new NetworkOperationReader(_map, _serializer); var readResponse = (TestResponse)reader.ReadResponse(_transport.SentOperations.Single().Item2); readResponse.Data.ShouldBe(response.Data); }
public void ShouldReadOperation() { var writer = new NetworkOperationWriter(_map, _serializer, _transport); var operation = new TestOperation { Data = "test_data" }; writer.WriteOperation(operation); var reader = new NetworkOperationReader(_map, _serializer); var readOperation = (TestOperation)reader.ReadOperation(_transport.SentOperations.Single().Item2); readOperation.Data.ShouldBe(operation.Data); }
public void ShouldWriteResponse() { var writer = new NetworkOperationWriter(_map, new SerializationService(new BinarySerializer()), _transport); writer.WriteResponse(new TestOperationWithResponse(), new TestResponse()); var sentOperation = _transport.SentOperations.SingleOrDefault(); sentOperation.ShouldNotBeNull(); sentOperation.Item1.ShouldBe(OperationCode.HandleResponse); sentOperation.Item2.ShouldContainKeyAndValue((byte)OperationParameterCode.OperationId, _map.GetMappedOperation(typeof(TestOperationWithResponse)).Id); sentOperation.Item2.ShouldContainKey((byte)OperationParameterCode.OperationResponseData); }