Beispiel #1
0
        public AssertInfo Run()
        {
            MyClient t = ClientFactory.CreateTestClient(Setting.baseUrl, new HttpClient(), token);

            string[] subStrings = api.Split('/');

            string funcName = "";

            string suffix = "Async";

            foreach (string s in subStrings)
            {
                funcName += Utils.toTitleCase(s);
            }

            MethodInfo methodInfo = typeof(MyClient).GetMethod(funcName + method.ToString() + suffix) ?? typeof(MyClient).GetMethod(funcName + suffix);

            Console.WriteLine(methodInfo.Name);


            List <Type> pars = methodInfo.GetParameters().Select(p => p.ParameterType).ToList();

            dynamic tasks = methodInfo.Invoke(t, Utils.MultipleParamParse(inputs, pars).ToArray());

            dynamic results = tasks.GetAwaiter().GetResult();

            return(AssertInfo.SingleCaseAssert(expectations, results, inputs, api, method.ToString()));
        }
Beispiel #2
0
        public static AssertInfo SingleCaseAssert(string expectation, dynamic result, List <string> input, string api, string method)
        {
            AssertInfo ret = new AssertInfo()
            {
                expect      = expectation,
                output      = JsonConvert.SerializeObject(result, Formatting.Indented),
                requestBody = JsonConvert.SerializeObject(new
                {
                    api,
                    method,
                    input
                }, Formatting.Indented)
            };

            if (result == null && expectation == null)
            {
                ret.assert = "succeed";
                return(ret);
            }
            if (result == null || expectation == null)
            {
                ret.assert   = "fail";
                ret.diffInfo = "";
                return(ret);
            }

            //schema matching
            //JSchemaGenerator generator = new JSchemaGenerator();
            //generator.SchemaIdGenerationHandling = SchemaIdGenerationHandling.TypeName;
            //Console.WriteLine(result[0].GetType());
            //JSchema schema = generator.Generate(typeof(Contracts.Offering));
            //string jsonSchema = schema.ToString();


            //content matching
            JsonSerializer jsonSerializer = JsonSerializer.Create(Setting.jsonSetting);
            JToken         exp            = JToken.FromObject(JsonConvert.DeserializeObject(expectation, result.GetType(), Setting.jsonSetting), jsonSerializer);
            JToken         output         = JToken.FromObject(result, jsonSerializer);

            JToken patch = Utils.JsonDeepCompare(exp, output);

            ret.diffInfo = patch?.ToString();
            ret.assert   = patch == null? "succeed" : "fail";

            Console.WriteLine(ret.diffInfo);
            return(ret);
        }