Beispiel #1
0
        private KeyValuePair <long, long> CompositeStorage(int count)
        {
            Stopwatch streamSw = new Stopwatch();
            Stopwatch sw       = new Stopwatch();

            sw.Start();
            for (int i = 0; i < count; i++)
            {
                ICompositeStorage storage = new JsonCompositeStorage();
                storage.Add("Name", "Test.UserModel");
                storage.Add("Version", 1);

                ICompositeStorage payloadStorage = storage.Add("Payload");
                payloadStorage.Add("FirstName", "John");
                payloadStorage.Add("LastName", "Doe");
                payloadStorage.Add("Direction", ListSortDirection.Descending);
                payloadStorage.Add("IDs", new int[] { 1, 2, 3 });
                payloadStorage.Add("Keys", new List <int>()
                {
                    4, 5, 6
                });

                streamSw.Start();
                using (MemoryStream stream = new MemoryStream())
                {
                    storage.StoreAsync(stream).Wait();
                    stream.Seek(0, SeekOrigin.Begin);

                    string json = null;
                    using (StreamReader reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true))
                        json = reader.ReadToEnd();

                    stream.Seek(0, SeekOrigin.Begin);
                    storage.LoadAsync(stream).Wait();
                }
                streamSw.Stop();

                string value;
                storage.TryGet("Name", out value);
                int version;
                storage.TryGet("Version", out version);
                storage.TryGet("Payload", out payloadStorage);
                payloadStorage.TryGet("FirstName", out value);
                payloadStorage.TryGet("LastName", out value);

                ListSortDirection direction;
                Assert.AreEqual(true, payloadStorage.TryGet("Direction", out direction));
                int[] ids;
                payloadStorage.TryGet("IDs", out ids);
                List <int> keys;
                payloadStorage.TryGet("Keys", out keys);
            }
            sw.Stop();
            return(new KeyValuePair <long, long>(sw.ElapsedMilliseconds, streamSw.ElapsedMilliseconds));
        }
        public void Base()
        {
            Converts.Repository
            .AddJsonEnumSearchHandler()
            .AddJsonPrimitivesSearchHandler()
            .AddJsonObjectSearchHandler();

            ICompositeStorage storage = new JsonCompositeStorage();

            storage.Add("Name", "Test.UserModel");
            storage.Add("Version", 1);

            ICompositeStorage payloadStorage = storage.Add("Payload");

            payloadStorage.Add("FirstName", "John");
            payloadStorage.Add("LastName", "Doe");
            payloadStorage.Add("Direction", ListSortDirection.Descending);
            payloadStorage.Add("IDs", new int[] { 1, 2, 3 });
            payloadStorage.Add("Keys", new List <int>()
            {
                4, 5, 6
            });

            using (MemoryStream stream = new MemoryStream())
            {
                storage.StoreAsync(stream).Wait();
                stream.Seek(0, SeekOrigin.Begin);

                string json = null;
                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true))
                    json = reader.ReadToEnd();

                stream.Seek(0, SeekOrigin.Begin);
                storage.LoadAsync(stream).Wait();
            }

            string value;

            Assert.AreEqual(true, storage.TryGet("Name", out value));
            Assert.AreEqual("Test.UserModel", value);

            int version;

            Assert.AreEqual(true, storage.TryGet("Version", out version));
            Assert.AreEqual(1, version);

            Assert.AreEqual(true, storage.TryGet("Payload", out payloadStorage));

            Assert.AreEqual(true, payloadStorage.TryGet("FirstName", out value));
            Assert.AreEqual("John", value);

            Assert.AreEqual(true, payloadStorage.TryGet("LastName", out value));
            Assert.AreEqual("Doe", value);

            ListSortDirection direction;

            Assert.AreEqual(true, payloadStorage.TryGet("Direction", out direction));
            Assert.AreEqual(ListSortDirection.Descending, direction);

            int[] ids;
            Assert.AreEqual(true, payloadStorage.TryGet("IDs", out ids));
            Assert.IsNotNull(ids);
            Assert.AreEqual(1, ids[0]);
            Assert.AreEqual(2, ids[1]);
            Assert.AreEqual(3, ids[2]);

            List <int> keys;

            Assert.AreEqual(true, payloadStorage.TryGet("Keys", out keys));
            Assert.IsNotNull(ids);
            Assert.AreEqual(4, keys[0]);
            Assert.AreEqual(5, keys[1]);
            Assert.AreEqual(6, keys[2]);
        }