public void PersistingDataTest()
        {
            var lookupCode = new LookupCode
            {
                Description = "desc"
            };

            using (var dbContext = new SheriffDbContext(EnvironmentBuilder.SetupDbOptions()))
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    using (TransactionScope scope2 = new TransactionScope())
                    {
                        dbContext.LookupCode.Add(lookupCode);
                        dbContext.SaveChanges();
                        scope2.Complete();
                        scope.Complete();
                    }
                }
            }

            using (var dbContext = new SheriffDbContext(EnvironmentBuilder.SetupDbOptions()))
            {
                var workSectionCode2 = dbContext.LookupCode.Find(lookupCode.Id);
                Assert.NotNull(workSectionCode2);
                dbContext.Remove(workSectionCode2);
                dbContext.SaveChanges();
            }
        }
        public void RollbackDataTest()
        {
            var lookupCode = new LookupCode
            {
                Description = "desc"
            };

            using (var dbContext = new SheriffDbContext(EnvironmentBuilder.SetupDbOptions()))
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    using (TransactionScope scope2 = new TransactionScope())
                    {
                        dbContext.LookupCode.Add(lookupCode);
                        dbContext.SaveChanges();
                        scope2.Complete();
                    }
                    //No scope complete, should rollback.
                }
            }

            using (var dbContext = new SheriffDbContext(EnvironmentBuilder.SetupDbOptions()))
            {
                var workSectionCode2 = dbContext.LookupCode.Find(lookupCode.Id);
                Assert.Null(workSectionCode2);
            }
        }
Exemple #3
0
 public ManageTypesControllerTests()
 {
     _dbContext  = new SheriffDbContext(EnvironmentBuilder.SetupDbOptions(useMemoryDatabase: true));
     _controller = new ManageTypesController(new ManageTypesService(_dbContext))
     {
         ControllerContext = HttpResponseTest.SetupMockControllerContext()
     };
 }
Exemple #4
0
 public ConcurrencyExceptionTest()
 {
     Db = new SheriffDbContext(EnvironmentBuilder.SetupDbOptions(false));
 }
 public WrapInTransactionScope(bool useMemoryDatabase)
 {
     Db     = new SheriffDbContext(EnvironmentBuilder.SetupDbOptions(useMemoryDatabase: useMemoryDatabase));
     _scope = new TransactionScope(TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled);
 }