public void Commit_WithReturnValue_SelectExecutedAsExpected() { //INSERT INTO Address (ID, IdPerson) VALUES('7e7304db-2b77-4040-ae64-9eb6a686a036', 1) var factory = GetProviderFactory(); var provider = new StubSqlProvider(); provider.SetObjectToReturn(1); using (mocks.Record()) { factory.CreateProvider("somestring"); LastCall.Return(provider).IgnoreArguments(); } Guid personId = Guid.NewGuid(); DataBoy .ForTable("Person") .Row("Id", personId) .ReturnValue("IdPerson").AtKey("IdOfPerson") //.ForTable("Address") // .Row("Id", Guid.NewGuid()) // .BindColumn("IdPerson").To("IdOfPerson") .Commit(); //HasAnySqlMatching string expectedSql = string.Format("SELECT IdPerson FROM Person WHERE Id = '{0}'", personId); Assert.IsTrue(provider.HasAnySqlMatching(expectedSql)); }
public void Commit_MultipleRows_SendsSqlsInCorrectOrder() { var factory = GetProviderFactory(); var provider = new StubSqlProvider(); using (mocks.Record()) { factory.CreateProvider("somestring"); LastCall.Return(provider).IgnoreArguments(); } DataBoy .ForTable("Person") .Row("IdPerson", 1).Data("Surname", "Obama").DeleteFirst() .Row("IdPerson", 2).Data("Surname", "Bush").DeleteFirst() .ForTable("Address") .Row("IdAddress", 100).Data("Street", "Main street").DeleteFirst() .Commit(); Assert.AreEqual("DELETE FROM Address WHERE IdAddress = 100", provider.GetExecutedQuery(0)); Assert.AreEqual("DELETE FROM Person WHERE IdPerson = 2", provider.GetExecutedQuery(1)); Assert.AreEqual("DELETE FROM Person WHERE IdPerson = 1", provider.GetExecutedQuery(2)); Assert.AreEqual("INSERT INTO Person (IDPERSON, SURNAME) VALUES(1, 'Obama')", provider.GetExecutedQuery(3)); Assert.AreEqual("INSERT INTO Person (IDPERSON, SURNAME) VALUES(2, 'Bush')", provider.GetExecutedQuery(4)); Assert.AreEqual("INSERT INTO Address (IDADDRESS, STREET) VALUES(100, 'Main street')", provider.GetExecutedQuery(5)); }
public void Commit_BindColumnToForInsert_InsertWorksCorrectly() { var factory = GetProviderFactory(); var provider = new StubSqlProvider(); provider.SetObjectToReturn(1); using (mocks.Record()) { factory.CreateProvider("somestring"); LastCall.Return(provider).IgnoreArguments(); } Guid personId = Guid.NewGuid(); Guid addressId = Guid.NewGuid(); DataBoy .ForTable("Person") .Row("Id", personId) .ReturnValue("IdPerson").AtKey("IdOfPerson") .ForTable("Address") .Row("Id", addressId) .BindColumn("IdPerson").To("IdOfPerson") .Commit(); string expectedSql = string.Format("INSERT INTO Address (ID, IdPerson) VALUES('{0}', 1)", addressId); Assert.IsTrue(provider.HasAnySqlMatching(expectedSql)); }
private int InsertPerson(string lastName, string firstName) { int id = NextId(); DataBoy.ForTable("Person") .Row("IdPerson", id) .D("FirstName", firstName) .D("LastName", lastName) .Commit(); return(id); }
public void InsertData_ForInsert_SendsExpectedSqlToDatabase() { int id = NextId(); string expectedSql = String.Format("INSERT INTO Person (IDPERSON, FIRSTNAME, LASTNAME) VALUES({0}, 'Petter', 'Hansen')", id); DataBoy.ForTable("Person") .Row("IdPerson", id) .D("FirstName", "Petter") .D("LastName", "Hansen") .Commit(); Assert.AreEqual(expectedSql, ExecutedSql); }
public void Commit_ForUpdate_SendsUpdateInsteadOfInsert() { var factory = GetProviderFactory(); var provider = new StubSqlProvider(); using (mocks.Record()) { factory.CreateProvider("somestring"); LastCall.Return(provider).IgnoreArguments(); } DataBoy.ForTable("Person").Row("IdPerson", 1).Data("Surname", "Obama").ForUpdate().Commit(); Assert.IsTrue(provider.GetExecutedQuery(0).StartsWith("UPDATE")); }
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 InsertData_ForInsert_DataActuallyInsertedInDatabase() { int id = NextId(); string firstName = "Jens"; string lastName = "Stoltenberg"; DataBoy.ForTable("Person") .Row("IdPerson", id) .D("FirstName", firstName) .D("LastName", lastName) .Commit(); var results = Database.Select(String.Format("SELECT * FROM Person WHERE IdPerson = {0}", id), SelectOptions.Single); Assert.AreEqual(1, results.Count); }
public void Commit_ForUpdate_UniqueKeyColumnNotIncludedInUpdateStatement() { var factory = GetProviderFactory(); var provider = new StubSqlProvider(); using (mocks.Record()) { factory.CreateProvider("somestring"); LastCall.Return(provider).IgnoreArguments(); } string idColumenName = "IdPerson"; DataBoy.ForTable("Person").Row(idColumenName, 1).Data("Surname", "Obama").ForUpdate().Commit(); Assert.AreEqual("UPDATE Person SET SURNAME = 'Obama' WHERE IdPerson = 1", provider.GetExecutedQuery(0)); }
public void Values_WithMultipleRows_SendSqlAsExpected() { var factory = GetProviderFactory(); var provider = new StubSqlProvider(); using (mocks.Record()) { factory.CreateProvider("somestring"); LastCall.Return(provider).IgnoreArguments(); } DataBoy.ForTable("Person") .Values( Column.Named("FirstName").Eq("Steel"), Column.Named("LastName").Eq("Hotman")); Assert.AreEqual("INSERT INTO Person (FIRSTNAME, LASTNAME) VALUES('Steel', 'Hotman')", provider.GetExecutedQuery(0)); }
public void QueryForTable_HappyDays_GetsDataAsExpected() { int id = NextId(); string firstName = "Reodor"; string lastName = "Felgen"; DataBoy.ForTable("Person") .Row("IdPerson", id) .D("FirstName", firstName) .D("LastName", lastName) .Commit(); string selectedLastName = DataBoy.QueryForTable("Person") .Where("IdPerson").Eq(id) .GetValueForColumn <string>("LastName"); Assert.AreEqual(lastName, selectedLastName); }
public void DeleteData_HappyDays_DataIsDeletedFromDatabase() { int id = NextId(); string firstName = "Jens"; string lastName = "Stoltenberg"; DataBoy.ForTable("Person") .Row("IdPerson", id) .D("FirstName", firstName) .D("LastName", lastName) .Commit(); DataBoy.ForTable("Person") .Row("IdPerson", id).ForDelete() .Commit(); var results = Database.Select(String.Format("SELECT * FROM Person WHERE IdPerson = {0}", id), SelectOptions.Single); Assert.AreEqual(0, results.Count); }
public void UpdateData_HappyDays_DataIsUpdatedInDatabase() { int id = NextId(); string firstName = "Jens"; string lastName = "Stoltenberg"; DataBoy.ForTable("Person") .Row("IdPerson", id) .D("FirstName", firstName) .D("LastName", lastName) .Commit(); string newFirstName = "Thorvald"; DataBoy.ForTable("Person") .Row("IdPerson", id).ForUpdate() .D("FirstName", newFirstName) .Commit(); var resultingRow = (Database.Select(String.Format("SELECT * FROM Person WHERE IdPerson = {0}", id), SelectOptions.Single))[0]; Assert.AreEqual(newFirstName, resultingRow.GetResult("FirstName")); }