@@ -1100,6 +1100,97 @@ private MigrationFiles GenerateFilesDryRun(string projectDir, string? outputDir,
11001100 return executor . MigrationsOperations . AddMigration ( "M" , outputDir , nameof ( GnomeContext ) , @namespace , dryRun : true ) ;
11011101 }
11021102
1103+ [ ConditionalFact ]
1104+ public void CreateAndApplyMigration_errors_when_no_model_changes ( )
1105+ {
1106+ using var tempPath = new TempDirectory ( ) ;
1107+ var resultHandler = ExecuteCreateAndApplyMigration (
1108+ tempPath ,
1109+ "TestMigration" ,
1110+ null ,
1111+ null ) ;
1112+
1113+ Assert . False ( resultHandler . HasResult ) ;
1114+ Assert . Equal ( typeof ( InvalidOperationException ) . FullName , resultHandler . ErrorType ) ;
1115+ Assert . Contains ( "No changes have been made to the model" , resultHandler . ErrorMessage ) ;
1116+ }
1117+
1118+ [ ConditionalFact ]
1119+ public void CreateAndApplyMigration_errors_for_invalid_context ( )
1120+ {
1121+ using var tempPath = new TempDirectory ( ) ;
1122+ var reportHandler = new OperationReportHandler ( ) ;
1123+ var resultHandler = new OperationResultHandler ( ) ;
1124+ var assembly = Assembly . GetExecutingAssembly ( ) ;
1125+ var executor = new OperationExecutor (
1126+ reportHandler ,
1127+ new Dictionary < string , object ? >
1128+ {
1129+ { "targetName" , assembly . FullName } ,
1130+ { "startupTargetName" , assembly . FullName } ,
1131+ { "projectDir" , tempPath . Path } ,
1132+ { "rootNamespace" , "My.Gnomespace.Data" } ,
1133+ { "language" , "C#" } ,
1134+ { "nullable" , false } ,
1135+ { "toolsVersion" , ProductInfo . GetVersion ( ) } ,
1136+ { "remainingArguments" , null }
1137+ } ) ;
1138+
1139+ new OperationExecutor . CreateAndApplyMigration (
1140+ executor ,
1141+ resultHandler ,
1142+ new Dictionary < string , object ? >
1143+ {
1144+ { "name" , "TestMigration" } ,
1145+ { "connectionString" , null } ,
1146+ { "contextType" , "NonExistentContext" } ,
1147+ { "outputDir" , null } ,
1148+ { "namespace" , null }
1149+ } ) ;
1150+
1151+ Assert . False ( resultHandler . HasResult ) ;
1152+ Assert . NotNull ( resultHandler . ErrorType ) ;
1153+ Assert . Contains ( "NonExistentContext" , resultHandler . ErrorMessage ) ;
1154+ }
1155+
1156+ private static OperationResultHandler ExecuteCreateAndApplyMigration (
1157+ string tempPath ,
1158+ string migrationName ,
1159+ string ? outputDir ,
1160+ string ? @namespace )
1161+ {
1162+ var reportHandler = new OperationReportHandler ( ) ;
1163+ var resultHandler = new OperationResultHandler ( ) ;
1164+ var assembly = Assembly . GetExecutingAssembly ( ) ;
1165+ var executor = new OperationExecutor (
1166+ reportHandler ,
1167+ new Dictionary < string , object ? >
1168+ {
1169+ { "targetName" , assembly . FullName } ,
1170+ { "startupTargetName" , assembly . FullName } ,
1171+ { "projectDir" , tempPath } ,
1172+ { "rootNamespace" , "My.Gnomespace.Data" } ,
1173+ { "language" , "C#" } ,
1174+ { "nullable" , false } ,
1175+ { "toolsVersion" , ProductInfo . GetVersion ( ) } ,
1176+ { "remainingArguments" , null }
1177+ } ) ;
1178+
1179+ new OperationExecutor . CreateAndApplyMigration (
1180+ executor ,
1181+ resultHandler ,
1182+ new Dictionary < string , object ? >
1183+ {
1184+ { "name" , migrationName } ,
1185+ { "connectionString" , null } ,
1186+ { "contextType" , "GnomeContext" } ,
1187+ { "outputDir" , outputDir } ,
1188+ { "namespace" , @namespace }
1189+ } ) ;
1190+
1191+ return resultHandler ;
1192+ }
1193+
11031194 public class OperationBaseTests
11041195 {
11051196 [ ConditionalFact ]
0 commit comments