예제 #1
0
        public void TestInit()
        {
            _bdContext       = BdContextBuilder.CreateInMemoryContext(Guid.NewGuid().ToString());
            _aliveRepository = new AliveRepository(_bdContext);
            _deadRepository  = new DeadRepository(_bdContext);

            _personAggregate = new PersonAggregate(_aliveRepository, _deadRepository, _bdContext);
        }
예제 #2
0
        public void TestTransaction()
        {
            var bdContext       = BdContextBuilder.CreateSqliteContext(Guid.NewGuid().ToString());
            var aliveRepository = new AliveRepository(bdContext);
            var deadRepository  = new DeadRepository(bdContext);

            var personAggregate = new PersonAggregate(aliveRepository, deadRepository, bdContext);

            personAggregate.Kill(12345);

            bdContext.Alive.Count(a => a.Document == 12345).Should().Be(0);
            bdContext.Dead.Count().Should().Be(1);
        }
예제 #3
0
        public void TestValidDb()
        {
            var bdContext       = BdContextBuilder.CreateSqliteContext(Guid.NewGuid().ToString());
            var newPerson       = new Alive(1000, "New person", DateTime.Now);
            var aliveRepository = new AliveRepository(bdContext);

            aliveRepository.Add(newPerson);
            aliveRepository.Save();
            var newerPerson = new Alive(1000, "Newer person", DateTime.Now.AddDays(-1));

            Action addDuplicate = () =>
            {
                aliveRepository.Add(newerPerson);
                aliveRepository.Save();
            };

            addDuplicate.Should().Throw <DbUpdateException>()
            .WithInnerException <SqliteException>();
        }