コード例 #1
0
ファイル: Delete_Should.cs プロジェクト: estoyan/Noleggio
        public void ThrowWhenEntityisNull()
        {
            //Arrange
            var mockDbSet = new Mock<IDbSet<IDeletableEntity>>();
            var mockedContext = new Mock<INoleggioDbContext>();
            mockedContext.Setup(x => x.Set<IDeletableEntity>()).Returns(mockDbSet.Object);
            var sut = new GenericEfRepository<IDeletableEntity>(mockedContext.Object);


            //Act&Assert
            Assert.Throws<ArgumentNullException>(() => sut.Add(null));
        }
コード例 #2
0
        public void CallOnce_DbSet_Add_WithSameArguments()
        {
            //Arrange
            var entity    = new Mock <IDeletableEntity>();
            var mockDbSet = new Mock <IDbSet <IDeletableEntity> >();

            mockDbSet.Setup(x => x.Add(entity.Object)).Verifiable();
            var context = new Mock <INoleggioDbContext>();

            context.Setup(x => x.Set <IDeletableEntity>()).Returns(mockDbSet.Object);
            var sut = new GenericEfRepository <IDeletableEntity>(context.Object);

            //Act
            sut.Add(entity.Object);

            //Assert
            mockDbSet.Verify(x => x.Add(entity.Object), Times.Once);
        }