コード例 #1
0
        public void InvokeSaveChangesOnDbContext()
        {
            var model = new ContactEditModel
            {
                FirstName = "Han",
                LastName = "Solo"
            };
            var contactsController = new ContactsController(_mockDbContext.Object);

            var result = contactsController.Post(model).Result;

            _mockDbContext.Verify(x => x.SaveChangesAsync(), Times.Exactly(1));
        }
コード例 #2
0
        public void AddNewContactToTheDbContext()
        {
            var model = new ContactEditModel
            {
                FirstName = "Han",
                LastName = "Solo"
            };
            var contactsController = new ContactsController(_mockDbContext.Object);

            var result = contactsController.Post(model).Result;

            _mockDbContext.MockContactsDbSet.Verify(x => x.Add(It.IsAny<Contact>()), Times.Exactly(1));
        }