public void Dev2BinaryStorage_BasicUsage_WhenAddingRemovingAtVolumn_AllDataFetched()
        {
            //------------Setup for test--------------------------
            Dev2BinaryStorage <BinaryDataListRow> dic = new Dev2BinaryStorage <BinaryDataListRow>(Guid.NewGuid().ToString(), 4194304); // 4MB buffer ;)

            const int cnt = 50000;

            IList <BinaryDataListRow> rows = new List <BinaryDataListRow>(cnt);
            IList <string>            keys = new List <string>();


            for (int i = 0; i < cnt; i++)
            {
                BinaryDataListRow row = new BinaryDataListRow(5);
                row.UpdateValue("col1" + Guid.NewGuid() + " " + Guid.NewGuid() + " " + Guid.NewGuid() + " " + Guid.NewGuid(), 0, 5);
                row.UpdateValue("col2", 1, 5);
                row.UpdateValue("col3" + Guid.NewGuid(), 2, 5);
                row.UpdateValue("col4", 3, 5);
                row.UpdateValue("col5" + Guid.NewGuid(), 4, 5);

                rows.Add(row);
                keys.Add(Guid.NewGuid().ToString());
            }

            //------------Execute Test---------------------------

            // add rows
            for (int i = 0; i < cnt; i++)
            {
                dic[keys[i]] = rows[i];

                // fake removals ;)
                if ((i + 1) % 100 == 0)
                {
                    dic.Remove(keys[i]);
                }

                // fake compact
                //if((i + 1) % 200 == 0)
                //{
                //    dic.Compact();
                //}
            }


            // check first and 2nd to last row, since last was removed ;)
            BinaryDataListRow fetchedRow1 = dic[keys[0]];
            BinaryDataListRow fetchedRow2 = dic[keys[cnt - 2]];

            //------------Assert Results-------------------------
            Assert.AreEqual("col2", fetchedRow1.FetchValue(1, 5));
            Assert.AreEqual("col4", fetchedRow1.FetchValue(3, 5));

            Assert.AreEqual("col2", fetchedRow2.FetchValue(1, 5));
            Assert.AreEqual("col4", fetchedRow2.FetchValue(3, 5));
        }
        public void Dev2BinaryStorage_BasicUsage_WhenAddingRemovingAndCompacting_AllDataFetched()
        {
            //------------Setup for test--------------------------
            Dev2BinaryStorage <BinaryDataListRow> dic = new Dev2BinaryStorage <BinaryDataListRow>(Guid.NewGuid().ToString(), 756);

            BinaryDataListRow row1 = new BinaryDataListRow(5);

            row1.UpdateValue("col1", 0, 5);
            row1.UpdateValue("col2", 1, 5);
            row1.UpdateValue("col3", 2, 5);
            row1.UpdateValue("col4", 3, 5);
            row1.UpdateValue("col5", 4, 5);

            BinaryDataListRow row3 = new BinaryDataListRow(5);

            row3.UpdateValue("col3", 2, 5);
            row3.UpdateValue("col4", 3, 5);
            row3.UpdateValue("col5", 4, 5);


            BinaryDataListRow row2 = new BinaryDataListRow(5);

            row1.UpdateValue("col1", 0, 5);
            row1.UpdateValue("col2", 1, 5);
            row1.UpdateValue("col3", 2, 5);
            row1.UpdateValue("col4", 3, 5);
            row1.UpdateValue("col5", 4, 5);

            string key1 = Guid.NewGuid().ToString();
            string key2 = Guid.NewGuid().ToString();
            string key3 = Guid.NewGuid().ToString();

            //------------Execute Test---------------------------
            dic[key3] = row3;
            dic[key2] = row2;
            dic[key1] = row1;

            dic.Remove(key2);
            dic.Compact();

            BinaryDataListRow fetchedRow1 = dic[key1];
            BinaryDataListRow fetchedRow3 = dic[key3];

            //------------Assert Results-------------------------
            Assert.AreEqual("col1", fetchedRow1.FetchValue(0, 5));
            Assert.AreEqual("col2", fetchedRow1.FetchValue(1, 5));
            Assert.AreEqual("col3", fetchedRow1.FetchValue(2, 5));
            Assert.AreEqual("col4", fetchedRow1.FetchValue(3, 5));
            Assert.AreEqual("col5", fetchedRow1.FetchValue(4, 5));


            Assert.AreEqual("col3", fetchedRow3.FetchValue(2, 5));
            Assert.AreEqual("col4", fetchedRow3.FetchValue(3, 5));
            Assert.AreEqual("col5", fetchedRow3.FetchValue(4, 5));
        }
        public void BinaryDataListRow_ProtoBuffDeserialize_NormalDeserialization_WithEmptyString_AllDataHydrated()
        {
            //------------Setup for test--------------------------

            BinaryDataListRow row1 = new BinaryDataListRow(5);

            row1.UpdateValue("col1", 0, 5);
            row1.UpdateValue("col2", 1, 5);
            row1.UpdateValue("", 2, 5);
            row1.UpdateValue("col4", 3, 5);
            row1.UpdateValue("col5", 4, 5);

            //------------Execute Test---------------------------
            var bytes = row1.ToByteArray();

            BinaryDataListRow row2 = new BinaryDataListRow(5);

            row2.ToObject(bytes);

            //------------Assert Results-------------------------
            var fetchValue = row2.FetchValue(2, 5);

            Assert.AreEqual("", fetchValue);
            Assert.IsNotNull(fetchValue);
        }
        public void CanFetchValueExpectValidRow()
        {
            Dev2BinaryStorage <BinaryDataListRow> dic = new Dev2BinaryStorage <BinaryDataListRow>(Guid.NewGuid().ToString(), 1024);

            BinaryDataListRow row1 = new BinaryDataListRow(5);

            row1.UpdateValue("col1", 0, 5);
            row1.UpdateValue("col2", 1, 5);
            row1.UpdateValue("col3", 2, 5);
            row1.UpdateValue("col4", 3, 5);
            row1.UpdateValue("col5", 4, 5);

            BinaryDataListRow row3 = new BinaryDataListRow(5);

            row3.UpdateValue("col3", 2, 5);
            row3.UpdateValue("col4", 3, 5);
            row3.UpdateValue("col5", 4, 5);


            string key1 = Guid.NewGuid().ToString();
            string key2 = Guid.NewGuid().ToString();
            string key3 = Guid.NewGuid().ToString();

            dic.Remove(key2);
            dic[key3] = row3;
            dic[key1] = row1;

            dic.Remove(key2);
            //dic.Compact();

            BinaryDataListRow fetchedRow1 = dic[key1];
            BinaryDataListRow fetchedRow3 = dic[key3];

            Assert.AreEqual("col1", fetchedRow1.FetchValue(0, 5));
            Assert.AreEqual("col2", fetchedRow1.FetchValue(1, 5));
            Assert.AreEqual("col3", fetchedRow1.FetchValue(2, 5));
            Assert.AreEqual("col4", fetchedRow1.FetchValue(3, 5));
            Assert.AreEqual("col5", fetchedRow1.FetchValue(4, 5));


            Assert.AreEqual("col3", fetchedRow3.FetchValue(2, 5));
            Assert.AreEqual("col4", fetchedRow3.FetchValue(3, 5));
            Assert.AreEqual("col5", fetchedRow3.FetchValue(4, 5));
        }
        public void Dev2BinaryStorage_WhenBaseSmallerThanView_AllDataFetched()
        {
            // ------------Setup for test--------------------------
            Dev2BinaryStorage <BinaryDataListRow> dic = new Dev2BinaryStorage <BinaryDataListRow>(Guid.NewGuid().ToString(), 756);

            const int baseRowCount = 5;
            const int viewRowCount = 6;

            BinaryDataListRow row1 = new BinaryDataListRow(5);

            row1.UpdateValue("col1", 0, baseRowCount);
            row1.UpdateValue("col2", 1, baseRowCount);
            row1.UpdateValue("col3", 2, baseRowCount);
            row1.UpdateValue("col4", 3, baseRowCount);
            row1.UpdateValue("col5", 4, baseRowCount);

            string key1 = Guid.NewGuid().ToString();

            // ------------Execute Test---------------------------

            dic[key1] = row1;
            row1.UpdateValue("col6", 5, viewRowCount);
            dic[key1] = row1;

            BinaryDataListRow fetchedRow1 = dic[key1];

            // ------------Assert Results-------------------------
            Assert.AreEqual("col1", fetchedRow1.FetchValue(0, viewRowCount));
            Assert.AreEqual("col2", fetchedRow1.FetchValue(1, viewRowCount));
            Assert.AreEqual("col3", fetchedRow1.FetchValue(2, viewRowCount));
            Assert.AreEqual("col4", fetchedRow1.FetchValue(3, viewRowCount));
            Assert.AreEqual("col5", fetchedRow1.FetchValue(4, viewRowCount));
            Assert.AreEqual("col6", fetchedRow1.FetchValue(5, viewRowCount));
        }