public void Delete_Should_ThrowNullReferenceException_WhenPassedArgumentIsNull() { // Arrange var mockedDbContext = new Mock <ICarSystemEfDbContext>(); var mockedSet = new Mock <DbSet <IAdvert> >(); // Act mockedDbContext.Setup(set => set.Set <IAdvert>()).Returns(mockedSet.Object); var mockedDbSet = new EfCarSystemDbSetCocoon <IAdvert>(mockedDbContext.Object); IAdvert entity = null; // Assert Assert.That(() => mockedDbSet.Delete(entity), Throws.InstanceOf <NullReferenceException>()); }
public void Delete_Should_NotThrowException_WhenPassedArgumentIsValid() { // Arrange var mockedSet = new Mock <DbSet <IAdvert> >(); var mockedAdvert = new Mock <IAdvert>(); mockedSet.SetupAllProperties(); var mockedDbContext = new Mock <ICarSystemEfDbContext>(); // Act mockedDbContext.Setup(x => x.Set <IAdvert>()).Returns(mockedSet.Object); var mockedDbSet = new EfCarSystemDbSetCocoon <IAdvert>(mockedDbContext.Object); try { mockedDbSet.Delete(mockedAdvert.Object); } catch (NullReferenceException e) { } // Assert mockedDbContext.Verify(x => x.Entry(mockedAdvert.Object), Times.AtLeastOnce); }