tests/UnitTests/Curiosity.Migrations.UnitTests/Services_Should.cs
/// <summary>
/// Checks registering many migrators to IoC
/// </summary>
Checks registering many migrators to IoC
Checks registering many migrators to IoC
[Fact]
        public void AddDifferentMigrationToService()
        {
            var provider = new Mock<IDbProvider>();
            var providerFactory = new Mock<IDbProviderFactory>();
            providerFactory
                .Setup(x => x.CreateDbProvider())
                .Returns(provider.Object);
            var services = new ServiceCollection();      
            services.AddTransient<DependencyService>();
            services.AddMigrations(options =>
            {
                options
                    .UseScriptMigrations()
                    .FromAssembly(Assembly.GetExecutingAssembly());
                options
                    .UserDbProviderFactory(providerFactory.Object);
            });
            services.AddMigrations(options =>
            {
                options
                    .UseCodeMigrations()
                    .FromAssembly(Assembly.GetExecutingAssembly());
                options
                    .UserDbProviderFactory(providerFactory.Object);
            });
            var serviceProvider = services.BuildServiceProvider();
            var migrators = serviceProvider.GetServices<IDbMigrator>()?.ToList();
            migrators.Should().NotBeNull("because we've registered it");
            migrators.Count.Should().Be(2, "because we've registered 2 migrations'");
        }
[ Fact ] public void AddDifferentMigrationToService ( ) { var provider = new Mock < IDbProvider > ( ) ; var providerFactory = new Mock < IDbProviderFactory > ( ) ; providerFactory . Setup ( x => x . CreateDbProvider ( ) ) . Returns ( provider . Object ) ; var services = new ServiceCollection ( ) ; services . AddTransient < DependencyService > ( ) ; services . AddMigrations ( options => { options . UseScriptMigrations ( ) . FromAssembly ( Assembly . GetExecutingAssembly ( ) ) ; options . UserDbProviderFactory ( providerFactory . Object ) ; } ) ; services . AddMigrations ( options => { options . UseCodeMigrations ( ) . FromAssembly ( Assembly . GetExecutingAssembly ( ) ) ; options . UserDbProviderFactory ( providerFactory . Object ) ; } ) ; var serviceProvider = services . BuildServiceProvider ( ) ; var migrators = serviceProvider . GetServices < IDbMigrator > ( ) ? . ToList ( ) ; migrators . Should ( ) . NotBeNull ( " " ) ; migrators . Count . Should ( ) . Be ( 2 , " " ) ; }
Checks registering many migrators to IoC
Checks registering many migrators to IoC
// arrange // act // assert