public void UsesNewConnectionForEachFindCall() { var count = 0; var repo = new DbXmlKeysRepository(() => { count++; return(_postgresTestHelper.ConnectionFactory()); }); repo.FindAll(); repo.FindAll(); Assert.AreEqual(2, count); }
public void CanFindAll() { var keys = new[] { new XmlKey { Xml = "<tag1></tag1>" }, new XmlKey { Xml = "<tag2></tag2>" } }; foreach (var key in keys) { key.Id = _postgresTestHelper.Connection.ExecuteScalar <Guid>(@"INSERT into ""XmlKeys""(Xml) values (@Xml) returning Id", key); } var repo = new DbXmlKeysRepository(_postgresTestHelper.ConnectionFactory); var actualKeys = repo.FindAll().ToArray(); Assert.AreEqual(keys.Length, actualKeys.Length); foreach (var key in keys) { Assert.IsTrue(actualKeys.Any(x => x.Id == key.Id && x.Xml == key.Xml), $"DB did not contain key with ID {key.Id}"); } }