public void RunTests() { SimpleLog.SetLogDir("D:\\test", true); var classes = GetClassTypesWith <ApiTest>(true); SimpleLog.Info("API Testing started...."); foreach (var type in classes) { SimpleLog.Info("UseCases in class " + type.Name + " is invoked"); object classInstance = type.Assembly.CreateInstance(type.FullName); var InitializeMethods = type.GetMethods().Where(m => m.GetCustomAttributes(typeof(ApiClassInitialize), false).Length > 0).ToArray(); foreach (var testmethod in InitializeMethods) { object[] obj = new object[] { link }; testmethod.Invoke(classInstance, obj); } var methods = type.GetMethods().Where(m => m.GetCustomAttributes(typeof(ApiUseCase), false).Length > 0).ToArray(); foreach (var testmethod in methods) { SimpleLog.Info("Usecase " + testmethod.Name + " is invoked"); TestInfo testinfo = new TestInfo(); try { testinfo.ClassName = classInstance.GetType().ToString(); testinfo.MethodName = testmethod.Name; testmethod.Invoke(classInstance, null); testinfo.TestSuccess = true; SimpleLog.Info("Usecase Successfully completed"); } catch (TargetInvocationException e) { SimpleLog.Info("Usecase Failed"); testinfo.TestSuccess = false; testinfo.errorMessage = e.InnerException.Message; SimpleLog.Log(e.InnerException); }catch (Exception e) { SimpleLog.Info("Usecase Failed"); testinfo.TestSuccess = false; testinfo.errorMessage = e.Message; SimpleLog.Log(e); } TestResults.Add(testinfo); } } SimpleLog.ShowLogFile(); }
private static void Configure(string executingAssemblyFileName) { var logLevelString = ConfigurationManager.AppSettings["LogLevel"]; var logLocation = ConfigurationManager.AppSettings["LogLocation"]; if (logLocation != null) { SimpleLog.SetLogDir(logLocation, true); } if (logLevelString != null && Enum.TryParse(logLevelString, true, out SimpleLog.Severity logLevel)) { SimpleLog.LogLevel = logLevel; } else { SimpleLog.LogLevel = SimpleLog.Severity.Error; } SimpleLog.BackgroundTaskDisabled = true; SimpleLog.Prefix = $"{executingAssemblyFileName}."; }