zzz projects Entity Framework Core EF Core
Home Articles Knowledge Base Online Examples
  • Home
  • Articles
  • Knowledge Base
  • Online Examples

Entity Framework Core - Knowledge Base (KB)

16 results in tag: xunit

Separate In Memory Databases EF7

Is there any way to create a separate (isolated) instance of an EF7 In Memory Database? I am using the In Memory Database in Entity Framework 7 in my unit tests written in xUnit. I would like to be able to run the tests in parallel but this isn't really p...
entity-framework-core xunit
asked by Abris

How do I wrap integration tests that use TestServer in a database transaction?

Using xUnit and the ...TestServer... from Microsoft.AspNet.TestHost, how can I wrap each test in a database transaction that can be rolled back after the test?...Here's how I create the ...TestServer...:...TestServer = new TestServer(TestServer.CreateBuil...
entity-framework-core xunit
asked by Mike B

Add test data in integration tests

I'm writing integration tests for my .NET Core app using xUnit. I have various things I want to test, but for brevity I'll use this example. I need to test these things ("document" is just a string, I'm not dealing with files):...Register new employee...L...
asp.net-core c# entity-framework-core integration-testing xunit
asked by vaindil

Xunit - How to use Moq and EF Core for Identity Primary Key

I am trying to automate my UnitTesting with AutoMoq and Xunit for Inserting feature....But I keep getting that I cannot insert a value into the KeyColumn as the following. ...EnrolmentRecordID... is the IdentityColumn in my SQL db and its value is genera...
c# entity-framework-core moq xunit
asked by TTCG

EF Core Update The instance of entity type 'Ads' cannot be tracked

I try to implement a XUnit Test for Asp.net Core DBContext, But I got below error....Message: System.InvalidOperationException : The instance of entity type 'Ads' cannot be tracked because another instance of this type with the same key is already being t...
entity-framework-core xunit
asked by Edward

XUnit Test DbContext did not dispose

I am implementing a XUnit test for DbContext, it seems the DbContext did not dispose correctly. When I debug the first test, it works, but on the second test, an error ...listAds... already added is thrown....After adding a watch, in the second test, ..._...
c# entity-framework-core xunit
asked by Edward

Entity Framework Core: Log queries for a single db context instance

Using EF Core (or any ORM for that matter) I want to keep track of the number of queries the ORM makes to the database during some operation in my software....I've used SQLAlchemy under Python earlier, and on that stack this is faily easy to set up. I typ...
c# entity-framework-core logging unit-testing xunit
asked by codeape

UseInMemoryDatabase context isn't being shared across unit tests

I'm using Entity Framework Core ...2.0-preview1... with InMemory ...2.0-preview1.... Each unit test class inherits a disposable class that creates a new in memory database that its parents can use.... public Constructor() { var services = n...
asp.net-core c# entity-framework-core sql xunit
asked by Kieran Devlin

How to set up the DbContext in xUnit test project properly?

I have the following code to set up DBContext in the .Net core 2.0 console program and it's injected to the constructor of the main application class.... IConfigurationRoot configuration = GetConfiguration(); services.AddSingleton(configuration); ...
c# entity-framework entity-framework-core xunit
asked by ca9163d9

How do I mock AddAsync?

I'm writing unit test. For testing the method below, ...public async Task<Guid> CreateWebJobStatus(string blobId, Guid loggedInUserId, string loggedInUserEmail) { Guid webJobStatusId = Guid.NewGuid(); WebJobStatus newWebJobStatus = new WebJobSta...
c# entity-framework-core moq unit-testing xunit
asked by Jason Hao

Asp.Net Core WebApi: Create Unit Tests

I have an AccountController class, here its ctor:...public AccountController( UserManager<User> userManager, SignInManager<User> signInManager, RoleService roleService, IConfiguration configuration) ...
asp.net-core c# entity-framework-core unit-testing xunit
asked by Nikita Goncharuk

Why are separate DbContexts modifying the same DbSet during Unit Tests?

Enviornment:...Xunit 2.3.1...Microsoft.EntityFrameworkCore.InMemory 2.1.0...I have three test methods in three different classes that when run separately pass but when run together only one will pass and the other two will fail. Then when the two are run ...
c# entity-framework-core in-memory-database unit-testing xunit
asked by JohnOsborne

Avoid HasData Seed DbContext in EF Core 2.2 during Unit Tests

In my ASP.Net CORE 2.2/EF Core 2.2 web API app, I have a HasData() method in my DbContext to seed the DB with some standard data that I use. However, I don't want to use that data when running my xUnit tests. ...My unit tests use the Sqlite in-memory pr...
asp.net-core entity-framework-core sqlite unit-testing xunit
asked by Bryan Lewis

EF Core DbContext Concurrency Issue with XUnit Tests

I seem to have a strange concurrency issue I can't seem to put my finger on. When I construct my implementation of a DbContext I inject the Entities I want to be built by the modelbuilder (don't worry about why). This is only done once by my app at runti...
c# entity-framework-core xunit
asked by Cyassin

Unit testing EF Core using in-memory database with an eager-loaded function

I am writing unit tests for my my Web API and cannot get the test to pass except by removing the include (eager-loading from the method). I am using the in-memory database to provide the ...dbcontext... and can't figure out why it is returning no data. T...
asp.net-core c# entity-framework-core unit-testing xunit
asked by lawrence fejokwu

EF Core Data is Null

Most of the answers on this state that the DbSet on the context must be a property. However that does not seem to be the case in this instance since the DbSet of this context is a property. Here is the sample code that I can use to recreate the problem. P...
c# entity-framework-core xunit
asked by user433229

Page 1 of 1
  • 1

Prime Library

Performance

  • Entity Framework Extensions
  • Entity Framework Classic
  • Bulk Operations
  • Dapper Plus

Expression Evaluator

  • C# Eval Expression
  • SQL Eval Function
More Projects...

Related

  • EF Extensions Online Benchmark
  • WIN an EF Extensions license
  • EF6 BatchSaveChanges for only $79
Get monthly updates by subscribing to our newsletter!
SUBSCRIBE!