Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsSqlServer etc migrationBuilder extensions #16956

Merged
merged 1 commit into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Migrations
{
/// <summary>
/// SQL Server specific extension methods for <see cref="MigrationBuilder" />.
/// </summary>
public static class SqlServerMigrationBuilderExtensions
{
/// <summary>
/// <para>
/// Returns true if the database provider currently in use is the SQL Server provider.
/// </para>
/// </summary>
/// <param name="migrationBuilder"> The migrationBuilder from the parameters on <see cref="Migration.Up(MigrationBuilder)" /> or <see cref="Migration.Down(MigrationBuilder)" />. </param>
/// <returns> True if SQL Server is being used; false otherwise. </returns>
public static bool IsSqlServer([NotNull] this MigrationBuilder migrationBuilder)
=> string.Equals(migrationBuilder.ActiveProvider,
typeof(SqlServerOptionsExtension).GetTypeInfo().Assembly.GetName().Name,
StringComparison.Ordinal);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Sqlite.Infrastructure.Internal;

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Migrations
{
/// <summary>
/// SQLite specific extension methods for <see cref="MigrationBuilder" />.
/// </summary>
public static class SqliteMigrationBuilderExtensions
{
/// <summary>
/// <para>
/// Returns true if the database provider currently in use is the SQLite provider.
/// </para>
/// </summary>
/// <param name="migrationBuilder"> The migrationBuilder from the parameters on <see cref="Migration.Up(MigrationBuilder)" /> or <see cref="Migration.Down(MigrationBuilder)" />. </param>
/// <returns> True if SQLite is being used; false otherwise. </returns>
public static bool IsSqlite([NotNull] this MigrationBuilder migrationBuilder)
=> string.Equals(migrationBuilder.ActiveProvider,
typeof(SqliteOptionsExtension).GetTypeInfo().Assembly.GetName().Name,
StringComparison.Ordinal);
}
}
28 changes: 28 additions & 0 deletions test/EFCore.SqlServer.Tests/SqlServerMigrationBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Migrations;
using Xunit;

namespace Microsoft.EntityFrameworkCore.SqlServer.Tests
{
public class SqlServerMigrationBuilderTest
{
[Fact]
public void IsSqlServer_when_using_SqlServer()
{
var migrationBuilder = new MigrationBuilder("Microsoft.EntityFrameworkCore.SqlServer");
Assert.True(migrationBuilder.IsSqlServer());
}

[Fact]
public void Not_IsSqlServer_when_using_different_provider()
{
var migrationBuilder = new MigrationBuilder("Microsoft.EntityFrameworkCore.InMemory");
Assert.False(migrationBuilder.IsSqlServer());
}

}
}
28 changes: 28 additions & 0 deletions test/EFCore.Sqlite.Tests/SqliteMigrationBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Migrations;
using Xunit;

namespace Microsoft.EntityFrameworkCore
{
public class SqliteMigrationBuilderTest
{
[Fact]
public void IsSqlite_when_using_Sqlite()
{
var migrationBuilder = new MigrationBuilder("Microsoft.EntityFrameworkCore.Sqlite");
Assert.True(migrationBuilder.IsSqlite());
}

[Fact]
public void Not_IsSqlite_when_using_different_provider()
{
var migrationBuilder = new MigrationBuilder("Microsoft.EntityFrameworkCore.InMemory");
Assert.False(migrationBuilder.IsSqlite());
}

}
}