private async Task DoTableRegionalQueryOnSupportedTypesAsync(TablePayloadFormat format) { CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR"); CloudTableClient client = GenerateCloudTableClient(); client.DefaultRequestOptions.PayloadFormat = format; CloudTable table = client.GetTableReference(GenerateRandomTableName()); await table.CreateAsync(); try { // Setup TableBatchOperation batch = new TableBatchOperation(); string pk = Guid.NewGuid().ToString(); DynamicTableEntity middleRef = null; for (int m = 0; m < 100; m++) { ComplexEntity complexEntity = new ComplexEntity(); complexEntity.String = string.Format("{0:0000}", m); complexEntity.Binary = new byte[] { 0x01, 0x02, (byte)m }; complexEntity.BinaryPrimitive = new byte[] { 0x01, 0x02, (byte)m }; complexEntity.Bool = m % 2 == 0 ? true : false; complexEntity.BoolPrimitive = m % 2 == 0 ? true : false; complexEntity.Double = m + ((double)m / 100); complexEntity.DoublePrimitive = m + ((double)m / 100); complexEntity.Int32 = m; complexEntity.IntegerPrimitive = m; complexEntity.Int64 = (long)int.MaxValue + m; complexEntity.LongPrimitive = (long)int.MaxValue + m; complexEntity.Guid = Guid.NewGuid(); DynamicTableEntity dynEnt = new DynamicTableEntity(pk, string.Format("{0:0000}", m)); dynEnt.Properties = complexEntity.WriteEntity(null); batch.Insert(dynEnt); if (m == 50) { middleRef = dynEnt; } // Add delay to make times unique await Task.Delay(100); } await table.ExecuteBatchAsync(batch); // 1. Filter on String ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterCondition("String", QueryComparisons.GreaterThanOrEqual, "0050"), 50); // 2. Filter on Guid ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForGuid("Guid", QueryComparisons.Equal, middleRef.Properties["Guid"].GuidValue.Value), 1); // 3. Filter on Long ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForLong("Int64", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["LongPrimitive"].Int64Value.Value), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForLong("LongPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["LongPrimitive"].Int64Value.Value), 50); // 4. Filter on Double ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDouble("Double", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["Double"].DoubleValue.Value), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDouble("DoublePrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["DoublePrimitive"].DoubleValue.Value), 50); // 5. Filter on Integer ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForInt("Int32", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["Int32"].Int32Value.Value), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForInt("IntegerPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["IntegerPrimitive"].Int32Value.Value), 50); // 6. Filter on Date ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDate("DateTimeOffset", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["DateTimeOffset"].DateTimeOffsetValue.Value), 50); // 7. Filter on Boolean ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBool("Bool", QueryComparisons.Equal, middleRef.Properties["Bool"].BooleanValue.Value), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBool("BoolPrimitive", QueryComparisons.Equal, middleRef.Properties["BoolPrimitive"].BooleanValue.Value), 50); // 8. Filter on Binary ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.Equal, middleRef.Properties["Binary"].BinaryValue), 1); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.Equal, middleRef.Properties["BinaryPrimitive"].BinaryValue), 1); // 9. Filter on Binary GTE ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["Binary"].BinaryValue), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["BinaryPrimitive"].BinaryValue), 50); // 10. Complex Filter on Binary GTE ExecuteQueryAndAssertResults(table, TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, middleRef.PartitionKey), TableOperators.And, TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["Binary"].BinaryValue)), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["BinaryPrimitive"].BinaryValue), 50); } finally { Thread.CurrentThread.CurrentCulture = currentCulture; table.DeleteIfExistsAsync().Wait(); } }
public void TableEdmTypeCheck() { CloudTableClient tableClient = GenerateCloudTableClient(); string pk = Guid.NewGuid().ToString(); DynamicTableEntity sendEnt = new DynamicTableEntity(); sendEnt.PartitionKey = pk; sendEnt.RowKey = Guid.NewGuid().ToString(); ComplexEntity ent = new ComplexEntity(); ent.String = null; sendEnt.Properties = ent.WriteEntity(null); string value = sendEnt.Properties["String"].StringValue; Assert.AreEqual(EdmType.String, sendEnt.Properties["String"].PropertyType); sendEnt.Properties["String"].StringValue = "helloworld"; Assert.AreEqual(EdmType.String, sendEnt.Properties["String"].PropertyType); sendEnt.Properties["String"].StringValue = null; Assert.AreEqual(EdmType.String, sendEnt.Properties["String"].PropertyType); ent.Binary = null; sendEnt.Properties = ent.WriteEntity(null); byte[] binaryValue = sendEnt.Properties["Binary"].BinaryValue; Assert.AreEqual(EdmType.Binary, sendEnt.Properties["Binary"].PropertyType); sendEnt.Properties["Binary"].BinaryValue = new byte[] { 1, 2 }; Assert.AreEqual(EdmType.Binary, sendEnt.Properties["Binary"].PropertyType); sendEnt.Properties["Binary"].BinaryValue = null; Assert.AreEqual(EdmType.Binary, sendEnt.Properties["Binary"].PropertyType); ent.DateTimeN = null; sendEnt.Properties = ent.WriteEntity(null); DateTime? dateTimeValue = sendEnt.Properties["DateTimeN"].DateTime; Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeN"].PropertyType); sendEnt.Properties["DateTimeN"].DateTime = DateTime.Now; Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeN"].PropertyType); sendEnt.Properties["DateTimeN"].DateTime = null; Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeN"].PropertyType); ent.DateTimeOffsetN = null; sendEnt.Properties = ent.WriteEntity(null); DateTimeOffset? dateTimeOffsetValue = sendEnt.Properties["DateTimeOffsetN"].DateTimeOffsetValue; Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeOffsetN"].PropertyType); sendEnt.Properties["DateTimeOffsetN"].DateTimeOffsetValue = DateTimeOffset.Now; Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeOffsetN"].PropertyType); sendEnt.Properties["DateTimeOffsetN"].DateTimeOffsetValue = null; Assert.AreEqual(EdmType.DateTime, sendEnt.Properties["DateTimeOffsetN"].PropertyType); ent.DoubleN = null; sendEnt.Properties = ent.WriteEntity(null); double? doubleValue = sendEnt.Properties["DoubleN"].DoubleValue; Assert.AreEqual(EdmType.Double, sendEnt.Properties["DoubleN"].PropertyType); sendEnt.Properties["DoubleN"].DoubleValue = 1234.5678; Assert.AreEqual(EdmType.Double, sendEnt.Properties["DoubleN"].PropertyType); sendEnt.Properties["DoubleN"].DoubleValue = null; Assert.AreEqual(EdmType.Double, sendEnt.Properties["DoubleN"].PropertyType); ent.GuidN = null; sendEnt.Properties = ent.WriteEntity(null); Guid? guidValue = sendEnt.Properties["GuidN"].GuidValue; Assert.AreEqual(EdmType.Guid, sendEnt.Properties["GuidN"].PropertyType); sendEnt.Properties["GuidN"].GuidValue = Guid.NewGuid(); Assert.AreEqual(EdmType.Guid, sendEnt.Properties["GuidN"].PropertyType); sendEnt.Properties["GuidN"].GuidValue = null; Assert.AreEqual(EdmType.Guid, sendEnt.Properties["GuidN"].PropertyType); ent.Int32N = null; sendEnt.Properties = ent.WriteEntity(null); int? intValue = sendEnt.Properties["Int32N"].Int32Value; Assert.AreEqual(EdmType.Int32, sendEnt.Properties["Int32N"].PropertyType); sendEnt.Properties["Int32N"].Int32Value = 123; Assert.AreEqual(EdmType.Int32, sendEnt.Properties["Int32N"].PropertyType); sendEnt.Properties["Int32N"].Int32Value = null; Assert.AreEqual(EdmType.Int32, sendEnt.Properties["Int32N"].PropertyType); ent.LongPrimitiveN = null; sendEnt.Properties = ent.WriteEntity(null); long? longValue = sendEnt.Properties["LongPrimitiveN"].Int64Value; Assert.AreEqual(EdmType.Int64, sendEnt.Properties["LongPrimitiveN"].PropertyType); sendEnt.Properties["LongPrimitiveN"].Int64Value = 1234; Assert.AreEqual(EdmType.Int64, sendEnt.Properties["LongPrimitiveN"].PropertyType); sendEnt.Properties["LongPrimitiveN"].Int64Value = null; Assert.AreEqual(EdmType.Int64, sendEnt.Properties["LongPrimitiveN"].PropertyType); ent.BoolN = null; sendEnt.Properties = ent.WriteEntity(null); bool? booleanValue = sendEnt.Properties["BoolN"].BooleanValue; Assert.AreEqual(EdmType.Boolean, sendEnt.Properties["BoolN"].PropertyType); sendEnt.Properties["BoolN"].BooleanValue = true; Assert.AreEqual(EdmType.Boolean, sendEnt.Properties["BoolN"].PropertyType); sendEnt.Properties["BoolN"].BooleanValue = null; Assert.AreEqual(EdmType.Boolean, sendEnt.Properties["BoolN"].PropertyType); }
public void TableEntityCompiledVSReflectionSerializationEqualityTest() { string pk = Guid.NewGuid().ToString(); string rk = Guid.NewGuid().ToString(); ComplexEntity sendEnt = new ComplexEntity(pk, rk); sendEnt.Binary = new Byte[] { 5, 6, 7, 8 }; sendEnt.BinaryNull = null; sendEnt.BinaryPrimitive = new byte[] { 5, 6, 7, 8 }; sendEnt.Bool = true; sendEnt.BoolN = true; sendEnt.BoolNull = null; sendEnt.BoolPrimitive = true; sendEnt.BoolPrimitiveN = true; sendEnt.BoolPrimitiveNull = null; sendEnt.DateTime = DateTime.UtcNow.AddMinutes(1); sendEnt.DateTimeN = DateTime.UtcNow.AddMinutes(1); sendEnt.DateTimeNull = null; sendEnt.DateTimeOffset = DateTimeOffset.Now.AddMinutes(1); sendEnt.DateTimeOffsetN = DateTimeOffset.Now.AddMinutes(1); sendEnt.DateTimeOffsetNull = null; sendEnt.Double = (Double)5678.5678; sendEnt.DoubleN = (Double)5678.5678; sendEnt.DoubleNull = null; sendEnt.DoublePrimitive = (double)5678.5678; sendEnt.DoublePrimitiveN = (double)5678.5678; sendEnt.DoublePrimitiveNull = null; sendEnt.Guid = Guid.NewGuid(); sendEnt.GuidN = Guid.NewGuid(); sendEnt.GuidNull = null; sendEnt.Int32 = 5678; sendEnt.Int32N = 5678; sendEnt.Int32Null = null; sendEnt.Int64 = (long)5678; sendEnt.Int64N = (long)5678; sendEnt.Int64Null = null; sendEnt.IntegerPrimitive = 5678; sendEnt.IntegerPrimitiveN = 5678; sendEnt.IntegerPrimitiveNull = null; sendEnt.LongPrimitive = 5678; sendEnt.LongPrimitiveN = 5678; sendEnt.LongPrimitiveNull = null; sendEnt.String = "ResetTestTotested"; TableEntity.DisableCompiledSerializers = true; var reflectionDict = sendEnt.WriteEntity(null); Assert.IsNull(sendEnt.CompiledWrite); TableEntity.DisableCompiledSerializers = false; var compiledDict = sendEnt.WriteEntity(null); Assert.IsNotNull(sendEnt.CompiledWrite); // Assert Serialized Dictionaries are the same Assert.AreEqual(reflectionDict.Count, compiledDict.Count); foreach (var kvp in reflectionDict) { Assert.IsTrue(compiledDict.ContainsKey(kvp.Key)); Assert.AreEqual(reflectionDict[kvp.Key], compiledDict[kvp.Key]); } }
public void ReflectionBasedSerializationTest() { ComplexEntity ent = new ComplexEntity(); ComplexEntity secondEnt = new ComplexEntity(); secondEnt.ReadEntity(ent.WriteEntity(null), null); ComplexEntity.AssertEquality(ent, secondEnt); }