Beispiel #1
0
        public void Test_Get()
        {
            using (var session = _helperRepository.OpenSession())
            {
                var repo = session.GetRepository <Foo>();

                var foo = repo.Get(1);

                foo.Bar.Should().Be(10);
                Console.WriteLine(foo);
            }
        }
Beispiel #2
0
        public static void Setup(TestContext context)
        {
            DependencyInjector.Kernel.StartMockRepository();
            _helperRepository = DependencyInjector.Kernel.Get <IHelperRepository>();

            using (var session = _helperRepository.OpenSession())
            {
                var repo = session.GetRepository <Foo>();
                try
                {
                    session.StartTransaction();

                    var foo1 = new Foo {
                        Bar = 10
                    };
                    var foo2 = new Foo {
                        Bar = 20
                    };
                    var foo3 = new Foo {
                        Bar = 30
                    };

                    repo.Insert(foo1);
                    repo.Insert(foo2);
                    repo.Insert(foo3);

                    session.CommitTransaction();
                }
                catch (Exception ex)
                {
                    session.RollBackTransaction();
                    Console.WriteLine(ex.Message);
                }
            }
        }
Beispiel #3
0
        public static void Setup(TestContext context)
        {
            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");

            _configuration = builder.Build();

            EntityFrameworkHelper.CreateSchema();

            DependencyInjector.Kernel.StartEntityFramework();

            var kernel = Kernel.GetKernel();

            kernel.Register <DbContext>(() =>
            {
                var opBuilder = new DbContextOptionsBuilder <SharedKernelTestContext>();
                opBuilder.UseSqlServer(_configuration.GetConnectionString("SharedKernel.Test"));
                return(new SharedKernelTestContext(opBuilder.Options));
            });

            _helperRepository = DependencyInjector.Kernel.Get <IHelperRepository>();

            using (var session = _helperRepository.OpenSession())
            {
                var repo = session.GetRepository <Foo>();
                try
                {
                    session.StartTransaction();

                    var foo1 = new Foo {
                        Bar = 10, DataInclusao = DateTime.Now, UsuarioInclusao = "test"
                    };
                    var foo2 = new Foo {
                        Bar = 20, DataInclusao = DateTime.Now, UsuarioInclusao = "test"
                    };
                    var foo3 = new Foo {
                        Bar = 30, DataInclusao = DateTime.Now, UsuarioInclusao = "test"
                    };

                    repo.Insert(foo1);
                    repo.Insert(foo2);
                    repo.Insert(foo3);

                    session.CommitTransaction();
                }
                catch (Exception ex)
                {
                    session.RollBackTransaction();
                    Console.WriteLine(ex.Message);
                }
            }
        }
Beispiel #4
0
        public static void Setup(TestContext context)
        {
            NHibernateHelper.CreateSchema();

            DependencyInjector.Kernel.StartNHibernate();
            _helperRepository = DependencyInjector.Kernel.Get <IHelperRepository>();

            using (var session = _helperRepository.OpenSession())
            {
                var repo = session.GetRepository <Foo>();
                try
                {
                    session.StartTransaction();

                    var foo1 = new Foo {
                        Bar = 10, DataInclusao = DateTime.Now, UsuarioInclusao = "test"
                    };
                    var foo2 = new Foo {
                        Bar = 20, DataInclusao = DateTime.Now, UsuarioInclusao = "test"
                    };
                    var foo3 = new Foo {
                        Bar = 30, DataInclusao = DateTime.Now, UsuarioInclusao = "test"
                    };

                    repo.Insert(foo1);
                    repo.Insert(foo2);
                    repo.Insert(foo3);

                    session.CommitTransaction();
                }
                catch (Exception ex)
                {
                    session.RollBackTransaction();
                    Console.WriteLine(ex.Message);
                }
            }
        }