コード例 #1
0
        void AllDataImplicitWriteListRange()
        {
            const
            string PKey = "WriteListRange";

            const int
                count = 9;                      // set to 9 or less, so that are range matches the query

            var
                query0 = StashConfiguration.GetClient <AllDataImplicit>()
                         .CreateQuery()
                         .Where(i => i.PartitionKey == PKey && i.RowKey.CompareTo("1") >= 0 && i.RowKey.CompareTo("9" + "z") <= 0);             // 1 to 9

            var
                query = query0.Where(i => i.BoolProperty == true || i.BoolProperty == false);

            int
                deleteCount = 0;

            Assert.IsTrue(
                (deleteCount = FullMultipleRange <AllDataImplicit>(
                     count,
                     PKey,
                     query)) == count,
                String.Format(
                    "Delete Count = {0}. Expected Count = {1}.",
                    deleteCount,
                    count));
        }
コード例 #2
0
 Write <T>(
     DataSize dataSize)
     where
 T                                                               :       IDataHelper <T>, new()
 {
     return(Write <T>(StashConfiguration.GetClient <T>(), dataSize));
 }
コード例 #3
0
        void DoTestAllDataWithDictionaryMultiple()
        {
            bool isSuccess;

            try
            {
                StashClientOptions
                    options = StashConfiguration.GetDefaultOptions();

                AllDataWithDictionaryMultiple(options);                         // use large data must fail

                // if control came here we failed
                isSuccess = false;
            }
            catch (Exception)
            {
                isSuccess = true;
            }

            if (!isSuccess)
            {
                Assert.Fail();
            }


            {
                StashClientOptions
                    options = StashConfiguration.GetDefaultOptions();

                options.SupportLargeObjectsInPool = true;

                AllDataWithDictionary
                    entity = AllDataWithDictionaryMultiple(options);

                // now read without the support large pool options and validate the the entities do NOT match
                //	and the unmapped pool count is different
                options.SupportLargeObjectsInPool = false;

                StashClient <AllDataWithDictionary>
                client = StashConfiguration.GetClient <AllDataWithDictionary>(options);

                AllDataWithDictionary
                    entityRead = client.Get(entity.PartitionKey, entity.RowKey);

                Assert.IsFalse(entityRead.Equals(entity));

                // now read without the support large pool options and validate the the entities DO match
                //	and the unmapped pool count is different
                options.SupportLargeObjectsInPool = true;

                client = StashConfiguration.GetClient <AllDataWithDictionary>(options);

                entityRead = client.Get(entity.PartitionKey, entity.RowKey);

                Assert.IsTrue(entityRead.Equals(entity));

                // delete
                client.Delete(entityRead);
            }
        }
コード例 #4
0
        Delete <T>(
            string partitionKey,
            string rowKey)
        {
            var context = StashConfiguration.GetClient <T>();

            context.Delete(partitionKey, rowKey);
        }
コード例 #5
0
        DoComputeDataSizeValidateBoundary()
        {
            // create instance and get its size
            var client = StashConfiguration.GetClient <AllDataExplicit>();

            var
                item = TypeFactory <AllDataExplicit> .CreateRandomMultiple();

            int
                size = client.ComputeEntityDataSize(item);

            // character count
            int
                maxSize = 1024 * 1024;

            int
                delta = (maxSize - size) / 2;                   // 2 = size of char

            // Increase size to max and insert
            item.StringField += DataGenerator.GetStringSizeFixed(delta);

            // re-compute size ... should exceed so trim it back
            int
                reSize = client.ComputeEntityDataSize(item);

            delta = (reSize - maxSize) / 2;

            item.StringField = item.StringField.Substring(0, item.StringField.Length - delta);             //  - 8

            // re-compute size ... should now fit maxSize
            reSize = client.ComputeEntityDataSize(item);

            client.Insert(item);

            // delete
            client.Delete(item);

            // Increase size by 1 and insert expecting to fail
            item.StringField += "A";

            bool isSuccess;

            try
            {
                client.Insert(item);

                isSuccess = false;
            }
            catch (Exception)
            {
                isSuccess = true;
            }

            Assert.IsTrue(isSuccess);
        }
