var mockSet = new Mock<DbSet<Student>>(); var mockContext = new Mock<Context>(); mockContext.SetupGet(m => m.Student).Returns(mockSet.Object);
//this is how my whole code looks like [TestClass] public class StudentServiceTest { private IComService _mockComService; private IAccountService _mockAccountService; protected MRContext Context; private IUnitOfWork _mockUnitWork; [SetUp] public void TestInit(MRContext context, IAccountService accountService, IComService comService, IUnitOfWork unitOfWork) { this._mockComService = comService; _mockUnitWork = unitOfWork; this._mockAccountService = accountService; Context = context; } [TestInitialize] public void Initialize() { var mockSet = new Mock<DbSet<Student>>(); var mockContext = new Mock<Context>(); mockContext.SetupGet(m => m.Student).Returns(mockSet.Object); } [TestMethod] public void AutoAssignmentCases() { var service = new StudentService(_mockAccountService, _mockComService, _mockUnitWork); var students = service.DoSomeTask(); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(students.Any(c => !c.SubjectId.HasValue)); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)