Class DbSetMock<TEntity>
Class DbSetMock. Implements the Moq.Mock<T>
Inherited Members
Mock<DbSet<TEntity>>.ToString()
Mock<DbSet<TEntity>>.OnGetObject()
Mock<DbSet<TEntity>>.As<TInterface>()
Mock<DbSet<TEntity>>.SetupAllProperties()
Mock<DbSet<TEntity>>.VerifyNoOtherCalls()
Mock<DbSet<TEntity>>.Behavior
Mock<DbSet<TEntity>>.CallBase
Mock<DbSet<TEntity>>.DefaultValueProvider
Mock<DbSet<TEntity>>.Object
Mock<DbSet<TEntity>>.Name
Mock<DbSet<TEntity>>.Switches
Mock.Of<T>()
Mock.Of<T>(MockBehavior)
Mock.Get<T>(T)
Mock.Verify(params Mock[])
Mock.VerifyAll(params Mock[])
Mock.Verify()
Mock.VerifyAll()
Mock.SetReturnsDefault<TReturn>(TReturn)
Mock.DefaultValue
Mock.Invocations
Mock.Setups
Namespace: FastMoq.Models
Assembly: FastMoq.Database.dll
Syntax
public class DbSetMock<TEntity> : Mock<DbSet<TEntity>>, IMock<DbSet<TEntity>>, IDbSetMock where TEntity : class
Type Parameters
| Name | Description |
|---|---|
| TEntity | The type of the t entity. |
Remarks
Any interface type can be used for mocking, but for classes, only abstract and virtual members can be mocked.
The behavior of the mock with regards to the setups and the actual calls is determined by the optional Moq.MockBehavior that can be passed to the Moq.Mock<T>.Mock(Moq.MockBehavior) constructor.
Examples
The following example shows establishing setups with specific values for method invocations:
// Arrange
var order = new Order(TALISKER, 50);
var warehouse = new Mock<IWarehouse>();
warehouse.Setup(w => w.HasInventory(TALISKER, 50)).Returns(true);
// Act
order.Fill(warehouse.Object);
// Assert
Assert.True(order.IsFilled);
The following example shows how to use the Moq.It class to specify conditions for arguments instead of specific values:
// Arrange
var order = new Order(TALISKER, 50);
var warehouse = new Mock<IWarehouse>();
// shows how to expect a value within a range:
warehouse.Setup(x => x.HasInventory(
It.IsAny<string>(),
It.IsInRange(0, 100, Range.Inclusive)))
.Returns(false);
// shows how to throw for unexpected calls.
warehouse.Setup(x => x.Remove(
It.IsAny<string>(),
It.IsAny<int>()))
.Throws(new InvalidOperationException());
// Act
order.Fill(warehouse.Object);
// Assert
Assert.False(order.IsFilled);
Constructors
DbSetMock()
Initializes an instance of the mock with Moq.MockBehavior.Default behavior.
Declaration
public DbSetMock()
Examples
var mock = new Mock<IFormatProvider>();
DbSetMock(IList<TEntity>)
Declaration
public DbSetMock(IList<TEntity> initialData)
Parameters
| Type | Name | Description |
|---|---|---|
| IList<TEntity> | initialData |
Methods
SetupAsyncListMethods()
Declaration
public virtual void SetupAsyncListMethods()
SetupListMethods()
Declaration
public virtual void SetupListMethods()
SetupMockMethods()
Declaration
public virtual void SetupMockMethods()
Implements
Moq.IMock<T>
Extension Methods
See Also
Mock<T>