Skip to content

Commit

Permalink
Publish GitHub Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure Pipelines committed Mar 26, 2024
1 parent a9b75b0 commit add7de9
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 1 deletion.
184 changes: 184 additions & 0 deletions articles/in-memory-testing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>In-Memory Testing | FluentMigrator documentation </title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="In-Memory Testing | FluentMigrator documentation ">


<link rel="shortcut icon" href="../images/favicon.ico">
<link rel="stylesheet" href="../styles/docfx.vendor.min.css">
<link rel="stylesheet" href="../styles/docfx.css">
<link rel="stylesheet" href="../styles/main.css">
<meta property="docfx:navrel" content="../toc.html">
<meta property="docfx:tocrel" content="toc.html">

<meta property="docfx:rel" content="../">

</head>
<body data-spy="scroll" data-target="#affix" data-offset="120">
<div id="wrapper">
<header>

<nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

<a class="navbar-brand" href="../index.html">
<img id="logo" class="svg" src="../images/logo.svg" alt="">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<form class="navbar-form navbar-right" role="search" id="search">
<div class="form-group">
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
</div>
</form>
</div>
</div>
</nav>

<div class="subnav navbar navbar-default">
<div class="container hide-when-search" id="breadcrumb">
<ul class="breadcrumb">
<li></li>
</ul>
</div>
</div>
</header>
<div class="container body-content">

<div id="search-results">
<div class="search-list">Search Results for <span></span></div>
<div class="sr-items">
<p><i class="glyphicon glyphicon-refresh index-loading"></i></p>
</div>
<ul id="pagination" data-first="First" data-prev="Previous" data-next="Next" data-last="Last"></ul>
</div>
</div>
<div role="main" class="container body-content hide-when-search">

<div class="sidenav hide-when-search">
<a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
<div class="sidetoggle collapse" id="sidetoggle">
<div id="sidetoc"></div>
</div>
</div>
<div class="article row grid-right">
<div class="col-md-10">
<article class="content wrap" id="_content" data-uid="in-memory-testing">
<h1 id="in-memory-testing">In-Memory Testing</h1>

<p>When performing integration testing, it's sometimes helpful to be able to use an in-memory database (such as Sqlite) to act as the database while tests are running. As a result, this article describes how you can accomplish this with FluentMigrator.</p>
<p><em>Credit to Craig on this <a href="https://stackoverflow.com/a/66926940">StackOverflow answer</a> that in turn created an issue for us to add this to the documentation.</em></p>
<p><em>Note: Sqlite only keeps the in-memory database in memory for the time the process is running. In addition, all connection strings that utilize the same name will access the same database.</em></p>
<p>Create InMemory database, setup FluentMigrator and execute migrations during test setup:</p>
<pre><code class="lang-csharp">public static IDisposable CreateInMemoryDatabase(Assembly AssemblyWithMigrations, IServiceCollection services = null)
{
if (services == null)
services = new ServiceCollection();

var connectionString = GetSharedConnectionString();
var connection = GetPersistantConnection(connectionString);
MigrateDb(services, connectionString, AssemblyWithMigrations);

services.AddSingleton&lt;IConnectionFactory&gt;(new InMemoryConnectionFactory(connectionString));

return services.BuildServiceProvider()
.GetRequiredService&lt;IDisposableUnderlyingQueryingTool&gt;();
}

private static string GetSharedConnectionString()
{
var dbName = Guid.NewGuid().ToString();
return $&quot;Data Source={dbName};Mode=Memory;Cache=Shared&quot;;
}

private static void MigrateDb(IServiceCollection services, string connectionString, Assembly assemblyWithMigrations)
{
var sp = services.AddFluentMigratorCore()
.ConfigureRunner(fluentMigratorBuilder =&gt; fluentMigratorBuilder
.AddSQLite()
.WithGlobalConnectionString(connectionString)
.ScanIn(assemblyWithMigrations).For.Migrations()
)
.BuildServiceProvider();

var runner = sp.GetRequiredService&lt;IMigrationRunner&gt;();
runner.MigrateUp();
}

