Exemplo n.º 1
0
        public void Remove_WhenObjectCollectionIsEmpty_ThrowsArgumentException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.Throws <ArgumentException>(() => contextRepo.RemoveRange <object>(new List <object>()));

            Assert.AreEqual("Cannot remove an empty collection. (Parameter 'entities')", exception.Message);
        }
Exemplo n.º 2
0
        public void Remove_WhenObjectCollectionIsNull_ThrowsArgumentNullException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.Throws <ArgumentNullException>(() => contextRepo.RemoveRange((ICollection <object>)null));

            Assert.AreEqual("Value cannot be null. (Parameter 'entities')", exception.Message);
        }
Exemplo n.º 3
0
        public void RemoveRange_WhenRemovingCollection_VerifyDbSetRemoveRangeIsCalled()
        {
            var objects = new List <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.RemoveRange(objects);

            Assert.Multiple(() =>
            {
                mockDbSet.Verify(a => a.RemoveRange(objects), Times.Once);
                mockContext.Verify(c => c.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never, "Context should never saved.");
            });
        }