mjebrahimi / SqlInMemory

SqlInMemory is a library for creating SqlServer database on Memory instead of hard disk, at last Drops and Disposes database when you're done with it. This is useful for Integration Testing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NuGet License: MIT Build Status

SqlInMemory

SqlInMemory is a library for creating SqlServer database on Memory instead of hard disk, at last Drops and Disposes database when you're done with it. This is useful for Integration Testing.

Note : This library uses RamDisk which also uses ImDisk in the backend for creating virtual disk drive. Therefore you have to install imdisk first. (Download link of current stable version 2.0.10)

Get Started

1. Install Package

PM> Install-Package SqlInMemory

2. Use it

Pass your connection string and it will create (mount) a virtual disk drive 'Z' and create database there finaly when disposed, drop database and unmount drive.

var connectionString = "Data Source=.;Initial Catalog=TestDb;Integrated Security=true";
using (SqlInMemoryDb.Create(connectionString))
{
    //Use database using ADO.NET or ORM

    //For example using EF Core
    services.AddDbContext<AppDbContext>(opt => opt.UseSqlServer(connectionString));
    var serviceProvider = services.BuildServiceProvider();
    var appDbContext = serviceProvider.GetService<AppDbContext>();
    appDbContext.Database.Migrate();
    //...
}

Contributing

Create an issue if you find a BUG or have a Suggestion or Question. If you want to develop this project, Fork on GitHub and Develop it and send Pull Request.

A HUGE THANKS for your help.

License

SqlInMemory is Copyright © 2020 Mohammd Javad Ebrahimi under the MIT License.

About

SqlInMemory is a library for creating SqlServer database on Memory instead of hard disk, at last Drops and Disposes database when you're done with it. This is useful for Integration Testing.

License:MIT License


Languages

Language:C# 100.0%