Example #1
0
        public void GenerateUpdateQuery_AllColumnsHasNoSetter_Throws()
        {
            // Arrange
            var generator = new MySqlQueryGenerator <AllColumnsHasMissingSetterEntity>("Users");

            // Act && Assert
            Assert.Throws <InvalidOperationException>(() => generator.GenerateUpdateQuery());
        }
Example #2
0
        public void GenerateUpdateQuery_NoPrimaryKey_Throws()
        {
            // Arrange
            var generator = new MySqlQueryGenerator <HeapEntity>("Users");

            // Act && Assert
            Assert.Throws <InvalidOperationException>(() => generator.GenerateUpdateQuery());
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
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);
        }
Example #9
0
        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);
        }
Example #10
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);
        }
Example #11
0
        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);
        }
Example #12
0
        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);
        }
Example #13
0
        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);
        }
Example #14
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);
        }
Example #15
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);
        }
Example #16
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);
        }
Example #17
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);
        }