public void When_calling_run_func_Then_the_expected_result_is_returned()
        {
            var expectedResult = _fixture.Create <string>();
            var result         = _sut.Run(() => expectedResult);

            Assert.That(result, Is.EqualTo(expectedResult));
        }
            public void SetUp()
            {
                _fixture = new CustomAutoFixture();

                _expectedContextManageCount = _hasCurrentContext ? 0 : 1;

                _contextService = _fixture.Freeze <IContextService <DbContext_Fake> >();
                _dbSetService   = _fixture.Freeze <IDbSetService <DbContext_Fake, Foo> >();
                _flushService   = _fixture.Freeze <IFlushService <DbContext_Fake> >();

                _context = new DbContext_Fake();

                _contextService.HasCurrentContext().Returns(_hasCurrentContext);
                _contextService.InitContext().Returns(_context);
                _contextService.GetCurrentContext().Returns(_context);

                _dbSet = Substitute.For <DbSet <Foo>, IQueryable <Foo> >();

                _dbSetService.GetDbSet(Arg.Any <DbContext_Fake>())
                .Returns(_dbSet);

                _sut = _fixture.Create <ContextRepository <DbContext_Fake, Foo> >();

                _foo = _fixture.Create <Foo>();
            }
            public void SetUp()
            {
                _fixture = new CustomAutoFixture();

                _expectedContextManageCount = _hasCurrentContext ? 0 : 1;

                _contextService = _fixture.Freeze <IContextService <DbContext_Fake> >();
                _dbSetService   = _fixture.Freeze <IDbSetService <DbContext_Fake, Foo> >();

                _context = new DbContext_Fake();

                _contextService.HasCurrentContext().Returns(_hasCurrentContext);
                _contextService.InitContext().Returns(_context);
                _contextService.GetCurrentContext().Returns(_context);

                _expectedEntity = _fixture.Create <Foo>();

                _dbSet = CreateDbSetSubstitute(_expectedEntity);
                _dbSet.FindAsync(_expectedEntity.FooId).Returns(_expectedEntity);

                _dbSetService.GetDbSet(Arg.Any <DbContext_Fake>())
                .Returns(_dbSet);

                _sut = _fixture.Create <ContextRepository <DbContext_Fake, Foo> >();
            }
Exemple #4
0
        public void When_calling_QueryAsync_with_null_queryFunc_Then_ArgumentNullException_is_thrown()
        {
            var repository = _fixture.Create <ContextRepository <DbContext_Fake, Foo> >();

            Assert.Multiple(() =>
            {
                Assert.That(() => repository.QueryAsync(null), Throws.InstanceOf <ArgumentNullException>());
                Assert.That(() => repository.QueryAsync(null, _fixture.CreateMany <string>()), Throws.InstanceOf <ArgumentNullException>());
            });
        }
        public void When_calling_run_action_Then_transaction_is_committed_once()
        {
            var transaction = _fixture.Create <IDbContextTransaction>();

            _databaseFacade.Transaction = transaction;

            _sut.Run(() => { });

            transaction.Received(1).Commit();
        }
        public void SetUp()
        {
            _fixture = new CustomAutoFixture();

            _context = new DbContext_Fake();

            _contextService = _fixture.Freeze <IContextService <DbContext_Fake> >();
            _contextService.HasCurrentContext().Returns(false);
            _contextService.InitContext().Returns(_context);
            _contextService.GetCurrentContext().Returns(_context);

            _databaseFacade = (DatabaseFacade_Fake)_context.Database;

            _sut = _fixture.Create <DbContextTransactionUnitOfWork <DbContext_Fake> >();
        }
        public void SetUp()
        {
            _fixture = new CustomAutoFixture();

            _sut = _fixture.Create <NoFlushService <DbContext_Fake> >();
        }
        public void SetUp()
        {
            _fixture = new CustomAutoFixture();

            _sut = _fixture.Create <ContextRepository <DbContext_Fake, Foo> >();
        }
Exemple #9
0
 public override Task <IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken = new CancellationToken())
 => Task.FromResult(_fixture.Create <IDbContextTransaction>());
Exemple #10
0
 public DatabaseFacade_Fake(DbContext context)
     : base(context)
 {
     _fixture    = new CustomAutoFixture();
     Transaction = _fixture.Create <IDbContextTransaction>();
 }