public DbContext SnapshotCreation()
        {
            var snapshot = new NorthWindDatabaseFactory(scaffold, snapshot: true);

            snapshot.CreateDbContext();
            return(snapshot.CreateDbContext());
        }
        public void Setup()
        {
            scaffold = new DatabaseScaffold();
            factory  = new NorthWindDatabaseFactory(scaffold);
            factory.CreateDbContext();
            // Pre-Create snapshot db.
            var snapshot = new NorthWindDatabaseFactory(scaffold, snapshot: true);

            snapshot.CreateDbContext().Dispose();
        }
        public void CreateDbContext_creates_an_instance()
        {
            // Arrange
            using var instance = new NorthWindDatabaseFactory();

            // Act
            using var dbContext = instance.CreateDbContext();

            // Assert
            dbContext.Should().NotBeNull();
        }
        public void CreateDbContext_prepares_the_db_context()
        {
            // Arrange
            using var instance = new NorthWindDatabaseFactory();

            // Act
            using var dbContext = instance.CreateDbContext();

            // Assert
            dbContext.Should().NotBeNull();
            TestHelpers.ShouldBePrepared(dbContext);
        }
        public void ExecuteMigrate_is_called()
        {
            // Arrange
            using var instance = new NorthWindDatabaseFactory();

            // Act
            using var dbContext = instance.CreateDbContext();

            // Assert
            instance.MigratedDbContext.Should().NotBeNull();
            instance.MigratedDbContext.Should().NotBeSameAs(dbContext);
        }
        public void CreateDbContext_opens_the_database()
        {
            // Arrange
            using var instance = new NorthWindDatabaseFactory();

            // Act
            using var dbContext = instance.CreateDbContext();

            // Assert
            var connection = dbContext.Database.GetDbConnection();

            connection.State.Should().Be(ConnectionState.Open);
        }
        public void Constructor_can_work_snapshot_mode()
        {
            // Arrange
            var count = 0;

            using var instance = new NorthWindDatabaseFactory(snapshot: true);
            instance.Prepared += () => count++;

            // Act
            TestHelpers.MakeFirstCall(instance);
            using var dbContext = instance.CreateDbContext();

            // Assert
            count.Should().Be(0);
            TestHelpers.ShouldBePrepared(dbContext);
        }
        public void CreateDbContext_calls_prepare_only_once()
        {
            // Arrange
            var count = 0;

            using var instance = new NorthWindDatabaseFactory();
            instance.Prepared += () => count++;

            // Act
            TestHelpers.MakeFirstCall(instance);
            using var dbContext = instance.CreateDbContext();

            // Assert
            count.Should().Be(1);
            TestHelpers.ShouldBePrepared(dbContext);
        }
 public DbContext FastCreation()
 {
     return(factory.CreateDbContext());
 }
Ejemplo n.º 10
0
        public static void MakeFirstCall(NorthWindDatabaseFactory instance)
        {
#pragma warning disable CS0642 // Possible mistaken empty statement
            using (instance.CreateDbContext());
#pragma warning restore CS0642 // Possible mistaken empty statement
        }