Пример #1
0
        public void Run()
        {
            const string kTestData = "Hello, World!";
            var          factory   = new PofStreamsFactoryImpl(threadingProxy, streamFactory, serializer);
            var          ms1       = streamFactory.CreateMemoryStream();
            var          ms2       = streamFactory.CreateMemoryStream();

            // Write test data into ms1
            var helperStream = factory.CreatePofStream(ms1);

            helperStream.Write(kTestData);
            ms1.Position = 0;

            // Read from ms1 stream with mainStream
            var mainStream = factory.CreatePofStream(ms1.Reader, ms2.Writer);

            AssertEquals(kTestData, mainStream.Read <string>());

            // Write to ms2 stream with mainStream
            mainStream.Write(kTestData);

            // Assert the data was written to ms2 as expected
            ms2.Position = 0;
            helperStream = factory.CreatePofStream(ms2);
            AssertEquals(kTestData, helperStream.Read <string>());
        }
Пример #2
0
        public void ReadTest()
        {
            const int    kMessageCount = 1024 * 64;
            const string kMessage      = "herp";

            using (var ms = streamFactory.CreateMemoryStream()) {
                for (var i = 0; i < kMessageCount; i++)
                {
                    serializer.Serialize(ms.GetWriter(), new TestClass(kMessage));
                }
                ms.Position = 0;

                var factory   = new PofStreamsFactoryImpl(threadingProxy, streamFactory, serializer);
                var pofStream = factory.CreatePofStream(ms);
                var tasks     = Util.Generate(kMessageCount / 2, i => pofStream.ReadAsync <TestClass>());
                tasks.Select(t => (TestClass)t.Result).ForEach(x => AssertEquals(x.Value, kMessage));
            }
        }
Пример #3
0
        public void WriteTest()
        {
            const int    kMessageCount = 1024 * 64;
            const string kMessage      = "herp";

            using (var ms = streamFactory.CreateMemoryStream()) {
                var factory      = new PofStreamsFactoryImpl(threadingProxy, streamFactory, serializer);
                var pofStream    = factory.CreatePofStream(ms);
                var writingTasks = Util.Generate(kMessageCount, i => pofStream.WriteAsync(new TestClass(kMessage)));
                writingTasks.ForEach(x => x.Wait());

                ms.Position = 0;

                for (var i = 0; i < kMessageCount; i++)
                {
                    var obj = serializer.Deserialize <TestClass>(ms.GetReader());
                    AssertEquals(kMessage, obj.Value);
                }
            }
        }