Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lauxjpn committed Mar 15, 2024
1 parent f0391a6 commit 9f85535
Showing 1 changed file with 300 additions and 0 deletions.
300 changes: 300 additions & 0 deletions test/EFCore.MySql.FunctionalTests/MigrationsInfrastructureMySqlTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.TestUtilities;
using MySqlConnector;
using Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using Pomelo.EntityFrameworkCore.MySql.Tests.TestUtilities.Attributes;
Expand Down Expand Up @@ -67,6 +69,7 @@ public override void Can_generate_up_scripts()
CREATE TABLE `Table1` (
`Id` int NOT NULL,
`Foo` int NOT NULL,
`Description` longtext NOT NULL,
CONSTRAINT `PK_Table1` PRIMARY KEY (`Id`)
);

Expand Down Expand Up @@ -98,6 +101,44 @@ public override void Can_generate_up_scripts()

COMMIT;

START TRANSACTION;

INSERT INTO Table1 (Id, Bar, Description) VALUES (-1, ' ', 'Value With

Empty Lines')

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000005_Migration5', '7.0.0-test');

COMMIT;

START TRANSACTION;

INSERT INTO Table1 (Id, Bar, Description) VALUES (-2, ' ', 'GO
Value With

Empty Lines')

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000006_Migration6', '7.0.0-test');

COMMIT;

START TRANSACTION;

INSERT INTO Table1 (Id, Bar, Description) VALUES (-3, ' ', 'GO
Value With

GO

Empty Lines
GO')

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000007_Migration7', '7.0.0-test');

COMMIT;


""",
Sql,
Expand Down Expand Up @@ -165,6 +206,7 @@ IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000
CREATE TABLE `Table1` (
`Id` int NOT NULL,
`Foo` int NOT NULL,
`Description` longtext NOT NULL,
CONSTRAINT `PK_Table1` PRIMARY KEY (`Id`)
);

Expand Down Expand Up @@ -262,6 +304,116 @@ IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000

COMMIT;

START TRANSACTION;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000005_Migration5') THEN

INSERT INTO Table1 (Id, Bar, Description) VALUES (-1, ' ', 'Value With

Empty Lines')

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000005_Migration5') THEN

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000005_Migration5', '7.0.0-test');

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

COMMIT;

START TRANSACTION;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000006_Migration6') THEN

INSERT INTO Table1 (Id, Bar, Description) VALUES (-2, ' ', 'GO
Value With

Empty Lines')

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000006_Migration6') THEN

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000006_Migration6', '7.0.0-test');

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

COMMIT;

START TRANSACTION;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000007_Migration7') THEN

INSERT INTO Table1 (Id, Bar, Description) VALUES (-3, ' ', 'GO
Value With

GO

Empty Lines
GO')

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000007_Migration7') THEN

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000007_Migration7', '7.0.0-test');

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

COMMIT;


""",
Sql,
Expand Down Expand Up @@ -432,6 +584,7 @@ public override void Can_generate_up_scripts_noTransactions()
CREATE TABLE `Table1` (
`Id` int NOT NULL,
`Foo` int NOT NULL,
`Description` longtext NOT NULL,
CONSTRAINT `PK_Table1` PRIMARY KEY (`Id`)
);

Expand All @@ -449,6 +602,32 @@ public override void Can_generate_up_scripts_noTransactions()
INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000004_Migration4', '7.0.0-test');

INSERT INTO Table1 (Id, Bar, Description) VALUES (-1, ' ', 'Value With

Empty Lines')

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000005_Migration5', '7.0.0-test');

INSERT INTO Table1 (Id, Bar, Description) VALUES (-2, ' ', 'GO
Value With

Empty Lines')

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000006_Migration6', '7.0.0-test');

INSERT INTO Table1 (Id, Bar, Description) VALUES (-3, ' ', 'GO
Value With

GO

Empty Lines
GO')

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000007_Migration7', '7.0.0-test');


""",
Sql,
Expand Down Expand Up @@ -476,6 +655,7 @@ IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000
CREATE TABLE `Table1` (
`Id` int NOT NULL,
`Foo` int NOT NULL,
`Description` longtext NOT NULL,
CONSTRAINT `PK_Table1` PRIMARY KEY (`Id`)
);

Expand Down Expand Up @@ -559,12 +739,132 @@ IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000005_Migration5') THEN

INSERT INTO Table1 (Id, Bar, Description) VALUES (-1, ' ', 'Value With

Empty Lines')

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000005_Migration5') THEN

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000005_Migration5', '7.0.0-test');

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000006_Migration6') THEN

INSERT INTO Table1 (Id, Bar, Description) VALUES (-2, ' ', 'GO
Value With

Empty Lines')

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000006_Migration6') THEN

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000006_Migration6', '7.0.0-test');

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000007_Migration7') THEN

INSERT INTO Table1 (Id, Bar, Description) VALUES (-3, ' ', 'GO
Value With

GO

Empty Lines
GO')

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;

DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000007_Migration7') THEN

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('00000000000007_Migration7', '7.0.0-test');

END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;


""",
Sql,
ignoreLineEndingDifferences: true);
}

public override void Can_apply_one_migration()
{
base.Can_apply_one_migration();

Assert.Null(Sql);
}

public override void Can_apply_all_migrations() // Issue https://github.com/dotnet/efcore/issues/33331
=> Assert.Throws<MySqlException>(() => base.Can_apply_all_migrations());

public override Task Can_apply_all_migrations_async() // Issue https://github.com/dotnet/efcore/issues/33331
=> Assert.ThrowsAsync<MySqlException>(() => base.Can_apply_all_migrations_async());

public override void Can_apply_range_of_migrations() // Issue https://github.com/dotnet/efcore/issues/33331
=> Assert.Throws<MySqlException>(() => base.Can_apply_range_of_migrations());

public override void Can_revert_all_migrations() // Issue https://github.com/dotnet/efcore/issues/33331
=> Assert.Throws<MySqlException>(() => base.Can_revert_all_migrations());

public override void Can_revert_one_migrations() // Issue https://github.com/dotnet/efcore/issues/33331
=> Assert.Throws<MySqlException>(() => base.Can_revert_one_migrations());

[ConditionalFact(Skip = "TODO: Implement")]
public override void Can_diff_against_2_2_model()
{
Expand Down

0 comments on commit 9f85535

Please sign in to comment.