Exemplo n.º 1
0
        public void Run(dynamic fixture, bool rollback = false)
        {
            if (!rollback)
            {
                var reset = Util.GetValue(fixture, "Reset");
                if (reset != null)
                {
                    rollbacks.Add(() => Run((Type)reset));
                }
                else if (fixture.GetType().GetMethod("Rollback") != null)
                {
                    rollbacks.Add(() => Run(fixture, rollback: true));
                }
            }

            var             local = !(fixture is ServerFixture);
            ISessionFactory factory;

            if (local)
            {
                if (IntegrationSetup.Factory == null)
                {
                    factory = GetFactory();
                    var config = new Config.Config();
                    config.RootDir = Common.Tools.FileHelper.MakeRooted(config.RootDir);
                    Util.SetValue(fixture, "Config", IntegrationSetup.clientConfig);
                    Util.SetValue(fixture, "Verbose", true);
                }
                else
                {
                    factory = IntegrationSetup.Factory;
                    Util.SetValue(fixture, "Config", IntegrationSetup.clientConfig);
                }
            }
            else
            {
                if (Setup.SessionFactory == null)
                {
                    IntegrationSetup.serviceConfig = Application.ReadConfig();
                    var development = new Development();
                    development.BasePath = Environment.CurrentDirectory;
                    development.Run(IntegrationSetup.serviceConfig);
                    Setup.SessionFactory = DbHelper.ServerNHConfig("local");
                }
                fixture.Config  = IntegrationSetup.serviceConfig;
                fixture.Verbose = verbose;
                factory         = Setup.SessionFactory;
            }

            using (var session = factory.OpenSession()) {
                using (var transaction = session.BeginTransaction()) {
                    if (rollback)
                    {
                        fixture.Rollback(session);
                    }
                    else
                    {
                        fixture.Execute(session);
                    }
                    transaction.Commit();
                }
            }
        }