I am using the Moq framework in my Unit Test. This is the UpdateApplication test method:
[TestMethod]
public void UpdateApplication()
{
    const string newAplpicationName = "NewApplication1";
    var data =
        new[]
        {
            new Application { Id = 1, Name = "Application1" }, new Application { Id = 2, Name = "Application2" },
            new Application { Id = 3, Name = "Application3" }, new Application { Id = 4, Name = "Application4" }
        }
            .AsQueryable();
    var mockSet = new Mock<DbSet<Application>>();
    mockSet.As<IQueryable<Application>>().Setup(m => m.Provider).Returns(data.Provider);
    mockSet.As<IQueryable<Application>>().Setup(m => m.Expression).Returns(data.Expression);
    mockSet.As<IQueryable<Application>>().Setup(m => m.ElementType).Returns(data.ElementType);
    mockSet.As<IQueryable<Application>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
    mockSet.Setup(m => m.AddOrUpdate(It.IsAny<Application[]>())).Callback(
        (Application[] apps) =>
        {
            apps.FirstOrDefault(m => m.Id == 1).Name = newAplpicationName;
        }).Verifiable(); // <-- Exception
    var mockContext = new Mock<AppDbContext>();
    mockContext.Setup(c => c.Applications).Returns(mockSet.Object);
    // Act 
    var commandHandler = new UpdateApplicationCommandHandler(mockContext.Object);
    var commandArg = new ApplicationCommandArg { Id = 1, Name = newAplpicationName };
    commandHandler.Execute(new UpdateApplicationCommand(commandArg));
    // Verify
    mockContext.Verify(m => m.SaveChanges(), Times.Once());
}
I got an exception when ran the test:
An exception of type 'System.NotSupportedException' occurred in Moq.dll but was not handled in user code Additional information: Expression references a method that does not belong to the mocked object: m => m.AddOrUpdate(It.IsAny()) at Moq.Mock.ThrowIfNotMember(Expression setup, MethodInfo method) at Moq.Mock.c__DisplayClass19`1.b__18() at Moq.PexProtector.Invoke[T](Func`1 function) at Moq.Mock.Setup[T](Mock`1 mock, Expression`1 expression, Condition condition) at Moq.Mock`1.Setup(Expression`1 expression) at UpdateApplication() in UpdateApplicationCommandTests.cs:line 39
How should I write unit tests for update and delete actions using Moq?
 
     
    