public virtual void OnAfterTest() { if (TestContext.CurrentContext.Result.FailCount > 0) { var ctx = CustomTestContext.Get(); var trace = ctx.Get <StringBuilder>(CustomTestContext.TRACE); if (trace != null && ctx.Get <bool>(CustomTestContext.LIMITED)) { // we need to set ErrorInfo.Message element text // because Azure displays only ErrorInfo node data TestExecutionContext.CurrentContext.CurrentResult.SetResult( TestExecutionContext.CurrentContext.CurrentResult.ResultState, TestExecutionContext.CurrentContext.CurrentResult.Message + "\r\n" + trace.ToString(), TestExecutionContext.CurrentContext.CurrentResult.StackTrace); } } CustomTestContext.Release(); }
public DisableBaseline(string reason, bool disable = true) { _ctx = CustomTestContext.Get(); _oldState = _ctx.Get <bool>(CustomTestContext.BASELINE_DISABLED); _ctx.Set(CustomTestContext.BASELINE_DISABLED, disable); }
public DisableLogging() { _ctx = CustomTestContext.Get(); _oldState = _ctx.Get <bool>(CustomTestContext.TRACE_DISABLED); _ctx.Set(CustomTestContext.TRACE_DISABLED, true); }
static TestBase() { Console.WriteLine("Tests started in {0}...", Environment.CurrentDirectory); Console.WriteLine("CLR Version: {0}...", Environment.Version); var traceCount = 0; DataConnection.TurnTraceSwitchOn(TraceLevel.Info); DataConnection.WriteTraceLine = (message, name, level) => { var ctx = CustomTestContext.Get(); var trace = ctx.Get <StringBuilder>(CustomTestContext.TRACE); if (trace == null) { trace = new StringBuilder(); ctx.Set(CustomTestContext.TRACE, trace); } trace.AppendLine($"{name}: {message}"); if (traceCount < TRACES_LIMIT || level == TraceLevel.Error) { ctx.Set(CustomTestContext.LIMITED, true); Console.WriteLine("{0}: {1}", name, message); Debug.WriteLine(message, name); } traceCount++; }; // Configuration.RetryPolicy.Factory = db => new Retry(); Configuration.Linq.TraceMapperExpression = false; // Configuration.Linq.GenerateExpressionTest = true; var assemblyPath = typeof(TestBase).Assembly.GetPath(); #if NET46 try { SqlServerTypes.Utilities.LoadNativeAssemblies(assemblyPath); } catch // this can fail during tests discovering with NUnitTestAdapter { } #endif Environment.CurrentDirectory = assemblyPath; var dataProvidersJsonFile = GetFilePath(assemblyPath, @"DataProviders.json"); var userDataProvidersJsonFile = GetFilePath(assemblyPath, @"UserDataProviders.json"); var dataProvidersJson = File.ReadAllText(dataProvidersJsonFile); var userDataProvidersJson = File.Exists(userDataProvidersJsonFile) ? File.ReadAllText(userDataProvidersJsonFile) : null; #if NETCOREAPP2_1 var configName = "CORE21"; #elif NETCOREAPP3_1 var configName = "CORE31"; #elif NET46 var configName = "NET46"; #else var configName = ""; #error Unknown framework #endif #if AZURE Console.WriteLine("Azure configuration detected."); configName += ".Azure"; #endif var testSettings = SettingsReader.Deserialize(configName, dataProvidersJson, userDataProvidersJson); var databasePath = Path.GetFullPath(Path.Combine("Database")); var dataPath = Path.Combine(databasePath, "Data"); if (Directory.Exists(dataPath)) { Directory.Delete(dataPath, true); } Directory.CreateDirectory(dataPath); foreach (var file in Directory.GetFiles(databasePath, "*.*")) { var destination = Path.Combine(dataPath, Path.GetFileName(file)); Console.WriteLine("{0} => {1}", file, destination); File.Copy(file, destination, true); } UserProviders = new HashSet <string>(testSettings.Providers ?? Array <string> .Empty, StringComparer.OrdinalIgnoreCase); SkipCategories = new HashSet <string>(testSettings.Skip ?? Array <string> .Empty, StringComparer.OrdinalIgnoreCase); var logLevel = testSettings.TraceLevel; var traceLevel = TraceLevel.Info; if (!string.IsNullOrEmpty(logLevel)) { if (!Enum.TryParse(logLevel, true, out traceLevel)) { traceLevel = TraceLevel.Info; } } if (!string.IsNullOrEmpty(testSettings.NoLinqService)) { DataSourcesBaseAttribute.NoLinqService = ConvertTo <bool> .From(testSettings.NoLinqService); } DataConnection.TurnTraceSwitchOn(traceLevel); Console.WriteLine("Connection strings:"); #if !NET46 DataConnection.DefaultSettings = TxtSettings.Instance; TxtSettings.Instance.DefaultConfiguration = "SQLiteMs"; foreach (var provider in testSettings.Connections /*.Where(c => UserProviders.Contains(c.Key))*/) { if (string.IsNullOrWhiteSpace(provider.Value.ConnectionString)) { throw new InvalidOperationException("ConnectionString should be provided"); } Console.WriteLine($"\tName=\"{provider.Key}\", Provider=\"{provider.Value.Provider}\", ConnectionString=\"{provider.Value.ConnectionString}\""); TxtSettings.Instance.AddConnectionString( provider.Key, provider.Value.Provider ?? "", provider.Value.ConnectionString); } #else foreach (var provider in testSettings.Connections) { Console.WriteLine($"\tName=\"{provider.Key}\", Provider=\"{provider.Value.Provider}\", ConnectionString=\"{provider.Value.ConnectionString}\""); DataConnection.AddOrSetConfiguration( provider.Key, provider.Value.ConnectionString, provider.Value.Provider ?? ""); } #endif Console.WriteLine("Providers:"); foreach (var userProvider in UserProviders) { Console.WriteLine($"\t{userProvider}"); } DefaultProvider = testSettings.DefaultConfiguration; if (!DefaultProvider.IsNullOrEmpty()) { DataConnection.DefaultConfiguration = DefaultProvider; #if !NET46 TxtSettings.Instance.DefaultConfiguration = DefaultProvider; #endif } #if NET46 LinqService.TypeResolver = str => { return(str switch { "Tests.Model.Gender" => typeof(Gender), "Tests.Model.Person" => typeof(Person), _ => null, }); };