コード例 #1
0
        public async Task TestInsertAsync_VerifySaveChangesCalledOnce()
        {
            SetUpMockData();

            var taskRepository = new TaskManagerRepository(mockContext.Object);
            var taskDetail     = new TaskItem()
            {
                Id = 1, Name = "Task 1 ", Priority = 10
            };
            var mockSet = new Mock <DbSet <TaskItem> >();

            mockContext.Setup(m => m.Tasks).Returns(mockSet.Object);
            var result = await taskRepository.InsertAsync(taskDetail);

            mockSet.Verify(m => m.Add(taskDetail), Times.Once);
            mockContext.Verify(m => m.SaveChangesAsync(System.Threading.CancellationToken.None), Times.Once);
        }