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
5 changes: 3 additions & 2 deletions docfx/analyzers/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ thread.
## Methods to exclude from VSTHRD103 checks

The VSTHRD103 analyzer flags calls to synchronous methods where asynchronous equivalents exist,
when in an async context. Sometimes certain APIs have async versions but those async versions
are significantly slower, less efficient, or simply not preferred. These methods can be
when in an async context. Sometimes certain APIs have async versions but those async versions
are significantly slower, less efficient, or simply not preferred. These methods can be
excluded from VSTHRD103 analysis by specifying them in a configuration file.

**Filename:** `vs-threading.SyncMethodsToExcludeFromVSTHRD103.txt`, or
Expand All @@ -113,6 +113,7 @@ are intended for different operations or exceptional use cases:
| --- | --- |
| Entity Framework Core `DbContext` | `Add`, `AddRange` |
| Entity Framework Core `DbSet<TEntity>` | `Add`, `AddRange` |
| Entity Framework Core `IDbContextFactory<TContext>` | `CreateDbContext` |
| NUnit `Assert` | `That` |
| xUnit `Assert` | `Throws`, `ThrowsAny` |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[Microsoft.EntityFrameworkCore.DbContext]::AddRange
[Microsoft.EntityFrameworkCore.DbSet`1]::Add
[Microsoft.EntityFrameworkCore.DbSet`1]::AddRange
[Microsoft.EntityFrameworkCore.IDbContextFactory`1]::CreateDbContext
[NUnit.Framework.Assert]::That
[Xunit.Assert]::Throws
[Xunit.Assert]::ThrowsAny
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,9 @@ async Task TestAsync()
set.Add(new object());
set.AddRange(new object());

Microsoft.EntityFrameworkCore.IDbContextFactory<Microsoft.EntityFrameworkCore.DbContext> factory = new Microsoft.EntityFrameworkCore.DbContextFactory<Microsoft.EntityFrameworkCore.DbContext>();
factory.CreateDbContext();

Unrelated.Assert.{|#0:Throws<Exception>|}(() => { });
}
}
Expand Down Expand Up @@ -2842,6 +2845,18 @@ public void Add(T entity) { }
public void AddRange(params T[] entities) { }
public Task AddRangeAsync(params T[] entities) => Task.CompletedTask;
}

interface IDbContextFactory<TContext> where TContext : DbContext
{
TContext CreateDbContext();
Task<TContext> CreateDbContextAsync();
}

class DbContextFactory<TContext> : IDbContextFactory<TContext> where TContext : DbContext, new()
{
public TContext CreateDbContext() => new TContext();
public Task<TContext> CreateDbContextAsync() => Task.FromResult(new TContext());
}
}

namespace Unrelated
Expand Down
Loading