Exemple #1
0
        public void PrimitiveTypes1Test()
        {
            var init = new PrimitiveTypes1();

            init.Initialize();
            PrimitiveTypes1 final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <PrimitiveTypes1>(mem);
            }
            AssertionHelper.AssertMembersAreEqual(init, final);
        }
Exemple #2
0
        public void ThreadSafe_NormalTest()
        {
            var boisThreaded = new BoisSerializer();
            var init         = new PrimitiveTypes1();

            init.Initialize();
            PrimitiveTypes1 final;

            using (var iniToDeserialMem = new MemoryStream())
            {
                boisThreaded.Serialize(init, iniToDeserialMem);
                iniToDeserialMem.Seek(0, SeekOrigin.Begin);

                int done  = 0;
                var tasks = new Thread[500];
                for (int i = 0; i < tasks.Length; i++)
                {
                    var th = new Thread(
                        () =>
                    {
                        Thread.Sleep(50);
                        using (var mem = new MemoryStream())
                        {
                            boisThreaded.Serialize(init, mem);
                            mem.Seek(0, SeekOrigin.Begin);
                            final = boisThreaded.Deserialize <PrimitiveTypes1>(mem);
                        }
                        Interlocked.Increment(ref done);
                        AssertionHelper.AssertMembersAreEqual(init, final);
                    });
                    th.IsBackground = true;
                    th.Name         = "ThreadSafe_Test_" + i;
                    tasks[i]        = th;
                }
                foreach (var task in tasks)
                {
                    task.Start();
                }

                while (done < tasks.Length)
                {
                    Thread.Sleep(10);
                }
            }
        }