Esempio n. 1
0
        public void Scope_and_open_and_save_on_open_context_should_make_entity_in_parent_visible()
        {
            // arrange
            var openEntity = new DummyEntity {
                Name = "Bob"
            };
            DummyEntity scopeEntity;

            /*
             * PROBLEM here:
             * - the inner dbContext is joining the outer dbContext
             * - the tracked dbContext in the outer/parent is not the proxy, thus, no updates were populated.
             * -> maybe the proxy-dbContexts may never "join" the parent scope?
             * -> maybe we should replace or stack the joined dbScopes?
             * --> who is disposing the inner-most dbContext then and how?
             */

            // act
            using (var scope = DbContextScopeFactory.Create())
            {
                var scopeDbContext = scope.Get <DummyDbContext>();

                using (var openDbContext = DbContextScopeFactory.Open <DummyDbContext>())
                {
                    openDbContext.Add(openEntity);
                    openDbContext.SaveChanges();
                }

                scopeEntity = scopeDbContext.Find <DummyEntity>(openEntity.Id);
            }

            // assert
            Assert.AreEqual(openEntity.Id, scopeEntity.Id);
        }
Esempio n. 2
0
        public async Task Update_entity_should_call_refresh_entities_async_in_parent_scope()
        {
            // arrange
            var dummyEntity = new DummyEntity {
                Name = "Bob"
            };

            using (var dbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                await dbContext.DummyEntities.AddAsync(dummyEntity);

                await dbContext.SaveChangesAsync();
            }
            CalledMethods.Clear();

            // act
            using (var dbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                var savedDummyEntity = await dbContext.DummyEntities.FindAsync(dummyEntity.Id);

                savedDummyEntity.Name = "Alice";
                await dbContext.SaveChangesAsync();
            }

            // assert
            assertCallOrder("SaveChangesAsync", "RefreshEntitiesInParentScopeAsync-SKIP", "Dispose");
        }
Esempio n. 3
0
        public void Dispose_of_proxy_should_be_forwarded()
        {
            // act
            using (DbContextScopeFactory.Open <DummyDbContext>())
            {
            }

            // assert
            assertCallOrder("Dispose");
        }
Esempio n. 4
0
        public async Task SaveChangesAsync_with_bool_and_cancellationToken_of_proxy_should_be_forwarded()
        {
            // act
            using (var dbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                await dbContext.SaveChangesAsync(true, new CancellationToken(false));
            }

            // assert
            assertCallOrder("SaveChangesAsync", "Dispose");
        }
Esempio n. 5
0
        public async Task SaveChangesAsync_of_proxy_should_be_forwarded()
        {
            // act
            using (var dbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                await dbContext.SaveChangesAsync();
            }

            // assert
            assertCallOrder("SaveChangesAsync", "Dispose");
        }
Esempio n. 6
0
        public void SaveChanges_with_bool_of_proxy_should_be_forwarded()
        {
            // act
            using (var dbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                dbContext.SaveChanges(true);
            }

            // assert
            assertCallOrder("SaveChanges", "Dispose");
        }
Esempio n. 7
0
        public void Add_entity_should_call_refresh_entities_in_parent_scope()
        {
            // act
            using (var dbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                dbContext.DummyEntities.Add(new DummyEntity());
                dbContext.SaveChanges();
            }

            // assert
            assertCallOrder("SaveChanges", "RefreshEntitiesInParentScope-SKIP", "Dispose");
        }
Esempio n. 8
0
        public async Task Add_entity_should_call_refresh_entities_async_in_parent_scope()
        {
            // act
            using (var dbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                await dbContext.DummyEntities.AddAsync(new DummyEntity());

                await dbContext.SaveChangesAsync();
            }

            // assert
            assertCallOrder("SaveChangesAsync", "RefreshEntitiesInParentScopeAsync-SKIP", "Dispose");
        }
Esempio n. 9
0
        public void Open_should_create_a_proxy()
        {
            // arrange
            string dummyDbContextTypeName;

            // act
            using (var dummyDbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                dummyDbContextTypeName = dummyDbContext.GetType().Name;
            }

            // assert
            StringAssert.StartsWith(dummyDbContextTypeName, "DummyDbContextProxy");
        }
Esempio n. 10
0
        public async Task Add_nested_entity_should_call_refresh_entities_async_in_parent_scope()
        {
            // act
            using (var dbContext1 = DbContextScopeFactory.Open <DummyDbContext>())
            {
                using (var dbContext2 = DbContextScopeFactory.Open <DummyDbContext>(DbContextScopeOption.ForceCreateNew))
                {
                    await dbContext2.DummyEntities.AddAsync(new DummyEntity());

                    await dbContext2.SaveChangesAsync();
                }
                await dbContext1.SaveChangesAsync();
            }

            // assert
            assertCallOrder("SaveChangesAsync", "RefreshEntitiesInParentScopeAsync", "Dispose", "SaveChangesAsync", "Dispose");
        }
Esempio n. 11
0
        public void Add_nested_entity_should_call_refresh_entities_in_parent_scope()
        {
            // act
            using (var dbContext1 = DbContextScopeFactory.Open <DummyDbContext>())
            {
                using (var dbContext2 = DbContextScopeFactory.Open <DummyDbContext>(DbContextScopeOption.ForceCreateNew))
                {
                    dbContext2.DummyEntities.Add(new DummyEntity());
                    dbContext2.SaveChanges();
                }

                dbContext1.SaveChanges();
            }

            // assert
            assertCallOrder("SaveChanges", "RefreshEntitiesInParentScope", "Dispose", "SaveChanges", "Dispose");
        }