private static IDbConnection GetPersistantConnection(string connectionString)
{
var connection = new SqliteConnection(connectionString);
connection.Open();

return connection;
}
</code></pre>
<p>This serves as an example test utilizing the static methods above:</p>
<pre><code class="lang-csharp">[TestFixture]
public Test : IDisposable {
private readonly IDisposable _holdingConnection;

[Test]
public Test() {
_holdingConnection = CreateInMemoryDatabase(typeof(MyFirstMigration).Assembly);
}

public void Dispose() {
_holdingConnection.Dispose();
}
}
</code></pre>

</article>
</div>

<div class="hidden-sm col-md-2" role="complementary">
<div class="sideaffix">
<div class="contribution">
<ul class="nav">
<li>
<a href="https://github.com/fluentmigrator/documentation/blob/master/articles/in-memory-testing.md/#L1" class="contribution-link">Edit this page</a>
</li>
</ul>
</div>
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
<h5>In this article</h5>
<div></div>
</nav>
</div>
</div>
</div>
</div>

<footer>
<div class="grad-bottom"></div>
<div class="footer">
<div class="container">
<span class="pull-right">
<a href="#top">Back to top</a>
</span>
<table border='0'><tr><td><span>Copyright © 2018 Fluent Migrator Project<br>Generated by <strong>DocFX</strong></span></td><td><a rel='license' href='http://creativecommons.org/licenses/by-sa/4.0/'><img alt='Creative Commons License' style='border-width:0' src='https://i.creativecommons.org/l/by-sa/4.0/88x31.png'></a><br><span xmlns:dct='http://purl.org/dc/terms/' property='dct:title'>FluentMigrator Documentation</span> by <a xmlns:cc='http://creativecommons.org/ns#' href='https://fluentmigrator.github.io' property='cc:attributionName' rel='cc:attributionURL'>FluentMigrator Project</a> is licensed under a <a rel='license' href='http://creativecommons.org/licenses/by-sa/4.0/'>Creative Commons Attribution-ShareAlike 4.0 International License</a>.</td></tr></table>

</div>
</div>
</footer>
</div>

