Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }