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

Improve testing docs #3539

Merged
merged 8 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
20 changes: 20 additions & 0 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,26 @@
"source_path": "core/saving/explicit-values-generated-properties.md",
"redirect_url": "/ef/core/modeling/generated-properties#overriding-values",
"redirect_document_id": false
},
{
"source_path": "core/testing/testing-sample.md",
"redirect_url": "/ef/core/testing/index",
"redirect_document_id": false
},
{
"source_path": "core/testing/sharing-databases.md",
"redirect_url": "/ef/core/testing/index",
"redirect_document_id": false
},
{
"source_path": "core/testing/sqlite.md",
"redirect_url": "/ef/core/testing/index",
"redirect_document_id": false
},
{
"source_path": "core/testing/in-memory.md",
"redirect_url": "/ef/core/testing/index",
"redirect_document_id": false
}
]
}
14 changes: 7 additions & 7 deletions entity-framework/core/managing-schemas/ensure-created.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ uid: core/managing-schemas/ensure-created
---
# Create and Drop APIs

The EnsureCreated and EnsureDeleted methods provide a lightweight alternative to [Migrations](xref:core/managing-schemas/migrations/index) for managing the database schema. These methods are useful in scenarios when the data is transient and can be dropped when the schema changes. For example during prototyping, in tests, or for local caches.
The <xref:Microsoft.EntityFrameworkCore.Storage.IDatabaseCreator.EnsureCreated> and <xref:Microsoft.EntityFrameworkCore.Storage.IDatabaseCreator.EnsureDeleted> methods provide a lightweight alternative to [Migrations](xref:core/managing-schemas/migrations/index) for managing the database schema. These methods are useful in scenarios when the data is transient and can be dropped when the schema changes. For example during prototyping, in tests, or for local caches.
ajcvickers marked this conversation as resolved.
Show resolved Hide resolved

Some providers (especially non-relational ones) don't support Migrations. For these providers, EnsureCreated is often the easiest way to initialize the database schema.
Some providers (especially non-relational ones) don't support Migrations. For these providers, `EnsureCreated` is often the easiest way to initialize the database schema.

> [!WARNING]
> EnsureCreated and Migrations don't work well together. If you're using Migrations, don't use EnsureCreated to initialize the schema.
> `EnsureCreated` and Migrations don't work well together. If you're using Migrations, don't use `EnsureCreated` to initialize the schema.
ajcvickers marked this conversation as resolved.
Show resolved Hide resolved

Transitioning from EnsureCreated to Migrations is not a seamless experience. The simplest way to do it is to drop the database and re-create it using Migrations. If you anticipate using migrations in the future, it's best to just start with Migrations instead of using EnsureCreated.
Transitioning from `EnsureCreated` to Migrations is not a seamless experience. The simplest way to do it is to drop the database and re-create it using Migrations. If you anticipate using migrations in the future, it's best to just start with Migrations instead of using `EnsureCreated`.

## EnsureDeleted

The EnsureDeleted method will drop the database if it exists. If you don't have the appropriate permissions, an exception is thrown.
The `EnsureDeleted` method will drop the database if it exists. If you don't have the appropriate permissions, an exception is thrown.

```csharp
// Drop the database if it exists
Expand All @@ -28,7 +28,7 @@ dbContext.Database.EnsureDeleted();

## EnsureCreated

EnsureCreated will create the database if it doesn't exist and initialize the database schema. If any tables exist (including tables for another DbContext class), the schema won't be initialized.
`EnsureCreated` will create the database if it doesn't exist and initialize the database schema. If any tables exist (including tables for another `DbContext` class), the schema won't be initialized.

```csharp
// Create the database if it doesn't exist
Expand All @@ -40,7 +40,7 @@ dbContext.Database.EnsureCreated();

## SQL Script

To get the SQL used by EnsureCreated, you can use the GenerateCreateScript method.
To get the SQL used by `EnsureCreated`, you can use the <xref:Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GenerateCreateScript> method.

