Open Closed

IDataSeedContributor exectuion order in UnitTests #571


User avatar
0
ab created
  • ABP Framework version: v3.3.0

Hello,

within my tests I have several DataSeedContributor implementation that inherit from IDataSeedContributor However, some test data seeds needs to be executed before another seed to make valid test data possible (e.g. I like to execute the OrderDataSeedContributor before the OrderItemsDataSeedContributor before since OrderItems are related to Orders).

Now I like to control the exectuion order of the DataSeedContributor. I found that the DataSeeds are executed here

    await scope.ServiceProvider
                        .GetRequiredService<IDataSeeder>()
                        .SeedAsync();

How can I control the execution order?

Thanks!


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Unfortunately the order cannot be determined, You can add dependency injection completely manually, but it is hard work. You'd better initialize the seed data in the same contributor

  • User Avatar
    0
    ab created

    Thank you for your reply! What do you mean with "You'd better initialize the seed data in the same contributor"?

    Do you mean that I should combine all seed data in the same class/ method?

    Thank you

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    (e.g. I like to execute the OrderDataSeedContributor before the OrderItemsDataSeedContributor before since OrderItems are related to Orders).

    You can initialize orders and order items in OrderDataSeedContributor

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11