示例#1
0
        public void NotThrowExceptionWhenPassedArgumentIsValid()
        {
            // Arrange
            var mockedSet    = new Mock <DbSet <ICreature> >();
            var mockedAdvert = new Mock <ICreature>();

            mockedSet.SetupAllProperties();
            var mockedDbContext = new Mock <IAquaWorldDbContext>();
            var fakeEntry       = (DbEntityEntry <ICreature>)FormatterServices.GetSafeUninitializedObject(typeof(DbEntityEntry <ICreature>));

            // Act
            mockedDbContext.Setup(x => x.Set <ICreature>()).Returns(mockedSet.Object);
            mockedDbContext.Setup(x => x.Entry(It.IsAny <ICreature>())).Returns(fakeEntry);
            var dataProvider = new EfAquaWorldDataProvider <ICreature>(mockedDbContext.Object);

            try
            {
                dataProvider.Add(mockedAdvert.Object);
            }
            catch (NullReferenceException)
            {
            }

            // Assert
            mockedDbContext.Verify(x => x.Entry(mockedAdvert.Object), Times.AtLeastOnce);
        }
示例#2
0
        public void ThrowNullReferenceExceptionWhenPassedArgumentIsNull()
        {
            // Arrange
            var mockedDbContext = new Mock <IAquaWorldDbContext>();
            var mockedSet       = new Mock <DbSet <ICreature> >();

            // Act
            mockedDbContext.Setup(set => set.Set <ICreature>()).Returns(mockedSet.Object);
            var       dataProvider = new EfAquaWorldDataProvider <ICreature>(mockedDbContext.Object);
            ICreature entity       = null;

            // Assert
            Assert.That(() => dataProvider.Add(entity),
                        Throws.InstanceOf <NullReferenceException>());
        }