Git Product home page Git Product logo

blog's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar jvandertil avatar jvandertil-blog-bot[bot] avatar

Watchers

 avatar  avatar  avatar

blog's Issues

Integration testing against a SQL server database

The most important bit of code would be the SqlServer fixture that is responsible for creating and deleting the database. It also provides a checkpoint so that the database can be reset to a known (a.k.a. empty) state.

    public class SqlServerFixture : IAsyncLifetime
    {
        private readonly string _dbName;
        private readonly string _connectionString;

        private readonly Checkpoint _emptyDatabaseCheckpoint;

        public SqlConnection Connection { get; private set; }

        public SqlServerFixture()
        {
            _dbName = "db-" + Guid.NewGuid().ToString();
            _connectionString = "Data Source=(localdb)\\MSSQLLocalDB; Integrated Security=True;";

            _emptyDatabaseCheckpoint = new Checkpoint
            {
                // Reseed identity columns
                WithReseed = true,
                TablesToIgnore = new[]
                {
                    // DbUp journal does not need cleaning
                    "SchemaVersions"
                },
            };
        }

        public async Task InitializeAsync()
        {
            Connection = new SqlConnection(_connectionString);
            await Connection.OpenAsync();

            await ExecuteDbCommandAsync($"CREATE DATABASE [{_dbName}]");
            await ExecuteDbCommandAsync($"USE [{_dbName}]");

            var builder = new SqlConnectionStringBuilder(_connectionString)
            {
                InitialCatalog = _dbName
            };

            var connectionString = builder.ToString();

            var runner = new DbUp.SqlServerMigrationRunner(connectionString);
            var result = runner.PerformUpgrade();

            if (!result.Successful)
            {
                throw result.Error;
            }

            await _emptyDatabaseCheckpoint.Reset(Connection);
        }

        public async Task DisposeAsync()
        {
            await ExecuteDbCommandAsync($"EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'{_dbName}'");
            await ExecuteDbCommandAsync("USE [master]");
            await ExecuteDbCommandAsync($"ALTER DATABASE [{_dbName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
            await ExecuteDbCommandAsync("USE [master]");
            await ExecuteDbCommandAsync($"DROP DATABASE [{_dbName}]");

            await Connection.DisposeAsync();
        }

        public Task ResetDatabaseAsync()
        {
            return _emptyDatabaseCheckpoint.Reset(Connection);
        }

        private async Task ExecuteDbCommandAsync(string commandText)
        {
            using var cmd = Connection.CreateCommand();
            cmd.CommandText = commandText;
            await cmd.ExecuteNonQueryAsync();
        }
    }

Create Linux build scripts for .NET projects

Rationale: Building .NET projects on Linux is faster in Azure Pipelines than building them on Windows agents.

Scripts are quite easy, so should be easy to implement this quick perf win.

Move to GitHub actions

Since this repository is as much a learning ground as it is an actual thing that's published. Let's try to move to GitHub actions from Azure Pipelines.

Since I put all the moving parts in scripts this should be easy... right?

Remove jquery

Now that bootstrap has gone vanilla JS, it's time for us as well :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.