```csharp
var sql = dbContext.Database.GenerateCreateScript();
Expand Down
7 changes: 5 additions & 2 deletions entity-framework/core/providers/in-memory/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ uid: core/providers/in-memory/index
---
# EF Core In-Memory Database Provider

This database provider allows Entity Framework Core to be used with an in-memory database. The in-memory database can be useful for testing, although the SQLite provider in in-memory mode may be a more appropriate test replacement for relational databases. The in-memory database is designed for testing only. The provider is maintained as part of the [Entity Framework Core Project](https://github.com/dotnet/efcore).
This database provider allows Entity Framework Core to be used with an in-memory database. While some users use the in-memory database for testing, this is generally discouraged; the SQLite provider in in-memory mode is a more appropriate test replacement for relational databases. For more information on how to test EF Core applications, see the [testing documentation](xref:core/testing/index). The provider is maintained as part of the [Entity Framework Core Project](https://github.com/dotnet/efcore).

> [!WARNING]
> The In-Memory provider was not designed for use outside of testing environments and should never be used as such.

## Install

Expand All @@ -31,7 +34,7 @@ Install-Package Microsoft.EntityFrameworkCore.InMemory

The following resources will help you get started with this provider.

* [Testing with InMemory](xref:core/testing/in-memory)
* [Testing with InMemory](xref:core/testing/unit-testing#inmemory-provider)
* [UnicornStore Sample Application Tests](https://github.com/rowanmiller/UnicornStore/blob/master/UnicornStore/src/UnicornStore.Tests/Controllers/ShippingControllerTests.cs)

## Supported Database Engines
Expand Down
2 changes: 1 addition & 1 deletion entity-framework/core/providers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Entity Framework Core can access many different databases through plug-in librar
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------|:------------------------------------------------------------------------------------------------|:-------------------------------------------|:------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------|
| [Microsoft.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer) | SQL Server 2012 onwards | [EF Core Project](https://github.com/dotnet/efcore/) (Microsoft) | | 6.0 | [docs](xref:core/providers/sql-server/index) |
| [Microsoft.EntityFrameworkCore.Sqlite](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Sqlite) | SQLite 3.7 onwards | [EF Core Project](https://github.com/dotnet/efcore/) (Microsoft) | | 6.0 | [docs](xref:core/providers/sqlite/index) |
| [Microsoft.EntityFrameworkCore.InMemory](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.InMemory) | EF Core in-memory database | [EF Core Project](https://github.com/dotnet/efcore/) (Microsoft) | [Limitations](xref:core/testing/in-memory) | 6.0 | [docs](xref:core/providers/in-memory/index) |
| [Microsoft.EntityFrameworkCore.InMemory](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.InMemory) | EF Core in-memory database | [EF Core Project](https://github.com/dotnet/efcore/) (Microsoft) | [Limitations](xref:core/testing/unit-testing#inmemory-provider) | 5.0 | [docs](xref:core/providers/in-memory/index) |
| [Microsoft.EntityFrameworkCore.Cosmos](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Cosmos) | Azure Cosmos DB SQL API | [EF Core Project](https://github.com/dotnet/efcore/) (Microsoft) | | 6.0 | [docs](xref:core/providers/cosmos/index) |
| [Npgsql.EntityFrameworkCore.PostgreSQL](https://www.nuget.org/packages/Npgsql.EntityFrameworkCore.PostgreSQL) | PostgreSQL | [Npgsql Development Team](https://github.com/npgsql) | | 6.0 | [docs](https://www.npgsql.org/efcore/index.html) |
| [Pomelo.EntityFrameworkCore.MySql](https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql) | MySQL, MariaDB | [Pomelo Foundation Project](https://github.com/PomeloFoundation) | | 6.0 | [readme](https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/blob/master/README.md) |
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2021-11-02T21:10:12.218Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.104 Safari/537.36" etag="OJO2gix77F34yKq73hS7" version="15.6.6" type="device"><diagram id="v9ad4cJjRyrfpDr2_PBp" name="Page-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