Пример #1
0
        public void AddRangeAsync_WhenObjectCollectionIsEmpty_ThrowsArgumentException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.ThrowsAsync <ArgumentException>(() => contextRepo.AddRangeAsync(new List <object>()));

            Assert.AreEqual("Cannot add an empty collection. (Parameter 'entities')", exception.Message);
        }
Пример #2
0
        public void AddRangeAsync_WhenObjectCollectionIsNull_ThrowsArgumentNullException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.ThrowsAsync <ArgumentNullException>(() => contextRepo.AddRangeAsync <object>(null));

            Assert.AreEqual("Value cannot be null. (Parameter 'entities')", exception.Message);
        }
Пример #3
0
        public async Task AddRangeAsync_WhenAddingCollection_VerifyDbSetAddRangeAsyncIsCalled()
        {
            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> >());

            await repository.AddRangeAsync(objects);

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