Exemplo n.º 1
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
        }