private static async Task TestFileToObject <T>(string filePath, List <string> ignoreProperties = null) { var listener = new EnumValueTraceListener(); Trace.Listeners.Add(listener); var path = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName; string json; try { var file = File.OpenRead(Path.Combine(path, filePath)); using var reader = new StreamReader(file); json = await reader.ReadToEndAsync(); } catch (FileNotFoundException) { throw; } var result = JsonConvert.DeserializeObject <T>(json); JsonToObjectComparer <IBitfinexSocketClient> .ProcessData("", result, json, ignoreProperties : new Dictionary <string, List <string> > { { "", ignoreProperties ?? new List <string>() } }); Trace.Listeners.Remove(listener); }
public async Task ProcessSubject <K>( string folderPrefix, Func <T, K> getSubject, string[] parametersToSetNull = null, Dictionary <string, string> useNestedJsonPropertyForCompare = null, Dictionary <string, List <string> > ignoreProperties = null, List <string> takeFirstItemForCompare = null) { var listener = new EnumValueTraceListener(); Trace.Listeners.Add(listener); var methods = typeof(K).GetMethods(); var callResultMethods = methods.Where(m => m.Name.EndsWith("Async")).ToList(); var skippedMethods = new List <string>(); foreach (var method in callResultMethods) { var path = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName; FileStream file = null; try { file = File.OpenRead(Path.Combine(path, $"JsonResponses", folderPrefix, $"{method.Name}.txt")); } catch (FileNotFoundException) { skippedMethods.Add(method.Name); continue; } var buffer = new byte[file.Length]; await file.ReadAsync(buffer, 0, buffer.Length); file.Close(); var json = Encoding.UTF8.GetString(buffer); var client = _clientFunc(json); var parameters = method.GetParameters(); var input = new List <object>(); foreach (var parameter in parameters) { if (parametersToSetNull?.Contains(parameter.Name) == true) { input.Add(null); } else { input.Add(TestHelpers.GetTestValue(parameter.ParameterType, 1)); } } // act var result = (CallResult)await TestHelpers.InvokeAsync(method, getSubject(client), input.ToArray()); // asset Assert.Null(result.Error, method.Name); var resultData = result.GetType().GetProperty("Data", BindingFlags.Public | BindingFlags.Instance).GetValue(result); ProcessData(method.Name, resultData, json, parametersToSetNull, useNestedJsonPropertyForCompare, ignoreProperties, takeFirstItemForCompare); } if (skippedMethods.Any()) { Debug.WriteLine("Skipped methods:"); } foreach (var method in skippedMethods) { Debug.WriteLine(method); } Trace.Listeners.Remove(listener); }