Skip to content

How to mock dbContext.Entry(entity).State #4

@caibf

Description

@caibf

Hello, I have the following codes.

using (var dbContext = GetDbContext())
{

    dbContext.Set<TEntity>().Attach(entity);
    dbContext.Entry(entity).State = EntityState.Modified;

    try
    {
        dbContext.SaveChanges();
        return true;
    }
    catch (DbUpdateConcurrencyException dbEx)
    {
        // Handling exception
        return false;
    }
}

Based on your sharing, I already know how to Mock Attach the method, but there is no handling for setting the dbContext.Entry(entity).State property. Can you give me a suggestion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions