Skip to content
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
2 changes: 1 addition & 1 deletion pages/ef-mstest-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ Mark a test method with `[NoDb]` when it does not touch the database, for exampl

A test without any attribute gets a new database per test, which is the most expensive mode. So a database-free test in a `LocalDbTestBase` class should be marked `[NoDb]` rather than left unmarked.

In a `[NoDb]` test `Database` is null, and accessing `ArrangeData`, `ActData`, or `AssertData`, or calling `Reset`, throws.
In a `[NoDb]` test `Database` and `ArrangeData` are null, so code under test that takes a context it never uses can still be constructed with `ArrangeData`. Accessing `ActData` or `AssertData`, or calling `Reset`, throws.

In a database test, recording resumes on the first access of `ActData`. A `[NoDb]` test has no `ActData`, so recording is resumed when the test starts. Other recorded activity, such as NServiceBus messages sent by the code under test, still appears in the snapshot.

Expand Down
2 changes: 1 addition & 1 deletion pages/ef-nunit-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ Mark a test method with `[NoDb]` when it does not touch the database, for exampl

A test without any attribute gets a new database per test, which is the most expensive mode. So a database-free test in a `LocalDbTestBase` class should be marked `[NoDb]` rather than left unmarked.

In a `[NoDb]` test `Database` is null, and accessing `ArrangeData`, `ActData`, or `AssertData`, or calling `Reset`, throws.
In a `[NoDb]` test `Database` and `ArrangeData` are null, so code under test that takes a context it never uses can still be constructed with `ArrangeData`. Accessing `ActData` or `AssertData`, or calling `Reset`, throws.

In a database test, recording resumes on the first access of `ActData`. A `[NoDb]` test has no `ActData`, so recording is resumed when the test starts. Other recorded activity, such as NServiceBus messages sent by the code under test, still appears in the snapshot.

Expand Down
2 changes: 1 addition & 1 deletion pages/ef-tunit-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ Mark a test method with `[NoDb]` when it does not touch the database, for exampl

A test without any attribute gets a new database per test, which is the most expensive mode. So a database-free test in a `LocalDbTestBase` class should be marked `[NoDb]` rather than left unmarked.

In a `[NoDb]` test `Database` is null, and accessing `ArrangeData`, `ActData`, or `AssertData`, or calling `Reset`, throws.
In a `[NoDb]` test `Database` and `ArrangeData` are null, so code under test that takes a context it never uses can still be constructed with `ArrangeData`. Accessing `ActData` or `AssertData`, or calling `Reset`, throws.

In a database test, recording resumes on the first access of `ActData`. A `[NoDb]` test has no `ActData`, so recording is resumed when the test starts. Other recorded activity, such as NServiceBus messages sent by the code under test, still appears in the snapshot.

Expand Down
2 changes: 1 addition & 1 deletion pages/ef-xunitv3-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ Mark a test method with `[NoDb]` when it does not touch the database, for exampl

A test without any attribute gets a new database per test, which is the most expensive mode. So a database-free test in a `LocalDbTestBase` class should be marked `[NoDb]` rather than left unmarked.

In a `[NoDb]` test `Database` is null, and accessing `ArrangeData`, `ActData`, or `AssertData`, or calling `Reset`, throws.
In a `[NoDb]` test `Database` and `ArrangeData` are null, so code under test that takes a context it never uses can still be constructed with `ArrangeData`. Accessing `ActData` or `AssertData`, or calling `Reset`, throws.

In a database test, recording resumes on the first access of `ActData`. A `[NoDb]` test has no `ActData`, so recording is resumed when the test starts. Other recorded activity, such as NServiceBus messages sent by the code under test, still appears in the snapshot.

Expand Down
2 changes: 1 addition & 1 deletion pages/mdsource/no-db.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Mark a test method with `[NoDb]` when it does not touch the database, for exampl

A test without any attribute gets a new database per test, which is the most expensive mode. So a database-free test in a `LocalDbTestBase` class should be marked `[NoDb]` rather than left unmarked.

In a `[NoDb]` test `Database` is null, and accessing `ArrangeData`, `ActData`, or `AssertData`, or calling `Reset`, throws.
In a `[NoDb]` test `Database` and `ArrangeData` are null, so code under test that takes a context it never uses can still be constructed with `ArrangeData`. Accessing `ActData` or `AssertData`, or calling `Reset`, throws.

In a database test, recording resumes on the first access of `ActData`. A `[NoDb]` test has no `ActData`, so recording is resumed when the test starts. Other recorded activity, such as NServiceBus messages sent by the code under test, still appears in the snapshot.

Expand Down
9 changes: 7 additions & 2 deletions src/EfLocalDb.MSTest.Tests/NoDbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ public void HasNoDatabase() =>

[TestMethod]
[NoDb]
public void ArrangeDataThrows()
public void ArrangeDataIsNull() =>
Assert.IsNull(ArrangeData);

[TestMethod]
[NoDb]
public void ActDataThrows()
{
var exception = Assert.ThrowsExactly<Exception>(() => _ = ArrangeData);
var exception = Assert.ThrowsExactly<Exception>(() => _ = ActData);
Assert.Contains("[NoDb]", exception.Message);
}

Expand Down
10 changes: 8 additions & 2 deletions src/EfLocalDb.MSTest/LocalDbTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,21 @@ void ThrowIfNoDb()
{
if (isNoDb)
{
throw new("The test is marked [NoDb], so it has no database. Remove [NoDb] to use ArrangeData, ActData, AssertData, or Reset.");
throw new("The test is marked [NoDb], so it has no database. Remove [NoDb] to use ActData, AssertData, or Reset.");
}
}

public virtual T ArrangeData
{
get
{
ThrowIfNoDb();
// Code under test often takes a context it never uses in a [NoDb] test,
// so return null rather than throw
if (isNoDb)
{
return null!;
}

if (phase == Phase.Act)
{
throw new("Phase has already moved to Act. Check for a ActData usage in the preceding code.");
Expand Down
9 changes: 7 additions & 2 deletions src/EfLocalDb.NUnit.Tests/NoDbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ public void HasNoDatabase() =>

[Test]
[NoDb]
public void ArrangeDataThrows()
public void ArrangeDataIsNull() =>
IsNull(ArrangeData);

[Test]
[NoDb]
public void ActDataThrows()
{
var exception = Throws<Exception>(() => _ = ArrangeData)!;
var exception = Throws<Exception>(() => _ = ActData)!;
That(exception.Message, Does.Contain("[NoDb]"));
}

Expand Down
10 changes: 8 additions & 2 deletions src/EfLocalDb.NUnit/LocalDbTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,21 @@ void ThrowIfNoDb()
{
if (isNoDb)
{
throw new("The test is marked [NoDb], so it has no database. Remove [NoDb] to use ArrangeData, ActData, AssertData, or Reset.");
throw new("The test is marked [NoDb], so it has no database. Remove [NoDb] to use ActData, AssertData, or Reset.");
}
}

public virtual T ArrangeData
{
get
{
ThrowIfNoDb();
// Code under test often takes a context it never uses in a [NoDb] test,
// so return null rather than throw
if (isNoDb)
{
return null!;
}

if (phase == Phase.Act)
{
throw new("Phase has already moved to Act. Check for a ActData usage in the preceding code.");
Expand Down
9 changes: 7 additions & 2 deletions src/EfLocalDb.TUnit.Tests/NoDbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ public async Task HasNoDatabase() =>

[Test]
[NoDb]
public async Task ArrangeDataThrows()
public async Task ArrangeDataIsNull() =>
await Assert.That(ArrangeData).IsNull();

[Test]
[NoDb]
public async Task ActDataThrows()
{
var exception = await Assert.That(() => _ = ArrangeData).Throws<Exception>();
var exception = await Assert.That(() => _ = ActData).Throws<Exception>();
await Assert.That(exception!.Message).Contains("[NoDb]");
}

Expand Down
10 changes: 8 additions & 2 deletions src/EfLocalDb.TUnit/LocalDbTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,21 @@ void ThrowIfNoDb()
{
if (isNoDb)
{
throw new("The test is marked [NoDb], so it has no database. Remove [NoDb] to use ArrangeData, ActData, AssertData, or Reset.");
throw new("The test is marked [NoDb], so it has no database. Remove [NoDb] to use ActData, AssertData, or Reset.");
}
}

public virtual T ArrangeData
{
get
{
ThrowIfNoDb();
// Code under test often takes a context it never uses in a [NoDb] test,
// so return null rather than throw
if (isNoDb)
{
return null!;
}

if (phase == Phase.Act)
{
throw new("Phase has already moved to Act. Check for a ActData usage in the preceding code.");
Expand Down
9 changes: 7 additions & 2 deletions src/EfLocalDb.Xunit.V3.Tests/NoDbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ public void HasNoDatabase() =>

[Fact]
[NoDb]
public void ArrangeDataThrows()
public void ArrangeDataIsNull() =>
Assert.Null(ArrangeData);

[Fact]
[NoDb]
public void ActDataThrows()
{
var exception = Assert.Throws<Exception>(() => _ = ArrangeData);
var exception = Assert.Throws<Exception>(() => _ = ActData);
Assert.Contains("[NoDb]", exception.Message);
}

Expand Down
10 changes: 8 additions & 2 deletions src/EfLocalDb.Xunit.V3/LocalDbTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,21 @@ void ThrowIfNoDb()
{
if (isNoDb)
{
throw new("The test is marked [NoDb], so it has no database. Remove [NoDb] to use ArrangeData, ActData, AssertData, or Reset.");
throw new("The test is marked [NoDb], so it has no database. Remove [NoDb] to use ActData, AssertData, or Reset.");
}
}

public virtual T ArrangeData
{
get
{
ThrowIfNoDb();
// Code under test often takes a context it never uses in a [NoDb] test,
// so return null rather than throw
if (isNoDb)
{
return null!;
}

if (phase == Phase.Act)
{
throw new("Phase has already moved to Act. Check for a ActData usage in the preceding code.");
Expand Down
Loading