public void When_getting_partial_insert_query() { var dialect = SQLServerDialect.Instance; var table = Table.MakeOrGet <Person>(dialect, string.Empty); var itemWithAllProperties = new { Id = 1, Name = "Foo", Age = 123 }; dialect.GetPartialInsertQuery <Person>(table, itemWithAllProperties) .ShouldBe(@"DECLARE @InsertedRows AS TABLE (Id BIGINT); INSERT INTO [Person] ( [Id], [Name], [Age] ) OUTPUT Inserted.[Id] INTO @InsertedRows VALUES ( @Id, @Name, @Age ); SELECT Id FROM @InsertedRows;"); var itemWithSomeProperties = new { Name = "Foo" }; dialect.GetPartialInsertQuery <Person>(table, itemWithSomeProperties) .ShouldBe(@"DECLARE @InsertedRows AS TABLE (Id BIGINT); INSERT INTO [Person] ( [Name] ) OUTPUT Inserted.[Id] INTO @InsertedRows VALUES ( @Name ); SELECT Id FROM @InsertedRows;"); var itemWithNoProperties = new { }; Should.Throw <InvalidDataException>(() => dialect.GetPartialInsertQuery <Person>(table, itemWithNoProperties)) .Message.ShouldBe("Unable to find any properties in: item"); var lonelyTable = Table.MakeOrGet <Lonely>(dialect, string.Empty); var lonely = new Lonely { Id = 1 }; dialect.GetPartialInsertQuery <Lonely>(lonelyTable, lonely) .ShouldBe(@"DECLARE @InsertedRows AS TABLE (Id BIGINT); INSERT INTO [Lonely] ( [Id] ) OUTPUT Inserted.[Id] INTO @InsertedRows VALUES ( @Id ); SELECT Id FROM @InsertedRows;"); }
private static void Transactions() { //created a command Command.CommandText = "select * from Transactions"; Reader = Command.ExecuteReader(); while (Reader.Read()) { string SerialNumber = (string)Reader["SerialNumber"]; string CustomerId = (string)Reader["CustomerId"]; string TripId = (string)Reader["TripId"]; string TypeOfTicket = (string)Reader["TypeOfTicket"]; string TypeOfTrip = (string)Reader["TypeOfTrip"]; double Price = (double)Reader["Price"]; int NumberOfSeats = (int)Reader["NumberOfSeats"]; Customer CurrentCustomer = SelectCustomer(CustomerId); Trip CurrentTrip = SelectTrip(TripId); if (CurrentCustomer == null || CurrentTrip == null) { continue; } //gets typeoftrip TripType tripType = null; if (TypeOfTrip == "Family") { tripType = new Family(); } else if (TypeOfTrip == "Couple") { tripType = new Couple(); } else if (TypeOfTrip == "General") { tripType = new General(); } else if (TypeOfTrip == "Lonely") { tripType = new Lonely(); } else if (TypeOfTrip == "Friends") { tripType = new Friends(); } Ticket CurrentTicket = new Ticket(SerialNumber, CurrentTrip, TypeOfTicket, tripType, Price, NumberOfSeats); CurrentCustomer.AddTicket(CurrentTicket); CurrentTrip.AddTicket(CurrentTicket); } Reader.Close(); return; }
public void When_getting_partial_insert_query() { var dialect = SQLiteDialect.Instance; var table = Table.MakeOrGet <Person>(dialect, string.Empty); var itemWithAllProperties = new { Id = 1, Name = "Foo", Age = 123 }; dialect.GetPartialInsertQuery <Person>(table, itemWithAllProperties) .ShouldBe(@"INSERT INTO [Person] ( [Id], [Name], [Age] ) VALUES ( @Id, @Name, @Age ); SELECT last_insert_rowid() AS Id;"); var itemWithSomeProperties = new { Name = "Foo" }; dialect.GetPartialInsertQuery <Person>(table, itemWithSomeProperties) .ShouldBe(@"INSERT INTO [Person] ( [Name] ) VALUES ( @Name ); SELECT last_insert_rowid() AS Id;"); var itemWithNoProperties = new { }; Should.Throw <InvalidDataException>(() => dialect.GetPartialInsertQuery <Person>(table, itemWithNoProperties)) .Message.ShouldBe("Unable to find any properties in: item"); var lonelyTable = Table.MakeOrGet <Lonely>(dialect, string.Empty); var lonely = new Lonely { Id = 1 }; dialect.GetPartialInsertQuery <Lonely>(lonelyTable, lonely) .ShouldBe(@"INSERT INTO [Lonely] ( [Id] ) VALUES ( @Id ); SELECT last_insert_rowid() AS Id;"); }
public void When_getting_partial_update_query() { var dialect = SQLiteDialect.Instance; var table = Table.MakeOrGet <Person>(dialect, string.Empty); var filter = Query <Person> .Make(table).Filter.And(x => x.Id, Operator.Equal, 1); var person = new Person { Age = 10, Name = "Joe" }; dialect.GetPartialUpdateQuery(table, person, filter) .ShouldBe(@"UPDATE [Person] SET [Id] = @Id, [Name] = @Name, [Age] = @Age WHERE 1=1 AND ([Id]=@Id1);"); var item = new { Age = 20, Name = "Bob" }; dialect.GetPartialUpdateQuery(table, item, filter) .ShouldBe(@"UPDATE [Person] SET [Age] = @Age, [Name] = @Name WHERE 1=1 AND ([Id]=@Id1);"); var lonelyTable = Table.MakeOrGet <Lonely>(dialect, string.Empty); var lonelyFilter = Query <Lonely> .Make(table).Filter.And(x => x.Id, Operator.Equal, 1); var lonely = new Lonely { Id = 1 }; dialect.GetPartialUpdateQuery(lonelyTable, lonely, lonelyFilter) .ShouldBe(@"UPDATE [Lonely] SET [Id] = @Id WHERE 1=1 AND ([Id]=@Id1);"); }
/// <summary> /// This generates the conditions of the new cow /// </summary> private void GenerateConditions() { //:TODO: add individual variation into fuzzy distributions // Wellness - Physical conditions m_Pain = new Pain(this); m_Sick = new Sick(this); m_Wounded = new Wounded(this); m_Damage = new Damage(this); m_Tired = new Tired(this); m_Hungry = new Hungry(this); m_Thirsty = new Thirsty(this); m_Dead = new Dead(this); // Contentment - Mental conditions m_Anger = new Angry(this); m_Sleepy = new Sleepy(this); m_Scared = new Scared(this); m_Bored = new Bored(this); m_Lonely = new Lonely(this); m_Happy = new Happy(this); m_Eager = new Eager(this); }