Exemple #1
0
        public void AttachRange_WhenObjectCollectionIsEmpty_ThrowsArgumentException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.Throws <ArgumentException>(() => contextRepo.AttachRange(new List <object>()));

            Assert.AreEqual("Cannot attach an empty collection. (Parameter 'entities')", exception.Message);
        }
Exemple #2
0
        public void AttachRange_WhenObjectCollectionIsNull_ThrowsArgumentNullException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.Throws <ArgumentNullException>(() => contextRepo.AttachRange <object>(null));

            Assert.AreEqual("Value cannot be null. (Parameter 'entities')", exception.Message);
        }
Exemple #3
0
        public void AttachRange_WhenAttachingCollection_VerifyDbSetAttachRangeIsCalled()
        {
            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.AttachRange(objects);

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