예제 #1
0
        public void DeserializerMismatchError()
        {
            DataSerializer s = new DataSerializer();

            s.AttachErrorHandler();

            Assert.ThrowsException <DeveloperError>(() => s.Encapsulate(new SerializerTestData()));

            BinaryFormatter formatter = new BinaryFormatter();

            MemoryStream stream2 = new MemoryStream();

            formatter.Serialize(stream2, 5);

            byte[]       ar      = stream2.ToArray();
            MemoryStream stream3 = new MemoryStream();

            stream3.Write(BitConverter.GetBytes(ar.Length), 0, 4);

            stream2.Seek(0, SeekOrigin.Begin);
            stream2.CopyTo(stream3);

            stream3.Seek(0, SeekOrigin.Begin);
            Assert.ThrowsException <DataSymmetricityError>(() => s.Receive(stream3));
        }
예제 #2
0
        public void SerializerError()
        {
            DataSerializer s = new DataSerializer();

            s.AttachErrorHandler();
            Assert.ThrowsException <DeveloperError>(() => s.Encapsulate(new SerializerTestData()));
        }
예제 #3
0
        public void Serializer()
        {
            DataSerializer s = new DataSerializer();

            s.AttachErrorHandler();
            s.SenderDataReady += stream =>
            {
                s.ProviderDataReady += obj => ((MockData1)obj).Verify();
                s.Receive(stream);
            };
            s.Encapsulate(new MockData1());
        }
예제 #4
0
        public IntegrationBase()
        {
            server = new MockTCP(wire);
            client = new MockTCP(wire);

            server.other = client;
            client.other = server;

            serverStatefulSession  = FTConnectionController.CreateStatefulSession(server, new StateProvider(), 5000, 8000);
            clientStatelessSession = FTConnectionController.CreateStatelessSession(client, 5000, 8000);

            serverTree.AttachErrorHandler();
            clientTree.AttachErrorHandler();

            serverSerializer = new DataSerializer();
            clientSerializer = new DataSerializer();
            serverSerializer.AttachErrorHandler();
            clientSerializer.AttachErrorHandler();

            serverTree.ConnectToDownstream(serverSerializer);
            serverSerializer.ConnectToDownstream(server);
            server.ConnectToUpstream(serverSerializer);
            serverSerializer.ConnectToUpstream(serverTree);

            clientTree.ConnectToDownstream(clientSerializer);
            clientSerializer.ConnectToDownstream(client);
            client.ConnectToUpstream(clientSerializer);
            clientSerializer.ConnectToUpstream(clientTree);

            serverData     = new LeafProtocolHandler <MockData1>();
            clientData     = new LeafProtocolHandler <MockData1>();
            clientRecovery = new LeafProtocolHandler <MockData2>();

            serverTree.Register(serverStatefulSession);
            serverTree.Register(serverData);
            serverTree.Entry(serverStatefulSession);
            serverTree.ConnectToLeaf(serverStatefulSession, serverData);

            clientTree.Register(clientStatelessSession);
            clientTree.Register(clientData);
            clientTree.Register(clientRecovery);
            clientTree.Entry(clientStatelessSession);
            clientTree.ConnectToLeaf(clientStatelessSession, clientData);
            clientTree.ConnectToLeaf(clientStatelessSession, clientRecovery);

            serverData.NewData     += protocol => { protocol.Verify(); serverDataCount++; };
            clientData.NewData     += protocol => { protocol.Verify(); clientDataCount++; };
            clientRecovery.NewData += protocol => { protocol.Verify(); recoveryCount++; };
        }
예제 #5
0
        public void DeserializerNotSerializableError()
        {
            DataSerializer s = new DataSerializer();

            s.AttachErrorHandler();

            BinaryFormatter formatter = new BinaryFormatter();

            MemoryStream stream = new MemoryStream();

            formatter.Serialize(stream, new byte[1200]);

            stream.Seek(0, SeekOrigin.Begin);
            Assert.ThrowsException <DataIntegrityError>(() => s.Receive(stream));
        }
예제 #6
0
        public void DataConcatenation()
        {
            DataSerializer s = new DataSerializer();

            s.AttachErrorHandler();
            s.SenderDataReady += data =>
            {
                MemoryStream ms = (MemoryStream)data;
                ms.Seek(0, SeekOrigin.Begin);
                byte[] ar = ms.ToArray();

                MemoryStream stream1 = new MemoryStream(ar, 0, 16);
                MemoryStream stream2 = new MemoryStream(ar, 16, ar.Length - 16);

                s.ProviderDataReady += obj => ((MockData1)obj).Verify();
                s.Receive(stream1);
                s.Receive(stream2);
            };

            s.Encapsulate(new MockData1());
        }