public static void Seed() { CodingSoldierDbContext context = null; try { context = new CodingSoldierDbContext(); if (!context.Roles.Any()) { foreach (var role in GetIdentityRoles()) { context.Roles.Add(role); } } if (!context.Categories.Any()) { foreach (var category in GetCategories()) { context.Categories.Add(category); } } context.SaveChanges(); } catch (Exception ex) { Debug.Write(ex.ToString()); } finally { if (context != null) { context.Dispose(); } } }
public UnitOfWork(DbContext dbContext) { if (dbContext == null) { throw new ArgumentNullException(nameof(dbContext)); } _dbContext = dbContext as CodingSoldierDbContext; }
public PostRepository(DbContext dbContext) { if (dbContext == null) { throw new ArgumentNullException(nameof(dbContext)); } _dbContext = dbContext as CodingSoldierDbContext; }
public UnitOfWork(CodingSoldierDbContext dbContext, IdentityDbContext <ApplicationUser> identityDbContext) { if (dbContext == null) { throw new ArgumentNullException(nameof(dbContext)); } _dbContext = dbContext as CodingSoldierDbContext; _identityDbContext = identityDbContext ?? throw new ArgumentNullException(nameof(identityDbContext)); }
public RepositoryTests() { var data = GetPosts(); var posts = Substitute.For <DbSet <Post>, IQueryable <Post> >(); (posts as IQueryable).Provider.Returns(data.Provider); (posts as IQueryable).Expression.Returns(data.Expression); (posts as IQueryable).ElementType.Returns(data.ElementType); (posts as IQueryable).GetEnumerator().Returns(data.GetEnumerator()); Database.SetInitializer <CodingSoldierDbContext>(null); _codingSoldierDbContext = Substitute.For <CodingSoldierDbContext>(); _codingSoldierDbContext.Set <Post>().Returns(posts); _postRepository = new Repository <Post>(_codingSoldierDbContext); }