<script type="text/javascript" src="../styles/docfx.vendor.min.js"></script>
<script type="text/javascript" src="../styles/docfx.js"></script>
<script type="text/javascript" src="../styles/main.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions articles/intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ <h1 id="more-features">More Features</h1>
<li><a class="xref" href="raw-sql.html">Using raw SQL</a></li>
<li><a class="xref" href="migration/migration-auto-reversing.html">Auto-reversing migrations</a></li>
<li><a class="xref" href="migration/migration-transaction-behavior.html">Transaction modes for the migration runner</a></li>
<li><a class="xref" href="in-memory-testing.html">In-Memory Testing</a></li>
</ul>
<h1 id="advanced-features-and-techniques-of-fluentmigrator">Advanced Features and Techniques of FluentMigrator</h1>
<ul>
Expand Down
7 changes: 6 additions & 1 deletion index.json
Original file line number Diff line number Diff line change
Expand Up @@ -12454,10 +12454,15 @@
"title": "Upgrade Guide from 3.2 to 4.0 | FluentMigrator documentation",
"keywords": "Upgrading from 3.2 to 4.0 This version contains mostly added features and fixed bugs. What is new? The most important changes are support for Microsoft.Data.Sqlite 6.0.x and the improved support for modern SQLite development."
},
"articles/in-memory-testing.html": {
"href": "articles/in-memory-testing.html",
"title": "In-Memory Testing | FluentMigrator documentation",
"keywords": "In-Memory Testing When performing integration testing, it's sometimes helpful to be able to use an in-memory database (such as Sqlite) to act as the database while tests are running. As a result, this article describes how you can accomplish this with FluentMigrator. Credit to Craig on this StackOverflow answer that in turn created an issue for us to add this to the documentation. Note: Sqlite only keeps the in-memory database in memory for the time the process is running. In addition, all connection strings that utilize the same name will access the same database. Create InMemory database, setup FluentMigrator and execute migrations during test setup: public static IDisposable CreateInMemoryDatabase(Assembly AssemblyWithMigrations, IServiceCollection services = null) { if (services == null) services = new ServiceCollection(); var connectionString = GetSharedConnectionString(); var connection = GetPersistantConnection(connectionString); MigrateDb(services, connectionString, AssemblyWithMigrations); services.AddSingleton<IConnectionFactory>(new InMemoryConnectionFactory(connectionString)); return services.BuildServiceProvider() .GetRequiredService<IDisposableUnderlyingQueryingTool>(); } private static string GetSharedConnectionString() { var dbName = Guid.NewGuid().ToString(); return $\"Data Source={dbName};Mode=Memory;Cache=Shared\"; } private static void MigrateDb(IServiceCollection services, string connectionString, Assembly assemblyWithMigrations) { var sp = services.AddFluentMigratorCore() .ConfigureRunner(fluentMigratorBuilder => fluentMigratorBuilder .AddSQLite() .WithGlobalConnectionString(connectionString) .ScanIn(assemblyWithMigrations).For.Migrations() ) .BuildServiceProvider(); var runner = sp.GetRequiredService<IMigrationRunner>(); runner.MigrateUp(); } private static IDbConnection GetPersistantConnection(string connectionString) { var connection = new SqliteConnection(connectionString); connection.Open(); return connection; } This serves as an example test utilizing the static methods above: [TestFixture] public Test : IDisposable { private readonly IDisposable _holdingConnection; [Test] public Test() { _holdingConnection = CreateInMemoryDatabase(typeof(MyFirstMigration).Assembly); } public void Dispose() { _holdingConnection.Dispose(); } }"
},
"articles/intro.html": {
"href": "articles/intro.html",
"title": "Install from Nuget | FluentMigrator documentation",
"keywords": "Install from Nuget The project is split into multiple packages: Package Description FluentMigrator The base assembly needed to create migrations FluentMigrator.Runner The runner classes required for in-process execution of migrations FluentMigrator.Console The .NET 4.0/4.5/.NET Core 2.0 executable for out-of-process execution of migrations FluentMigrator.MSBuild The .NET 4.0/4.5/.NET Standard 2.0 task for MSBuild FluentMigrator.DotNet.Cli The .NET Core 2.1 executable that integrates into the .NET Core CLI tooling (dotnet command) Getting Started Check out the tour of FluentMigrator in our Quickstart We also started a FAQ Usage details How to create a migration Learn about the fluent interface Profiles can be used to seed test data And then choose one of the migration runners to run your migrations More Features Database functions as default value Microsoft SQL Server specific extensions Using raw SQL Auto-reversing migrations Transaction modes for the migration runner Advanced Features and Techniques of FluentMigrator Dealing with multiple database types Filter migrations run based on Tags Enforcing migration version numbering rules Create custom metadata for the VersionInfo table Current Release Release Notes Upgrade guides 3.1 to 3.2 3.0 to 3.1 2.x to 3.0 Runners Console dotnet-fm Supported databases For the current release these are the supported databases: Database Identifier Alternative identifier(s) Microsoft SQL Server 2019 SqlServer2016(1) SqlServer Microsoft SQL Server 2017 SqlServer2016(2) SqlServer Microsoft SQL Server 2016 SqlServer2016 SqlServer Microsoft SQL Server 2014 SqlServer2014 SqlServer Microsoft SQL Server 2012 SqlServer2012 SqlServer Microsoft SQL Server 2008 SqlServer2008 SqlServer Microsoft SQL Server 2005 SqlServer2005 SqlServer Microsoft SQL Server 2000 SqlServer2000 SqlServer Microsoft SQL Server Compact Edition(3) SqlServerCe SqlServer PostgreSQL Postgres PostgreSQL PostgreSQL 9.2 Postgres92 PostgreSQL92 PostgreSQL 10.0 PostgreSQL10_0 PostgreSQL PostgreSQL 11.0 PostgreSQL11_0 PostgreSQL MySQL 4 MySql4 MySql MySQL 5 MySql5 MySql, MariaDB Oracle Oracle Oracle (managed ADO.NET) OracleManaged Oracle Oracle (DotConnect ADO.NET) OracleDotConnect Oracle Microsoft JET Engine (Access) Jet SQLite Sqlite Firebird Firebird Amazon Redshift Redshift SAP Hana Hana SAP SQL Anywhere(4) SqlAnywhere16 SqlAnywhere DB2 DB2 DB2 iSeries DB2 iSeries DB2 (1) All integration tests ran without error against an SQL Server 2019 using the SqlServer2016 dialect. (2) All integration tests ran without error against an SQL Server 2017 using the SqlServer2016 dialect. (3) Support for Microsoft SQL Server Compact Edition is being dropped due to Microsoft end-of-life support date passing. (4) Support for SAP SQL Anywhere is being dropped due to SAP not supporting a .NET Core / .NET 5 database driver."
"keywords": "Install from Nuget The project is split into multiple packages: Package Description FluentMigrator The base assembly needed to create migrations FluentMigrator.Runner The runner classes required for in-process execution of migrations FluentMigrator.Console The .NET 4.0/4.5/.NET Core 2.0 executable for out-of-process execution of migrations FluentMigrator.MSBuild The .NET 4.0/4.5/.NET Standard 2.0 task for MSBuild FluentMigrator.DotNet.Cli The .NET Core 2.1 executable that integrates into the .NET Core CLI tooling (dotnet command) Getting Started Check out the tour of FluentMigrator in our Quickstart We also started a FAQ Usage details How to create a migration Learn about the fluent interface Profiles can be used to seed test data And then choose one of the migration runners to run your migrations More Features Database functions as default value Microsoft SQL Server specific extensions Using raw SQL Auto-reversing migrations Transaction modes for the migration runner In-Memory Testing Advanced Features and Techniques of FluentMigrator Dealing with multiple database types Filter migrations run based on Tags Enforcing migration version numbering rules Create custom metadata for the VersionInfo table Current Release Release Notes Upgrade guides 3.1 to 3.2 3.0 to 3.1 2.x to 3.0 Runners Console dotnet-fm Supported databases For the current release these are the supported databases: Database Identifier Alternative identifier(s) Microsoft SQL Server 2019 SqlServer2016(1) SqlServer Microsoft SQL Server 2017 SqlServer2016(2) SqlServer Microsoft SQL Server 2016 SqlServer2016 SqlServer Microsoft SQL Server 2014 SqlServer2014 SqlServer Microsoft SQL Server 2012 SqlServer2012 SqlServer Microsoft SQL Server 2008 SqlServer2008 SqlServer Microsoft SQL Server 2005 SqlServer2005 SqlServer Microsoft SQL Server 2000 SqlServer2000 SqlServer Microsoft SQL Server Compact Edition(3) SqlServerCe SqlServer PostgreSQL Postgres PostgreSQL PostgreSQL 9.2 Postgres92 PostgreSQL92 PostgreSQL 10.0 PostgreSQL10_0 PostgreSQL PostgreSQL 11.0 PostgreSQL11_0 PostgreSQL MySQL 4 MySql4 MySql MySQL 5 MySql5 MySql, MariaDB Oracle Oracle Oracle (managed ADO.NET) OracleManaged Oracle Oracle (DotConnect ADO.NET) OracleDotConnect Oracle Microsoft JET Engine (Access) Jet SQLite Sqlite Firebird Firebird Amazon Redshift Redshift SAP Hana Hana SAP SQL Anywhere(4) SqlAnywhere16 SqlAnywhere DB2 DB2 DB2 iSeries DB2 iSeries DB2 (1) All integration tests ran without error against an SQL Server 2019 using the SqlServer2016 dialect. (2) All integration tests ran without error against an SQL Server 2017 using the SqlServer2016 dialect. (3) Support for Microsoft SQL Server Compact Edition is being dropped due to Microsoft end-of-life support date passing. (4) Support for SAP SQL Anywhere is being dropped due to SAP not supporting a .NET Core / .NET 5 database driver."
},
"articles/maintenance-migrations.html": {
"href": "articles/maintenance-migrations.html",
Expand Down
10 changes: 10 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -27482,6 +27482,16 @@
},
"version": ""
},
{
"type": "Conceptual",
"source_relative_path": "articles/in-memory-testing.md",
"output": {
".html": {
"relative_path": "articles/in-memory-testing.html"
}
},
"version": ""
},
{
"type": "Conceptual",
"source_relative_path": "articles/intro.md",
Expand Down
3 changes: 3 additions & 0 deletions xrefmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ references:
- uid: guides-overview
name: FluentMigrator Guides
href: articles/guides/overview.html
- uid: in-memory-testing
name: In-Memory Testing
href: articles/in-memory-testing.html
- uid: maintenance-migrations.md
name: Maintenance Migrations
href: articles/maintenance-migrations.html
Expand Down

0 comments on commit add7de9

Please sign in to comment.