コード例 #1
0
        public static void SetUp(TestContext context, TestDataInitializer intializer, bool configure = true)
        {
            //bool preventDrop = false;

            if (configure)
            {
                //Configure App
                var config = new ConfigurationBuilder()
                             .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                             .Build();
                config.ConfigureVoat();
                //config["voat:test:preventDatabaseDrop"] != "True"
            }

            FilePather.Instance = new FilePather(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

            //Drop and reseed database
            using (var db = new VoatDataContext())
            {
                intializer.InitializeDatabase(db); //This attempts to create and seed unit test db
            }

            //This causes the voat rules engine to init using config section for load
            var rulesEngine = VoatRulesEngine.Instance;

            //purge redis for unit tests if enabled
            var defaultHandler = CacheConfigurationSettings.Instance.Handlers.FirstOrDefault(x => x.Enabled && x.Type.ToLower().Contains("redis"));

            if (defaultHandler != null)
            {
                var instance = defaultHandler.Construct <ICacheHandler>();
                instance.Purge();
            }
        }