Mock DbContext SaveChanges() method does not return any values

c# entity-framework-6 moq unit-testing

Accepted Answer

Using an interface or abstraction as an example

public interface IDbContext {
    int SaveChanges();
}

This is how you would put up the fake.

var expected = 3;
var mock = new Mock<IDbContext>();
mock.Setup(m => m.SaveChanges()).Returns(expected);


var context = mock.Object;

var actual = context.SaveChanges();

Assert.AreEqual(expected, actual);
4
9/8/2016 4:12:50 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow