Beispiel #1
0
        public void RollbackTransactionOnErrorTest()
        {
            var entityID = Guid.NewGuid();

            using (var container = new RhetosTestContainer(commitChanges: true))
            {
                var context = container.Resolve <Common.ExecutionContext>();

                var entity = new TestStorage.Simple
                {
                    ID   = entityID,
                    Name = "Test"
                };
                context.PersistenceStorage.Insert(new List <TestStorage.Simple> {
                    entity
                });
                Assert.AreEqual(1, context.Repository.TestStorage.Simple.Load(x => x.ID == entityID).Count());
                context.PersistenceTransaction.DiscardChanges();
            }

            using (var container = new RhetosTestContainer(commitChanges: false))
            {
                var context = container.Resolve <Common.ExecutionContext>();
                Assert.AreEqual(0, context.Repository.TestStorage.Simple.Load(x => x.ID == entityID).Count());
            }
        }
        public void RollbackTransactionOnErrorTest()
        {
            var entityID = Guid.NewGuid();

            using (var scope = TestScope.Create())
            {
                var context = scope.Resolve <Common.ExecutionContext>();

                var entity = new TestStorage.Simple
                {
                    ID   = entityID,
                    Name = "Test"
                };
                context.PersistenceStorage.Insert(new List <TestStorage.Simple> {
                    entity
                });
                Assert.AreEqual(1, context.Repository.TestStorage.Simple.Load(x => x.ID == entityID).Count());
                context.PersistenceTransaction.DiscardOnDispose();
                scope.CommitAndClose();
            }

            using (var scope = TestScope.Create())
            {
                var context = scope.Resolve <Common.ExecutionContext>();
                Assert.AreEqual(0, context.Repository.TestStorage.Simple.Load(x => x.ID == entityID).Count());
            }
        }