Example #1
0
        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();
            //Reset Db and drop schema objects
            var resetDb = ConfigurationManager.AppSettings["ResetDatabase"] == "true";
            if(resetDb)
              Vita.UnitTests.Common.TestUtil.DropSchemaObjects(DbSettings);
            //Setup model, initialize Books module, create database model, update schema -------------------------------------------------
            BooksApp = new BooksEntityApp(LoginCryptoKey);
            BooksApp.LogPath = LogFilePath;
            BooksApp.ActivationLogPath = ActivationLogFilePath;
            BooksApp.CacheSettings.CacheEnabled = CacheEnabled;
            NotificationListener = new NotificationListener(BooksApp, blockAll: true);   //SmtpMock for testing password reset and other processes
            BooksApp.Init();
            //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);

            Thread.Yield();
            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;
              }
        }
Example #2
0
        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);
              var serviceUrl = ConfigurationManager.AppSettings["ServiceUrl"];
              StartService(serviceUrl);
              Client = new WebApiClient(serviceUrl);
              Client.InnerHandler.AllowAutoRedirect = false; //we need it for Redirect test
        }