public void GenerateUpdateQuery_AllColumnsHasNoSetter_Throws() { // Arrange var generator = new MySqlQueryGenerator <AllColumnsHasMissingSetterEntity>("Users"); // Act && Assert Assert.Throws <InvalidOperationException>(() => generator.GenerateUpdateQuery()); }
public void GenerateUpdateQuery_NoPrimaryKey_Throws() { // Arrange var generator = new MySqlQueryGenerator <HeapEntity>("Users"); // Act && Assert Assert.Throws <InvalidOperationException>(() => generator.GenerateUpdateQuery()); }
public void GenerateGetQuery_NoPrimaryKey_Valid() { // Arrange var generator = new MySqlQueryGenerator <HeapEntity>("Users"); // Act var query = generator.GenerateGetQuery(); // Assert Assert.Equal("SELECT Users.Username, Users.Password FROM Users WHERE Users.Username = @Username AND Users.Password = @Password;", query); }
public void GenerateGetQuery_CustomColumnNames_Valid() { // Arrange var generator = new MySqlQueryGenerator <CustomColumnNamesEntity>("Orders"); // Act var selectQuery = generator.GenerateGetQuery(); // Assert Assert.Equal($"SELECT Orders.OrderId AS Id, Orders.DateCreated AS Date FROM Orders WHERE Orders.OrderId = @Id;", selectQuery); }
public void GenerateGetAllQuery_ProperTableName_Valid() { // Arrange var generator = new MySqlQueryGenerator <HeapEntity>("Users"); // Act var selectQuery = generator.GenerateGetAllQuery(); // Assert Assert.Equal($"SELECT Users.Username, Users.Password FROM Users;", selectQuery); }
public void GenerateGetQuery_SinglePrimaryKey_Valid() { // Arrange var generator = new MySqlQueryGenerator <SinglePrimaryKeyEntity>("Users"); // Act var selectQuery = generator.GenerateGetQuery(); // Assert Assert.Equal($"SELECT Users.Id, Users.Username, Users.Password FROM Users WHERE Users.Id = @Id;", selectQuery); }
public void GenerateGetQuery_CompositePrimaryKey_Valid() { // Arrange var generator = new MySqlQueryGenerator <CompositePrimaryKeyEntity>("Users"); // Act var selectQuery = generator.GenerateGetQuery(); // Assert Assert.Equal($"SELECT Users.Username, Users.Password, Users.DateCreated FROM Users WHERE Users.Username = @Username AND Users.Password = @Password;", selectQuery); }
public void GenerateInsertQuery_CustomColumnNames_Valid() { // Arrange var generator = new MySqlQueryGenerator <CustomColumnNamesEntity>("Orders"); // Act var insertQuery = generator.GenerateInsertQuery(new CustomColumnNamesEntity()); // Assert Assert.Equal(@"INSERT INTO Orders (DateCreated) VALUES (@Date); SELECT Orders.OrderId AS Id, Orders.DateCreated AS Date FROM Orders WHERE Orders.OrderId = LAST_INSERT_ID();", insertQuery); }
public void GenerateUpdateQuery_ColumnHasNoSetter_ColumnIsExcluded() { // Arrange var generator = new MySqlQueryGenerator <ColumnHasMissingSetterEntity>("Users"); // Act var query = generator.GenerateUpdateQuery(); // Assert Assert.Equal(@"UPDATE Users SET Age = @Age WHERE Users.Id = @Id; SELECT Users.Id, Users.Age, Users.DateCreated FROM Users WHERE Users.Id = @Id;", query); }
public void GenerateInsertQuery_ColumnHasDefaultConstraintAndDefaultValue_Valid() { // Arrange var generator = new MySqlQueryGenerator <HasDefaultConstraintEntity>("Users"); // Actj var query = generator.GenerateInsertQuery(new HasDefaultConstraintEntity()); // Assert Assert.Equal(@"INSERT INTO Users (Id) VALUES (@Id); SELECT Users.Id, Users.DateCreated FROM Users WHERE Users.Id = @Id;", query); }
public void GenerateUpdateQuery_CustomColumnNames_Valid() { // Arrange var generator = new MySqlQueryGenerator <CustomColumnNamesEntity>("Orders"); // Act var updateQuery = generator.GenerateUpdateQuery(); // Assert Assert.Equal($@"UPDATE Orders SET DateCreated = @Date WHERE Orders.OrderId = @Id; SELECT Orders.OrderId AS Id, Orders.DateCreated AS Date FROM Orders WHERE Orders.OrderId = @Id;", updateQuery); }
public void GenerateUpdateQuery_CompositePrimaryKey_Valid() { // Arrange var generator = new MySqlQueryGenerator <CompositePrimaryKeyEntity>("Users"); // Act var updateQuery = generator.GenerateUpdateQuery(); // Assert Assert.Equal($@"UPDATE Users SET DateCreated = @DateCreated WHERE Users.Username = @Username AND Users.Password = @Password; SELECT Users.Username, Users.Password, Users.DateCreated FROM Users WHERE Users.Username = @Username AND Users.Password = @Password;", updateQuery); }
public void GenerateUpdateQuery_SinglePrimaryKey_Valid() { // Arrange var generator = new MySqlQueryGenerator <SinglePrimaryKeyEntity>("Users"); // Act var updateQuery = generator.GenerateUpdateQuery(); // Assert Assert.Equal($@"UPDATE Users SET Username = @Username, Password = @Password WHERE Users.Id = @Id; SELECT Users.Id, Users.Username, Users.Password FROM Users WHERE Users.Id = @Id;", updateQuery); }
public void GenerateInsertQuery_NoPrimaryKey_Valid() { // Arrange var generator = new MySqlQueryGenerator <HeapEntity>("Users"); // Act var insertQuery = generator.GenerateInsertQuery(new HeapEntity()); // Assert Assert.Equal(@"INSERT INTO Users (Username, Password) VALUES (@Username, @Password); SELECT Users.Username, Users.Password FROM Users WHERE Users.Username = @Username AND Users.Password = @Password;", insertQuery); }
public void GenerateInsertQuery_MissingColumnValue_ContainsColumn() { // Arrange var generator = new MySqlQueryGenerator <CompositePrimaryKeyEntity>("Users"); // Act var insertQuery = generator.GenerateInsertQuery(new CompositePrimaryKeyEntity()); // Assert Assert.Equal(@"INSERT INTO Users (Username, Password, DateCreated) VALUES (@Username, @Password, @DateCreated); SELECT Users.Username, Users.Password, Users.DateCreated FROM Users WHERE Users.Username = @Username AND Users.Password = @Password;", insertQuery); }
public void GenerateInsertQuery_IdentityValuePrimaryKey_Valid() { // Arrange var generator = new MySqlQueryGenerator <SinglePrimaryKeyEntity>("Users"); // Act var insertQuery = generator.GenerateInsertQuery(new SinglePrimaryKeyEntity()); // Assert Assert.Equal(@"INSERT INTO Users (Username, Password) VALUES (@Username, @Password); SELECT Users.Id, Users.Username, Users.Password FROM Users WHERE Users.Id = LAST_INSERT_ID();", insertQuery); }
public void GenerateInsertQuery_ColumnHasDefaultConstraintAndNonDefaultValue_Valid() { // Arrange var generator = new MySqlQueryGenerator <HasDefaultConstraintEntity>("Users"); var record = new HasDefaultConstraintEntity { Id = 42, DateCreated = DateTime.Now }; // Act var query = generator.GenerateInsertQuery(record); // Assert Assert.Equal(@"INSERT INTO Users (Id, DateCreated) VALUES (@Id, @DateCreated); SELECT Users.Id, Users.DateCreated FROM Users WHERE Users.Id = @Id;", query); }