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)); }
Write <T>( DataSize dataSize) where T : IDataHelper <T>, new() { return(Write <T>(StashConfiguration.GetClient <T>(), dataSize)); }
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); } }
Delete <T>( string partitionKey, string rowKey) { var context = StashConfiguration.GetClient <T>(); context.Delete(partitionKey, rowKey); }
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); }
GetQuery <T>( string partitionKey, string rowKey) where T : IDataHelper <T>, new() { return(TypeFactory <T> .GetQuery( StashConfiguration.GetClient <T>(), partitionKey, rowKey)); }
InsertItems <T>( IEnumerable <T> items) { var context = StashConfiguration.GetClient <T>().GetContext(); foreach (T item in items) { context.Insert(item); } context.Commit(); }
ReadAll <T>() where T : IDataHelper <T>, new() { var service = StashConfiguration.GetClient <T>(); var q = from t in service.CreateQuery() select t; return(q); }
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); }
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); }
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); }
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); }
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); }
void TestAllDataImplicit() { StashConfiguration.GetClient <AllDataImplicit>().CreateTableIfNotExist(); Full <AllDataImplicit>(DataSize.Small); }