예제 #1
0
        public DrawerControllerTests() : base(new ApiTestSetup <ISession>(
                                                  Startup.GetContainer(),
                                                  WebApiConfig.Register,
                                                  builder =>
        {
            builder.RegisterType <LocalDb>().AsSelf();      // this needs to be registered so it's Disposed properly

            // changing the ISession to a singleton so that the two ISession Resolve() calls
            // produce the same instance such that the transaction includes all test activity.
            builder.Register(context =>
            {
                var connString = context.Resolve <LocalDb>().OpenConnection().ConnectionString;
                // migrate empty db
                Program.Main(new[] { connString });

                return(NhibernateConfig.CreateSessionFactory(connString).OpenSession());
            })
            .As <ISession>()
            .SingleInstance();
        },
                                                  session => session.BeginTransaction(),
                                                  session => session.Transaction.Dispose(), // tear down transaction to release locks
                                                  session =>
        {
            NhibernateConfig.CompleteRequest(session);
            session.Clear();     // this is to ensure we don't get ghost results from the NHibernate cache
        }))
        { }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddMvc(o => o.InputFormatters.Insert(0, new RawRequestBodyFormatter()));


            services.AddMvc(options =>
            {
                options.InputFormatters.Add(new TextPlainInputFormatter());
            });
            var nc = new NhibernateConfig(Configuration);

            services.AddSingleton <IInvoiceRepository, InvoiceRepository>(d =>
            {
                return(new InvoiceRepository(nc.Session));
            });

            services.AddSingleton <IItemRepository, ItemRepository>(d =>
            {
                return(new ItemRepository(nc.Session));
            });
            services.AddSingleton <IStoreRepository, StoreRepository>(d => {
                return(new StoreRepository(nc.Session));
            });
            services.AddSingleton <IUserRepository, UserRepository>(d => {
                return(new UserRepository(nc.Session));
            });
        }
 public HomeControllerTests()
     : base(new MvcTestSetup <ISession>(
                ContainerConfig.BuildContainer(),
                session => session.BeginTransaction(),
                session => session.Transaction.Dispose(), // tear down transaction to release locks
                session =>
 {
     NhibernateConfig.CompleteRequest(session);
     session.Clear();            // this is to ensure we don't get ghost results from the NHibernate cache
 }
                ))
 { }
예제 #4
0
        public Teste Inserir(Teste teste)
        {
            using (var session = NhibernateConfig.GetSessionFactory().OpenSession())
            {
                using (var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted))
                {
                    try
                    {
                        session.Save(teste);
                        transaction.Commit();

                        return(teste);
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
 public DeleteIcControllerTests()
     : base(new ApiTestSetup <ISession>(
                ContainerConfig.BuildContainer(),
                WebApiConfig.Register,
                builder =>
 {
     // changing the ISession to a singleton so that the two ISession Resolve() calls
     // produce the same instance such that the transaction includes all test activity.
     builder.Register(context => NhibernateConfig.CreateSessionFactory().OpenSession())
     .As <ISession>()
     .SingleInstance();
 },
                session => session.BeginTransaction(),
                session => session.Transaction.Dispose(), // tear down transaction to release locks
                session =>
 {
     NhibernateConfig.CompleteRequest(session);
     session.Clear();            // this is to ensure we don't get ghost results from the NHibernate cache
 }
                ))
 { }
예제 #6
0
        // GET api/values
        public IEnumerable <string> Get()
        {
            var session = NhibernateConfig.OpenSession();

            return(new[] { "value1", "value2" });
        }