private static ZumoTest CreateSimpleTypedRoundTripTest <TExpectedException>( string testName, RoundTripTestType type, object value) where TExpectedException : Exception { return(new ZumoTest(testName, async delegate(ZumoTest test) { var client = ZumoTestGlobals.Instance.Client; var table = client.GetTable <RoundTripTableItem>(); var item = new RoundTripTableItem(); switch (type) { case RoundTripTestType.Bool: item.Bool1 = (bool?)value; break; case RoundTripTestType.ComplexWithConverter: item.ComplexType1 = (ComplexType[])value; break; case RoundTripTestType.ComplexWithCustomSerialization: item.ComplexType2 = (ComplexType2)value; break; case RoundTripTestType.Date: item.Date1 = (DateTime?)value; break; case RoundTripTestType.Double: item.Double1 = (double)value; break; case RoundTripTestType.Enum: item.EnumType = (EnumType)value; break; case RoundTripTestType.Int: item.Int1 = (int)value; break; case RoundTripTestType.Long: item.Long1 = (long)value; break; case RoundTripTestType.String: item.String1 = (string)value; break; case RoundTripTestType.Id: item.Id = (int)value; break; default: throw new ArgumentException("Invalid type"); } RoundTripTableItem originalItem = item.Clone(); try { await table.InsertAsync(item); test.AddLog("Inserted item, id = {0}", item.Id); if (item.Id <= 0) { test.AddLog("Error, insert didn't succeed (id == 0)"); return false; } RoundTripTableItem roundTripped = await table.LookupAsync(item.Id); test.AddLog("Retrieved the item from the service"); if (!originalItem.Equals(roundTripped)) { test.AddLog("Round-tripped item is different! Expected: {0}; actual: {1}", originalItem, roundTripped); return false; } if (type == RoundTripTestType.String && item.String1 != null && item.String1.Length < 50) { test.AddLog("Now querying the table for the item (validating characters on query)"); var queried = await table.Where(i => i.Id > (item.Id - 40) && i.String1 == item.String1).ToListAsync(); var lastItem = queried.Where(i => i.Id == item.Id).First(); if (originalItem.Equals(lastItem)) { test.AddLog("Query for item succeeded"); } else { test.AddLog("Round-tripped (queried) item is different! Expected: {0}; actual: {1}", originalItem, lastItem); return false; } } if (typeof(TExpectedException) == typeof(ExceptionTypeWhichWillNeverBeThrown)) { return true; } else { test.AddLog("Error, test should have failed with {0}, but succeeded.", typeof(TExpectedException).FullName); return false; } } catch (TExpectedException ex) { test.AddLog("Caught expected exception - {0}: {1}", ex.GetType().FullName, ex.Message); return true; } })); }
private static ZumoTest CreateSimpleTypedRoundTripTest(string testName, RoundTripTestType type, object value) { return(CreateSimpleTypedRoundTripTest <ExceptionTypeWhichWillNeverBeThrown>(testName, type, value)); }