public async Task Should_Replace_DbContext()
        {
            _options.GetReplacedTypeOrSelf(typeof(IThirdDbContext)).ShouldBe(typeof(TestAppDbContext));

            (ServiceProvider.GetRequiredService <IThirdDbContext>() is TestAppDbContext).ShouldBeTrue();

            using (var uow = _unitOfWorkManager.Begin())
            {
                var instance1 = await _dummyRepository.GetDbContextAsync();

                (instance1 is IThirdDbContext).ShouldBeTrue();

                var instance2 = await _dummyRepository.GetDbContextAsync();

                (instance2 is TestAppDbContext).ShouldBeTrue();

                var instance3 = await _personRepository.GetDbContextAsync();

                (instance3 is TestAppDbContext).ShouldBeTrue();

                // All instances should be the same!
                instance3.ShouldBe(instance1);
                instance3.ShouldBe(instance2);

                await uow.CompleteAsync();
            }
        }
Beispiel #2
0
        public async Task Should_Replace_DbContext()
        {
            (ServiceProvider.GetRequiredService <IThirdDbContext>() is TestAppDbContext).ShouldBeTrue();

            using (var uow = _unitOfWorkManager.Begin())
            {
                ((await _dummyRepository.GetDbContextAsync()) is IThirdDbContext).ShouldBeTrue();
                ((await _dummyRepository.GetDbContextAsync()) is TestAppDbContext).ShouldBeTrue();

                await uow.CompleteAsync();
            }
        }