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>(); }
public void DuplicatedDocument() { var sameDocumentperson = new Alive(12345, "Pessoa 3", DateTime.UtcNow); _aliveRepository.Add(sameDocumentperson); _aliveRepository.Save(); //É possível adicionar uma pessoa repetida mesmo com "Document" como constraint. _bdContext.Alive.Count(a => a.Document == 12345).Should().Be(3); }