private bool ValidateParameters(string operation, JObject expected, JObject actual) { Log(string.Format("Called {0}, now validating parameters", operation)); List <string> errors = new List <string>(); if (!Utilities.CompareJson(expected, actual, errors)) { foreach (var error in errors) { Log(error); } Log("Parameters passing for the {0} operation failed", operation); Log("Expected: {0}", expected); Log("Actual: {0}", actual); return(false); } else { Log("Parameters passing for the {0} operation succeeded", operation); return(true); } }
private async Task CreateUntypedUpdateTest <TExpectedException>( string testName, string itemToInsertJson, string itemToUpdateJson, bool setUpdatedId = true, bool useStringIdTable = false) where TExpectedException : Exception { Log("### Executing {0}.", testName); var itemToInsert = JObject.Parse(itemToInsertJson); var itemToUpdate = JObject.Parse(itemToUpdateJson); CamelCaseProps(itemToUpdate); var client = GetClient(); var table = client.GetTable(useStringIdTable ? "RoundTripTable" : "IntIdRoundTripTable"); try { var inserted = await table.InsertAsync(itemToInsert); object id = useStringIdTable ? (object)(string)inserted["id"] : (object)(int)inserted["id"]; Log("Inserted item with id {0}", id); if (setUpdatedId) { itemToUpdate["id"] = new JValue(id); } var expectedItem = JObject.Parse(itemToUpdate.ToString()); var updated = await table.UpdateAsync(itemToUpdate); Log("Updated item; now retrieving it to compare with the expected value"); var retrievedItem = await table.LookupAsync(id); Log("Retrieved item"); List <string> errors = new List <string>(); if (!Utilities.CompareJson(expectedItem, retrievedItem, errors)) { foreach (var error in errors) { Log(error); } Assert.Fail("Error, retrieved item is different than the expected value. Expected: " + expectedItem + "; actual:" + retrievedItem); return; } // cleanup await table.DeleteAsync(new JObject(new JProperty("id", id))); if (typeof(TExpectedException) != typeof(ExceptionTypeWhichWillNeverBeThrown)) { Assert.Fail("Error, test should have failed with " + typeof(TExpectedException).FullName + " but succeeded."); } } catch (TExpectedException ex) { Log("Caught expected exception - {0}: {1}", ex.GetType().FullName, ex.Message); } }