Пример #1
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);
        }
Пример #2
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>();
        }