コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
ファイル: DbAssertTests.cs プロジェクト: sheitm/DataWings
        public void AreEqual_ForEqualValues_NothingHappens()
        {
            string firstNameColumn = "firstName";
            string firstName       = "Barack";

            SetUpAreEqualTest(firstNameColumn, firstName);

            DbAssert.ForTable("Person").WithColumnValuePair("x", "y").AreEqual(firstNameColumn, firstName);
        }
コード例 #4
0
ファイル: DbAssertTests.cs プロジェクト: sheitm/DataWings
        public void AreEqual_ForNonEqualValues_ThrowsAssertionException()
        {
            string firstNameColumn = "firstName";
            string firstName       = "Barack";

            SetUpAreEqualTest(firstNameColumn, "SomeOtherFirstName");

            DbAssert.ForTable("Person").WithColumnValuePair("x", "y").AreEqual(firstNameColumn, firstName);
        }
コード例 #5
0
ファイル: DbAssertTests.cs プロジェクト: sheitm/DataWings
        public void NotExists_ForExistingValue_ThrowsAssertionException()
        {
            string columnName  = "Surname";
            string columnValue = "Obama";

            SetUpExistsTest(1);

            DbAssert.ForTable("Person").WithColumnValuePair(columnName, columnValue).NotExists();
        }
コード例 #6
0
ファイル: DbAssertTests.cs プロジェクト: sheitm/DataWings
        public void NotExists_ForNonExistingValue_NothingHappens()
        {
            string columnName  = "Surname";
            string columnValue = "Obama";

            SetUpExistsTest(0);

            DbAssert.ForTable("Person").WithColumnValuePair(columnName, columnValue).NotExists();
        }
コード例 #7
0
ファイル: DbAssertTests.cs プロジェクト: sheitm/DataWings
        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);
        }
コード例 #8
0
ファイル: DbAssertTests.cs プロジェクト: sheitm/DataWings
        public void NotExists_ExistsInDatabase_ThrowsAssertionException()
        {
            string lastName  = "Bulgakov";
            string firstName = "Mikhail";
            int    id        = InsertPerson(lastName, firstName);

            DbAssert.ForTable("Person")
            .WithColumnValuePair("IdPerson", id)
            .NotExists();
        }
コード例 #9
0
ファイル: DbAssertTests.cs プロジェクト: sheitm/DataWings
        public void Exists_ExistsInDatabase_NoExceptionThrown()
        {
            string lastName  = "Stoltenberg";
            string firstName = "Jens";
            int    id        = InsertPerson(lastName, firstName);

            DbAssert.ForTable("Person")
            .WithColumnValuePair("IdPerson", id)
            .Exists();
        }
コード例 #10
0
 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();
 }
コード例 #11
0
        public void CanDeserializeInitializedNullableInt()
        {
            var expected = new InitializedInt32
            {
                Value1 = null,
                Value2 = 2222,
                Value3 = 3,
            };

            DbAssert.AreEqual(expected, "SELECT NULL AS Value1, 2222 AS Value2", false);
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        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);
        }
コード例 #14
0
 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();
 }
コード例 #15
0
ファイル: DbAssertTests.cs プロジェクト: sheitm/DataWings
        public void ConventionalNotExists_DoesNotExistInDb_SendsCountSqlToSqlProvider()
        {
            Guid id = Guid.NewGuid();

            SetUpConventionalExistsTest(id, 0);

            var entity = new Entity {
                IdEntity = id
            };

            DbAssert.NotExists(entity);

            mocks.VerifyAll();
        }
コード例 #16
0
ファイル: DbAssertTests.cs プロジェクト: sheitm/DataWings
        public void ConventionalNotExists_ExistsInDb_ThrowsAssertionException()
        {
            Guid id = Guid.NewGuid();

            SetUpConventionalExistsTest(id, 1);

            var entity = new Entity {
                IdEntity = id
            };

            DbAssert.NotExists(entity);

            mocks.VerifyAll();
        }
コード例 #17
0
 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();
     }
 }
コード例 #18
0
ファイル: AdversaryTests.cs プロジェクト: sheitm/DataWings
        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);
        }
コード例 #19
0
        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();
            }
        }
コード例 #20
0
        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();
        }
コード例 #21
0
 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();
 }
コード例 #22
0
 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();
 }
コード例 #23
0
 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();
 }
コード例 #24
0
        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();
        }
コード例 #25
0
 public static void AssertExistsInDatabase(this object entity)
 {
     DbAssert.Exists(entity);
 }
コード例 #26
0
 public static void AssertColumnEquals(this object entity, string propertyName)
 {
     DbAssert.ColumnEquals(entity, propertyName);
 }
コード例 #27
0
 public void CanSerializeNullByteArray()
 {
     DbAssert.IsTrue("SELECT CAST(IIF(@parameter IS NULL, 1, 0) AS BIT)", new { parameter = (byte[])null });
 }
コード例 #28
0
 public void CanSerializeTwoElementByteArray()
 {
     DbAssert.IsTrue("SELECT CAST(IIF(CAST(@parameter AS VARCHAR) = 'AB', 1, 0) AS BIT)", new { parameter = new[] { (byte)'A', (byte)'B' } });
 }
コード例 #29
0
 public void CanSerializeEmptyByteArray()
 {
     DbAssert.IsTrue("SELECT CAST(IIF(CAST(@parameter AS VARCHAR) = '', 1, 0) AS BIT)", new { parameter = new byte[] { } });
 }
コード例 #30
0
 public void CanDeserializeNullByteArray()
 {
     DbAssert.ArrayAreEqual <byte[]>(null, "SELECT CAST(NULL AS VARBINARY)");
 }