コード例 #6
0
 GetQuery <T>(
     string partitionKey,
     string rowKey)
     where
 T                                                               :       IDataHelper <T>, new()
 {
     return(TypeFactory <T> .GetQuery(
                StashConfiguration.GetClient <T>(),
                partitionKey,
                rowKey));
 }
コード例 #7
0
        InsertItems <T>(
            IEnumerable <T> items)
        {
            var
                context = StashConfiguration.GetClient <T>().GetContext();

            foreach (T item in items)
            {
                context.Insert(item);
            }

            context.Commit();
        }
コード例 #8
0
        ReadAll <T>()
            where
        T                                                               :       IDataHelper <T>, new()
        {
            var
                service = StashConfiguration.GetClient <T>();

            var
                q = from t in service.CreateQuery()
                    select t;

            return(q);
        }
コード例 #9
0
        AllDataWithDictionaryMultiple(
            StashClientOptions options)
        {
            StashClient <AllDataWithDictionary>
            client = StashConfiguration.GetClient <AllDataWithDictionary>(options);

            AllDataWithDictionary
                entity = TypeFactory <AllDataWithDictionary> .Create(DataSize.Multiple);       // DataSize.Multiple

            client.Insert(entity);

            AllDataWithDictionary
                entityRead = client.Get(entity.PartitionKey, entity.RowKey);

            Assert.IsTrue(entityRead.Equals(entity));

            return(entityRead);
        }
コード例 #10
0
        Merge <T>(
            T data)
            where
        T                                                               :       IDataHelper <T>
        {
            var context = StashConfiguration.GetClient <T>();

            data.UpdateForMerge();

            string
                etag = data.GetETag();

            data = context.Merge(data);

            // check that if etag is present, it changed.
            Assert.IsTrue(!data.HasETag() || data.GetETag() != etag);

            return(data);
        }
コード例 #11
0
        Write <T>(
            int count)
            where
        T                                                               :       IDataHelper <T>, new()
        {
            List <T>
            result = new List <T>();

            var context = StashConfiguration.GetClient <T>();

            while (--count >= 0)
            {
                var
                    data = TypeFactory <T> .CreateRandomSmall();

                context.Insert(data);

                result.Add(data);
            }

            return(result);
        }
コード例 #12
0
        DeleteMultiple <T>(
            IQueryable <T> query)
            where
        T                                                               :       IDataHelper <T>, new()
        {
            var
                items = query.ToList();

            var service = StashConfiguration.GetClient <T>();

            int i = 0;

            foreach (T item in items)
            {
                ++i;
                service.Delete(item);
            }

            System.Diagnostics.Trace.WriteLine(
                String.Format(
                    "{0} items deleted.",
                    i));
            return(i);
        }
コード例 #13
0
        InsertOrUpdate <T>(
            DataSize dataSize)
            where
        T                                                               :       IDataHelper <T>, new()
        {
            var client = StashConfiguration.GetClient <T>();

            T
                data = TypeFactory <T> .Create(dataSize);

            T
                written = client.InsertOrUpdate(data);

            // read
            T
                read = Read <T>(
                written.GetPartitionKey(),
                written.GetRowKey());

            Assert.IsTrue(read.Equals(written));

            // update
            written.UpdateDateTime();

            written = client.InsertOrUpdate(written);
            written = client.InsertOrMerge(written);

            read = Read <T>(
                written.GetPartitionKey(),
                written.GetRowKey());

            Assert.IsTrue(read.Equals(written));

            // delete
            client.Delete(read);
        }
コード例 #14
0
        void TestAllDataImplicit()
        {
            StashConfiguration.GetClient <AllDataImplicit>().CreateTableIfNotExist();

            Full <AllDataImplicit>(DataSize.Small);
        }