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

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

            // Act && Assert
            Assert.Throws <InvalidOperationException>(() => generator.GenerateUpdateQuery());
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }