public void CanCommunicate()
        {
            var plane = TestGeometry.CreateUnitPlane("Plane");
            
            var serializerFactory = new SerializerFactory();
            var serializer = serializerFactory.CreateSerializer();
            
            var communicatorFactory = new CommunicatorFactory();

            var primaryCommunicator = communicatorFactory.CreatePrimaryCommunicator(serializer);
            primaryCommunicator.Connect();
            
            var secondaryCommunicator = communicatorFactory.CreateSecondaryCommunicator(serializer);
            secondaryCommunicator.Connect();

            Task.Delay(500).Wait();

            primaryCommunicator.Send(plane);

            Task.Delay(500).Wait();
            
            Assert.True(secondaryCommunicator.HasReceivedTransactions);

            var transaction = secondaryCommunicator.Receive();
            var deserializedPlane = serializer.Deserialize<VisualizerMesh>(transaction.Payload);
            
            Assert.Equal(plane.Label, deserializedPlane.Label);
            
            secondaryCommunicator.Disconnect();
            primaryCommunicator.Disconnect();
            
            Assert.False(primaryCommunicator.IsConnected);
            Assert.False(secondaryCommunicator.IsConnected);
        }
        public void CanCommunicateWithProcess()
        {
            var factory           = new ProcessFactory();
            var visualizerProcess = factory.CreateVisualizerProcess(VisualizerType.Unity);

            visualizerProcess.Start();
            var plane = TestGeometry.CreateUnitPlane("Plane");

            visualizerProcess.Communicator.Send(plane);
            Task.Delay(5000).Wait();
            visualizerProcess.Stop();
        }
Beispiel #3
0
        public void CanSerializeAndDeserializeMesh()
        {
            var plane = TestGeometry.CreateUnitPlane("Plane");

            var factory    = new SerializerFactory();
            var serializer = factory.CreateSerializer();

            var transaction = new Transaction(typeof(VisualizerMesh), serializer.SerializeToStream(plane));

            var stream = serializer.SerializeToStream(transaction);
            var deserializedTransaction = serializer.Deserialize <Transaction>(stream);

            Assert.Equal(typeof(VisualizerMesh).Name, transaction.PayloadType);

            var deserializedPlane = serializer.Deserialize <VisualizerMesh>(deserializedTransaction.Payload);

            Assert.Equal(plane.Label, deserializedPlane.Label);
        }
        public void CanSendMultipleMessages()
        {
            var serializerFactory = new SerializerFactory();
            var serializer = serializerFactory.CreateSerializer();
            
            var communicatorFactory = new CommunicatorFactory();

            var primaryCommunicator = communicatorFactory.CreatePrimaryCommunicator(serializer);
            primaryCommunicator.Connect();
            
            var secondaryCommunicator = communicatorFactory.CreateSecondaryCommunicator(serializer);
            secondaryCommunicator.Connect();

            Task.Delay(500).Wait();
            
            for (var i = 0; i < 5; i++)
            {
                var geometryName = "Plane" + i;
                var plane = TestGeometry.CreateUnitPlane(geometryName);
                
                primaryCommunicator.Send(plane);
                Task.Delay(500).Wait();
                var transactionFromPrimary = secondaryCommunicator.Receive();
                var deserializedPlaneFromPrimary = serializer.Deserialize<VisualizerMesh>(transactionFromPrimary.Payload);
                
                secondaryCommunicator.Send(deserializedPlaneFromPrimary);
                Task.Delay(500).Wait();
                var transactionFromSecondary = primaryCommunicator.Receive();
                var deserializedPlaneFromSecondary = serializer.Deserialize<VisualizerMesh>(transactionFromSecondary.Payload);
                
                Assert.Equal(deserializedPlaneFromPrimary.Label, deserializedPlaneFromSecondary.Label);
            }
            
            secondaryCommunicator.Disconnect();
            primaryCommunicator.Disconnect();
        }