private static void CreateSampleData() { // We create sample data multiple times, so later test wipes out data from previous test. // We do not wipe out certain tables DataUtility.DeleteAllData(BooksApp, exceptEntities: new Type[] { typeof(IDbInfo), typeof(IDbModuleInfo) }); SampleDataGenerator.CreateUnitTestData(BooksApp); }
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 }
private static void CreateSampleData() { var cacheStt = BooksApp.CacheSettings; var saveCacheEnabled = cacheStt.CacheEnabled; cacheStt.CacheEnabled = false; var entitiesToClear = BooksApp.Model.GetAllEntityTypes().ToList(); // We create sample data multiple times, so later test wipes out data from previous test. // We do not wipe out certain tables TestUtil.DeleteAllData(BooksApp, exceptEntities: new Type[] { typeof(IErrorLog), typeof(IDbInfo), typeof(IDbModuleInfo) }); if (BooksApp.LoggingApp != null) { TestUtil.DeleteAllData(BooksApp.LoggingApp, exceptEntities: new Type[] { typeof(IErrorLog), typeof(IDbInfo), typeof(IDbModuleInfo), typeof(IDbUpgradeBatch), typeof(IDbUpgradeScript) }); } SampleDataGenerator.CreateUnitTestData(BooksApp); cacheStt.CacheEnabled = saveCacheEnabled; }
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); } }; }
private static void CreateSampleData() { DataUtility.DeleteAllData(BooksApp, exceptEntities: new Type[] { typeof(IDbInfo), typeof(IDbModuleInfo) }); SampleDataGenerator.CreateUnitTestData(BooksApp); }