public void ShouldBeAbleToSwitch( string mysqld) { using var sut = Create(mysqld); // Arrange var expected = GetRandomAlphaString(5, 10); // Pre-assert var builder = new MySqlConnectionStringUtil(sut.ConnectionString); Expect(builder.Database).To.Equal("tempdb"); // Act sut.SwitchToSchema(expected); // Assert builder = new MySqlConnectionStringUtil(sut.ConnectionString); Expect(builder.Database).To.Equal(expected); }
public void Construction_ShouldCreateSchemaAndSwitchToIt( string mysqld) { // Arrange var expectedId = GetRandomInt(); var expectedName = GetRandomAlphaNumericString(5); // Pre-Assert // Act using (var db = Create(mysqld)) { var builder = new MySqlConnectionStringUtil(db.ConnectionString); Expect(builder.Database).Not.To.Be.Null.Or.Empty(); using (var connection = db.OpenConnection()) using (var command = connection.CreateCommand()) { command.CommandText = new[] { "create table cows (id int, name varchar(128));", $"insert into cows (id, name) values ({expectedId}, '{expectedName}');" }.JoinWith("\n"); command.ExecuteNonQuery(); } using (var connection = db.OpenConnection()) using (var command = connection.CreateCommand()) { command.CommandText = "select id, name from cows;"; using (var reader = command.ExecuteReader()) { Expect(reader.HasRows).To.Be.True(); Expect(reader.Read()).To.Be.True(); Expect(reader["id"]).To.Equal(expectedId); Expect(reader["name"]).To.Equal(expectedName); Expect(reader.Read()).To.Be.False(); // Assert } } } }