public void Attach_WhenObjectIsNull_ThrowsArgumentNullException() { var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >()); var exception = Assert.Throws <ArgumentNullException>(() => contextRepo.Attach <object>(null)); Assert.AreEqual("Value cannot be null. (Parameter 'entity')", exception.Message); }
public void Attach_WhenAttachingObject_VerifyDbSetAttachIsCalled() { 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.Attach(@object); Assert.Multiple(() => { mockDbSet.Verify(a => a.Attach(@object), Times.Once); mockContext.Verify(c => c.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never, "Context should never saved."); }); }