public void TestBasicInsertionQuery() { Int32 count = DataAccess.CreateQuery("Insert into TESTTABLE (field1, field2) values (1, 'test')").ExecuteNonQuery(); Assert.That(count, Is.EqualTo(1)); DbAssert.OnQuery("Select count(*) cnt from testtable").That("cnt", Is.EqualTo(1)).ExecuteAssert(); }
public void NoTransactionCommitt() { Int32 count = DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test')").ExecuteNonQuery(); Assert.That(count, Is.EqualTo(1)); DbAssert.OnQuery("Select count(*) cnt from FirstTable").That("cnt", Is.EqualTo(1)).ExecuteAssert(); }
public void AreEqual_ForEqualValues_NothingHappens() { string firstNameColumn = "firstName"; string firstName = "Barack"; SetUpAreEqualTest(firstNameColumn, firstName); DbAssert.ForTable("Person").WithColumnValuePair("x", "y").AreEqual(firstNameColumn, firstName); }
public void AreEqual_ForNonEqualValues_ThrowsAssertionException() { string firstNameColumn = "firstName"; string firstName = "Barack"; SetUpAreEqualTest(firstNameColumn, "SomeOtherFirstName"); DbAssert.ForTable("Person").WithColumnValuePair("x", "y").AreEqual(firstNameColumn, firstName); }
public void NotExists_ForExistingValue_ThrowsAssertionException() { string columnName = "Surname"; string columnValue = "Obama"; SetUpExistsTest(1); DbAssert.ForTable("Person").WithColumnValuePair(columnName, columnValue).NotExists(); }
public void NotExists_ForNonExistingValue_NothingHappens() { string columnName = "Surname"; string columnValue = "Obama"; SetUpExistsTest(0); DbAssert.ForTable("Person").WithColumnValuePair(columnName, columnValue).NotExists(); }
public void AreEqual_ShouldBeAble_NoExceptionThrown() { string lastName = "Bulgakov"; string firstName = "Mikhail"; int id = InsertPerson(lastName, firstName); DbAssert.ForTable("Person") .WithColumnValuePair("IdPerson", id) .AreEqual("LastName", lastName); }
public void NotExists_ExistsInDatabase_ThrowsAssertionException() { string lastName = "Bulgakov"; string firstName = "Mikhail"; int id = InsertPerson(lastName, firstName); DbAssert.ForTable("Person") .WithColumnValuePair("IdPerson", id) .NotExists(); }
public void Exists_ExistsInDatabase_NoExceptionThrown() { string lastName = "Stoltenberg"; string firstName = "Jens"; int id = InsertPerson(lastName, firstName); DbAssert.ForTable("Person") .WithColumnValuePair("IdPerson", id) .Exists(); }
public void BasicTransactionRollback() { using (GlobalTransactionManager.BeginTransaction()) { Int32 count = DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test')").ExecuteNonQuery(); Assert.That(count, Is.EqualTo(1)); GlobalTransactionManager.DoomCurrentTransaction(); } DbAssert.OnQuery("Select count(*) cnt from FirstTable").That("cnt", Is.EqualTo(0)).ExecuteAssert(); }
public void CanDeserializeInitializedNullableInt() { var expected = new InitializedInt32 { Value1 = null, Value2 = 2222, Value3 = 3, }; DbAssert.AreEqual(expected, "SELECT NULL AS Value1, 2222 AS Value2", false); }
public void TestSaveSaveAllData() { AnEntity ent = AnEntity.CreateSome(); sut.Save(ent); DbAssert.OnQuery("select Id, Name, Value from AnEntity where Id ={Id}") .SetInt32Param("Id", Invoker.GetProp <Int32>(ent, "Id")) .That("Name", Is.EqualTo(ent.Name)) .That("Value", Is.EqualTo(ent.Value)) .ExecuteAssert(); }
public void CanDeserializeInitializedString() { var expected = new InitializedString { Value1 = null, Value2 = "New value 2", Value3 = "Initialized value 3", }; DbAssert.AreEqual(expected, "SELECT CAST(NULL AS NVARCHAR(10)) AS Value1, 'New value 2' AS Value2", false); }
public void DistinctDbTransactionCommitt() { using (GlobalTransactionManager.BeginTransaction()) { Int32 count = DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test')").ExecuteNonQuery(); Assert.That(count, Is.EqualTo(1)); count = DataAccess.OnDb("secondary") .CreateQuery("Insert into SecondaryFirstTable (field1, field2) values (1, 'test')") .ExecuteNonQuery(); Assert.That(count, Is.EqualTo(1)); } DbAssert.OnQuery("Select count(*) cnt from FirstTable").That("cnt", Is.EqualTo(1)).ExecuteAssert(); DbAssert.OnDb("secondary").WithQuery("Select count(*) cnt from SecondaryFirstTable").That("cnt", Is.EqualTo(1)).ExecuteAssert(); }
public void ConventionalNotExists_DoesNotExistInDb_SendsCountSqlToSqlProvider() { Guid id = Guid.NewGuid(); SetUpConventionalExistsTest(id, 0); var entity = new Entity { IdEntity = id }; DbAssert.NotExists(entity); mocks.VerifyAll(); }
public void ConventionalNotExists_ExistsInDb_ThrowsAssertionException() { Guid id = Guid.NewGuid(); SetUpConventionalExistsTest(id, 1); var entity = new Entity { IdEntity = id }; DbAssert.NotExists(entity); mocks.VerifyAll(); }
public void DistinctDbTransactionAccessInTransaction() { using (GlobalTransactionManager.BeginTransaction()) { DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test')") .ExecuteNonQuery(); DataAccess.OnDb("secondary") .CreateQuery("Insert into SecondaryFirstTable (field1, field2) values (1, 'test')") .ExecuteNonQuery(); //VErify that in transaction all data is queryable DbAssert.OnQuery("Select count(*) cnt from FirstTable").That("cnt", Is.EqualTo(1)).ExecuteAssert(); DbAssert.OnDb("secondary").WithQuery("Select count(*) cnt from SecondaryFirstTable").That("cnt", Is.EqualTo(1)).ExecuteAssert(); GlobalTransactionManager.DoomCurrentTransaction(); } }
public void IncRowVersion_HappyDays_IncreasesVersionInDatabase() { int id = NextId(); int rowVersion = 1; DataBoy.ForTable("Person") .Row("IdPerson", id) .D("FirstName", "Petter") .D("LastName", "Hansen") .D("Version", rowVersion) .Commit(); Adversary.ForTable("Person").IdentifiedBy("IdPerson", id).IncRowVersion("Version"); DbAssert.ForTable("Person").WithColumnValuePair("IdPerson", id).AreEqual("Version", rowVersion + 1); }
public void TestEnlistInGlobalTransactionRead() { Int32 insertedId; using (GlobalTransactionManager.BeginTransaction()) { using (ISession session = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml")) { AnEntity e = AnEntity.CreateSome(); insertedId = (Int32)session.Save(e); } //We are still in the transaction, ensure we can read the db in the same transaction DbAssert.OnDb("main").WithQuery("select count(*) cnt from AnEntity where id = {id}") .SetInt32Param("id", insertedId) .That("cnt", Is.EqualTo(1)).ExecuteAssert(); } }
public void TestEnlistInGlobalTransaction() { Int32 insertedId; using (GlobalTransactionManager.BeginTransaction()) { using (ISession session = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml")) { AnEntity e = AnEntity.CreateSome(); insertedId = (Int32)session.Save(e); } GlobalTransactionManager.DoomCurrentTransaction(); } DbAssert.OnQuery("select count(*) cnt from AnEntity where id = {id}") .SetInt32Param("id", insertedId) .That("cnt", Is.EqualTo(0)).ExecuteAssert(); }
public void MultipleTransactionRollbackAndCommit() { using (GlobalTransactionManager.BeginTransaction()) { using (GlobalTransactionManager.BeginTransaction()) { DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test1')").ExecuteNonQuery(); GlobalTransactionManager.DoomCurrentTransaction(); } DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test2')").ExecuteNonQuery(); } //inner transaction is rollbacked, but the external one no, so I should see second row DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); DbAssert.OnQuery("Select field2 from FirstTable") .That("field2", Is.EqualTo("test2")).ExecuteAssert(); }
public void MultipleTransactionSeeDataCommittedInNested() { using (GlobalTransactionManager.BeginTransaction()) { using (GlobalTransactionManager.BeginTransaction()) { Int32 count = DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test1')").ExecuteNonQuery(); Assert.That(count, Is.EqualTo(1)); } //First transaction is committed I should see data into db GlobalTransactionManager.DoomCurrentTransaction(); DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); } //Transaction is doomed, so the row disappeared DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(0)).ExecuteAssert(); }
public void MultipleTransactionFirstRollbackThenCommitt() { using (GlobalTransactionManager.BeginTransaction()) { using (GlobalTransactionManager.BeginTransaction()) { DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test1')").ExecuteNonQuery(); GlobalTransactionManager.DoomCurrentTransaction(); } using (GlobalTransactionManager.BeginTransaction()) { DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (2, 'test2')").ExecuteNonQuery(); DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); } DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); } DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); }
public void TestSessionCanWorkWhenTransactionIsClosed() { Int32 insertedId; using (ISession session = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml")) { using (GlobalTransactionManager.BeginTransaction()) { AnEntity e = AnEntity.CreateSome(); session.Save(e); session.Flush(); } //Now the transaction is closed, session still need to work correctly AnEntity e1 = AnEntity.CreateSome(); insertedId = (Int32)session.Save(e1); session.Flush(); } //Need to see the second entity DbAssert.OnQuery("select count(*) cnt from AnEntity where id = {id}") .SetInt32Param("id", insertedId) .That("cnt", Is.EqualTo(1)).ExecuteAssert(); }
public static void AssertExistsInDatabase(this object entity) { DbAssert.Exists(entity); }
public static void AssertColumnEquals(this object entity, string propertyName) { DbAssert.ColumnEquals(entity, propertyName); }
public void CanSerializeNullByteArray() { DbAssert.IsTrue("SELECT CAST(IIF(@parameter IS NULL, 1, 0) AS BIT)", new { parameter = (byte[])null }); }
public void CanSerializeTwoElementByteArray() { DbAssert.IsTrue("SELECT CAST(IIF(CAST(@parameter AS VARCHAR) = 'AB', 1, 0) AS BIT)", new { parameter = new[] { (byte)'A', (byte)'B' } }); }
public void CanSerializeEmptyByteArray() { DbAssert.IsTrue("SELECT CAST(IIF(CAST(@parameter AS VARCHAR) = '', 1, 0) AS BIT)", new { parameter = new byte[] { } }); }
public void CanDeserializeNullByteArray() { DbAssert.ArrayAreEqual <byte[]>(null, "SELECT CAST(NULL AS VARBINARY)"); }