public EFGenericRepository(IDearDiaryDbContext dbContext) { if (dbContext == null) { throw new ArgumentNullException("Database context cannot be null."); } this.dbContext = dbContext; this.dbSet = this.dbContext.Set <T>(); }
public void ThrowArgumentNullException_WhenDbContextIsNull() { // Arrange IDearDiaryDbContext dbContext = null; // Act & Assert Assert.That(() => new EFGenericRepository <MockedModel>(dbContext), Throws.ArgumentNullException.With.Message.Contains("Database context cannot be null.")); }
public DearDiaryData( IDearDiaryDbContext dbContext, IEFGenericRepository <User> usersRepo, IEFGenericRepository <Aim> aimsRepo, IEFGenericRepository <AimCategory> categoriesRepo, IEFGenericRepository <City> citiesRepo, IEFGenericRepository <Country> countriesRepo) { if (dbContext == null) { throw new ArgumentNullException("Database context cannot be null."); } if (usersRepo == null) { throw new ArgumentNullException("Users entity framework repository cannot be null."); } if (aimsRepo == null) { throw new ArgumentNullException("Aims entity framework repository cannot be null."); } if (categoriesRepo == null) { throw new ArgumentNullException("AimCategories entity framework repository cannot be null."); } if (citiesRepo == null) { throw new ArgumentNullException("Cities entity framework repository cannot be null."); } if (countriesRepo == null) { throw new ArgumentNullException("Countries entity framework repository cannot be null."); } this.dbContext = dbContext; this.users = usersRepo; this.aims = aimsRepo; this.aimCategories = categoriesRepo; this.cities = citiesRepo; this.countries = countriesRepo; }
public void ThrowCorrectArgumentNullException_WhenOneOfTheConstructorParametersIsNull() { // Arrange IDearDiaryDbContext dbContext = null; var mockedUsers = new Mock <IEFGenericRepository <User> >(); var mockedAims = new Mock <IEFGenericRepository <Aim> >(); var mockedAimCategories = new Mock <IEFGenericRepository <AimCategory> >(); var mockedCities = new Mock <IEFGenericRepository <City> >(); var mockedCountries = new Mock <IEFGenericRepository <Country> >(); // Act & Assert Assert.That(() => new DearDiaryData(dbContext, mockedUsers.Object, mockedAims.Object, mockedAimCategories.Object, mockedCities.Object, mockedCountries.Object), Throws.ArgumentNullException.With.Message.Contains("Database context cannot be null.")); }