public void Remove_WhenObjectIsNull_ThrowsArgumentNullException() { var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >()); var exception = Assert.Throws <ArgumentNullException>(() => contextRepo.Remove((object)null)); Assert.AreEqual("Value cannot be null. (Parameter 'entity')", exception.Message); }
public void Remove_WhenRemovingObject_VerifyDbSetRemoveIsCalled() { var @object = new object(); var mockContext = new Mock <IAuditedContext>(); var mockDbSet = new Mock <DbSet <object> >(); mockContext.Setup(a => a.Set <object>()).Returns(mockDbSet.Object); var repository = new ContextRepository <IAuditedContext>(mockContext.Object, It.IsAny <ILogger <IAuditedContext> >()); repository.Remove(@object); Assert.Multiple(() => { mockDbSet.Verify(a => a.Remove(@object), Times.Once); mockContext.Verify(c => c.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never, "Context should never saved."); }); }