public static void InitImpl() { if (BooksApp != null) { return; } LogFilePath = ConfigurationManager.AppSettings["LogFilePath"]; DeleteLocalLogFile(); var protectedSection = (NameValueCollection)ConfigurationManager.GetSection("protected"); var loginCryptoKey = protectedSection["LoginInfoCryptoKey"]; var connString = protectedSection["MsSqlConnectionString"]; var logConnString = protectedSection["MsSqlLogConnectionString"]; BooksApp = new BooksEntityApp(loginCryptoKey); //Add mock email/sms service NotificationListener = new NotificationListener(BooksApp, blockAll: true); //Set magic captcha in login settings, so we can pass captcha in unit tests var loginStt = BooksApp.GetConfig <Vita.Modules.Login.LoginModuleSettings>(); loginStt.MagicCaptcha = "Magic"; BooksApp.Init(); //connect to database var driver = MsSqlDbDriver.Create(connString); var dbOptions = MsSqlDbDriver.DefaultMsSqlDbOptions; var dbSettings = new DbSettings(driver, dbOptions, connString, upgradeMode: DbUpgradeMode.Always); // schemas); var resetDb = ConfigurationManager.AppSettings["ResetDatabase"] == "true"; if (resetDb) { Vita.UnitTests.Common.TestUtil.DropSchemaObjects(dbSettings); } BooksApp.ConnectTo(dbSettings); var logDbSettings = new DbSettings(driver, dbOptions, logConnString); BooksApp.LoggingApp.ConnectTo(logDbSettings); BooksApp.LoggingApp.LogPath = LogFilePath; TestUtil.DeleteAllData(BooksApp, exceptEntities: new [] { typeof(IDbInfo), typeof(IDbModuleInfo) }); TestUtil.DeleteAllData(BooksApp.LoggingApp); SampleDataGenerator.CreateUnitTestData(BooksApp); // Start service var serviceUrl = ConfigurationManager.AppSettings["ServiceUrl"]; var jsonNames = ConfigurationManager.AppSettings["JsonStyleNames"] == "true"; var jsonMappingMode = jsonNames ? ApiNameMapping.UnderscoreAllLower : ApiNameMapping.Default; StartService(serviceUrl, jsonMappingMode); // create client var clientContext = new OperationContext(BooksApp); // change options to None to disable logging of test client calls Client = new WebApiClient(clientContext, serviceUrl, clientName: "TestClient", nameMapping: jsonMappingMode, options: ClientOptions.EnableLog, badRequestContentType: typeof(List <ClientFault>)); WebApiClient.SharedHttpClientHandler.AllowAutoRedirect = false; //we need it for Redirect test }
public static void InitApp() { Util.Check(!_initFailed, "App initialization failed. Cannot run tests. See other tests output for failure details."); if (BooksApp != null) { return; } try { //force randomization of schema update SQLs, to test that they will put in correct order anyway DbModelUpdater.Test_RandomizeInitialSchemaUpdatesOrder = true; //Check if Reset was called; if Driver is null, we are running in Test Explorer mode if (Driver == null) { SetupForTestExplorerMode(); } //Setup model, initialize Books module, create database model, update schema ------------------------------------------------- BooksApp = new BooksEntityApp(LoginCryptoKey); BooksApp.LogPath = LogFilePath; BooksApp.SystemLogPath = ActivationLogFilePath; BooksApp.CacheSettings.CacheEnabled = CacheEnabled; NotificationListener = new NotificationListener(BooksApp, blockAll: true); //SmtpMock for testing password reset and other processes BooksApp.Init(); //Reset Db and drop schema objects; first set schema list var resetDb = ConfigurationManager.AppSettings["ResetDatabase"] == "true"; if (resetDb) { DbSettings.SetSchemas(BooksApp.Areas.Select(a => a.Name)); Vita.UnitTests.Common.TestUtil.DropSchemaObjects(DbSettings); } //Now connect the main app BooksApp.ConnectTo(DbSettings); //if we have logging app as a separate app - we need to connect it too. // NOTE: good pracice to connect LoggingApp before we connect the main app, so it can log main database update scripts // but it should work anyway. var logDbSettings = new DbSettings(Driver, DbSettings.ModelConfig.Options, LogConnectionString); BooksApp.LoggingApp.ConnectTo(logDbSettings); CreateSampleData(); } catch (ClientFaultException cfx) { Debug.WriteLine("Validation errors: \r\n" + cfx.ToString()); throw; } catch (Exception sx) { _initFailed = true; //Unit test framework shows only ex message, not details; let's write specifics into debug output - it will be shown in test failure report Debug.WriteLine("app init encountered errors: "); Debug.WriteLine(sx.ToLogString()); throw; } }
private BooksEntityApp CreateBooksEntityApp(string connString) { // If we are running WebTests, the BooksApp is already setup if (BooksEntityApp.Instance != null) { return(BooksEntityApp.Instance); } var booksApp = new BooksEntityApp(); booksApp.Init(); //connect to db var driver = new MsSqlDbDriver(); var dbOptions = driver.GetDefaultOptions(); var dbSettings = new DbSettings(driver, dbOptions, connString, upgradeMode: DbUpgradeMode.Always); booksApp.ConnectTo(dbSettings); return(booksApp); }
public static BooksEntityApp CreateConfigureBooksApp() { // set up application var protectedSection = (NameValueCollection)ConfigurationManager.GetSection("protected"); var cryptoKey = protectedSection["LoginInfoCryptoKey"]; var booksApp = new BooksEntityApp(cryptoKey); booksApp.Init(); var connString = protectedSection["MsSqlConnectionString"]; var logConnString = protectedSection["MsSqlLogConnectionString"]; var driver = MsSqlDbDriver.Create(connString); var dbOptions = MsSqlDbDriver.DefaultMsSqlDbOptions; var logDbSettings = new DbSettings(driver, dbOptions, logConnString); booksApp.LoggingApp.ConnectTo(logDbSettings); var dbSettings = new DbSettings(driver, dbOptions, connString, upgradeMode: DbUpgradeMode.Always); booksApp.ConnectTo(dbSettings); //Web Api WebHelper.ConfigureWebApi(GlobalConfiguration.Configuration, booksApp, logLevel: Entities.Services.LogLevel.Details); /* var hc = GlobalConfiguration.Configuration; var webH = hc.MessageHandlers.First(h => h is WebCallContextHandler); hc.MessageHandlers.Remove(webH); */ return booksApp; }
public static BooksEntityApp CreateConfigureBooksApp() { // set up application var protectedSection = (NameValueCollection)ConfigurationManager.GetSection("protected"); var cryptoKey = protectedSection["LoginInfoCryptoKey"]; var booksApp = new BooksEntityApp(cryptoKey); booksApp.Init(); var connString = protectedSection["MsSqlConnectionString"]; var logConnString = protectedSection["MsSqlLogConnectionString"]; var driver = MsSqlDbDriver.Create(connString); var dbOptions = MsSqlDbDriver.DefaultMsSqlDbOptions; var logDbSettings = new DbSettings(driver, dbOptions, logConnString); booksApp.LoggingApp.ConnectTo(logDbSettings); var dbSettings = new DbSettings(driver, dbOptions, connString, upgradeMode: DbUpgradeMode.Always); booksApp.ConnectTo(dbSettings); //Web Api WebHelper.ConfigureWebApi(GlobalConfiguration.Configuration, booksApp, logLevel: Entities.Services.LogLevel.Details ); return(booksApp); }
public static void InitImpl() { if (BooksApp != null) { return; } LoadAppConfig(); LogFilePath = AppConfiguration["LogFilePath"]; if (File.Exists(LogFilePath)) { File.Delete(LogFilePath); } BooksApp = new BooksEntityApp(); BooksApp.LogPath = LogFilePath; //Add mock email/sms service // NotificationListener = new NotificationListener(BooksApp, blockAll: true); // Setup mock messaging service LoginMessagingService = new MockLoginMessagingService(); var loginConfig = BooksApp.GetConfig <Modules.Login.LoginModuleSettings>(); loginConfig.MessagingService = LoginMessagingService; BooksApp.Init(); //connect to database var driver = new MsSqlDbDriver(); var dbOptions = MsSqlDbDriver.DefaultMsSqlDbOptions; var connString = AppConfiguration["MsSqlConnectionString"]; var dbSettings = new DbSettings(driver, dbOptions, connString, upgradeMode: DbUpgradeMode.Always); // schemas); BooksApp.ConnectTo(dbSettings); // Logging app LoggingApp = new DbLoggingEntityApp(); LoggingApp.ListenTo(BooksApp); var logConnString = AppConfiguration["MsSqlLogConnectionString"]; var logDbSettings = new DbSettings(driver, dbOptions, logConnString, upgradeMode: DbUpgradeMode.Always); // schemas); LoggingApp.ConnectTo(logDbSettings); // create sample data DataUtility.DeleteAllData(BooksApp, exceptEntities: new Type[] { typeof(IDbInfo), typeof(IDbModuleInfo) }); SampleDataGenerator.CreateUnitTestData(BooksApp); // Start service var serviceUrl = AppConfiguration["ServiceUrl"]; StartService(serviceUrl); // create client var useXml = false; if (useXml) { var clientSettings = new RestClientSettings(serviceUrl, serializer: new XmlContentSerializer(), badRequestContentType: typeof(string)); // typeof(List<ClientFault>)); Client = new RestClient(clientSettings); } else { Client = new RestClient(serviceUrl, badRequestContentType: typeof(List <ClientFault>)); //json, very simple setup } RestClient.SharedHttpClientHandler.AllowAutoRedirect = false; //we need it for Redirect test // Setup handler converting BadRequestException into ClientFaultException, with list of faults already converted Client.Settings.Events.ReceivedError += (s, e) => { if (e.CallData.Exception is BadRequestException bre) { e.CallData.Exception = new ClientFaultException((IList <ClientFault>)bre.Details); } }; }
public static void InitApp() { Util.Check(!_initFailed, "App initialization failed. Cannot run tests. See other tests output for failure details."); if (BooksApp != null) { return; } try { //force randomization of schema update SQLs, to test that they will be put in correct order anyway DbModelUpdater.Test_RandomizeInitialSchemaUpdatesOrder = true; //Check if Reset was called; if Driver is null, we are running in Test Explorer mode if (Driver == null) { SetupForTestExplorerMode(); } if (ServerType == DbServerType.SQLite) { DeleteSqliteDbFile("VitaBooksSQLite"); } //Setup model, initialize Books module, create database model, update schema ------------------------------------------------- BooksApp = new BooksEntityApp(); BooksApp.EntityClassProvider = Vita.Entities.Emit.EntityClassEmitter.CreateEntityClassProvider(); BooksApp.LogPath = LogFilePath; BooksApp.ActivationLogPath = ActivationLogFilePath; BooksApp.Init(); // Oracle - uncomment this to see tablespace use, but you must pre-create the tablespace in SQL-Developer /* * if(ServerType == DbServerType.Oracle) * foreach(var area in BooksApp.Areas) * area.OracleTableSpace = "Books"; */ // Setup mock messaging service LoginMessagingService = new MockLoginMessagingService(); var loginConfig = BooksApp.GetConfig <Modules.Login.LoginModuleSettings>(); loginConfig.MessagingService = LoginMessagingService; // for SQLite- drop and copy database //Reset Db and drop schema objects; first set schema list var resetDb = AppSettings["ResetDatabase"] == "true"; if (resetDb) { DataUtility.DropSchemaObjects(BooksApp, DbSettings); } //Now connect the main app BooksApp.ConnectTo(DbSettings); //if we have logging app as a separate app - we need to connect it too. // NOTE: good pracice to connect LoggingApp before we connect the main app, so it can log main database update scripts // but it should work anyway. //var logDbSettings = new DbSettings(Driver, DbSettings.ModelConfig.Options, LogConnectionString); //BooksApp.LoggingApp.ConnectTo(logDbSettings); CreateSampleData(); } catch (ClientFaultException cfx) { Debug.WriteLine("Validation errors: \r\n" + cfx.ToString()); _initFailed = true; throw; } catch (Exception sx) { _initFailed = true; //Unit test framework shows only ex message, not details; let's write specifics into debug output - it will be shown in test failure report Debug.WriteLine("app init encountered errors: "); Debug.WriteLine(sx.ToLogString()); throw; } }