public static bool Equal(APICallLogEntry expected, APICallLogEntry observed) { if (expected.MethodName != observed.MethodName) return false; if (expected.Arguments.Length != observed.Arguments.Length) return false; for (int i = 0; i < expected.Arguments.Length; i++) { if (expected.Arguments[i].Key != observed.Arguments[i].Key) { return false; } string expectedValue = expected.Arguments[i].Value; string observedValue = observed.Arguments[i].Value; if (expectedValue != observedValue) { double temp1, temp2; if (double.TryParse(expectedValue, out temp1) && double.TryParse(observedValue, out temp2)) return temp1 == temp2; // TODO: when else can we ignore this? return false; } } return true; }
protected void RetrieveAPICallLog() { string directoryPath = Path.Combine(Workspace.DataService.DestinationFolder, APICallLog.DirectoryName); string markerFilePath = Path.Combine(directoryPath, APICallLog.MarkerFileName); if (!this.LogAPICalls) { AstoriaTestLog.IsFalse(TrustedMethods.IsFileExists(markerFilePath), "Marker file should have been cleaned up by prior request"); return; } IOUtil.EnsureFileDeleted(markerFilePath); this.APICallLogXml = new XElement("APICallLog"); this.APICallLogEntries = new List <APICallLogEntry>(); string[] files; // re-query each time, in case any new files were created while ((files = Directory.GetFiles(directoryPath, "*.xml")).Length > 0) { foreach (string filePath in files.OrderBy(f => f)) //NEED TO BE IN CORRECT ORDER { string text = File.ReadAllText(filePath); XElement element = null; try { element = XElement.Parse(text); } catch { } if (element != null) { this.APICallLogXml.Add(element); this.APICallLogEntries.Add(APICallLogEntry.FromXml(element)); } else { this.APICallLogXml.Add(text); this.APICallLogEntries.Add(new APICallLogEntry(text, new KeyValuePair <string, string> [0])); //this will hopefully ALWAYS fail to compare } IOUtil.EnsureFileDeleted(filePath); } } //if (APICallLogEntries.Any(e => e.MethodName == APICallLog.UnterminatedCall)) //{ // foreach (APICallLogEntry entry in APICallLogEntries) // AstoriaTestLog.WriteLine("(Observed) - " + entry.ToString()); // AstoriaTestLog.FailAndContinue(new Microsoft.Test.ModuleCore.TestFailedException("Un-terminated API calls detected")); //} }
public static bool Equal(APICallLogEntry expected, APICallLogEntry observed) { if (expected.MethodName != observed.MethodName) { return(false); } if (expected.Arguments.Length != observed.Arguments.Length) { return(false); } for (int i = 0; i < expected.Arguments.Length; i++) { if (expected.Arguments[i].Key != observed.Arguments[i].Key) { return(false); } string expectedValue = expected.Arguments[i].Value; string observedValue = observed.Arguments[i].Value; if (expectedValue != observedValue) { double temp1, temp2; if (double.TryParse(expectedValue, out temp1) && double.TryParse(observedValue, out temp2)) { return(temp1 == temp2); } // TODO: when else can we ignore this? return(false); } } return(true); }