예제 #1
0
        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();
                }
            }
        }
예제 #2
0
 public UnitOfWork(DbContext dbContext)
 {
     if (dbContext == null)
     {
         throw new ArgumentNullException(nameof(dbContext));
     }
     _dbContext = dbContext as CodingSoldierDbContext;
 }
예제 #3
0
 public PostRepository(DbContext dbContext)
 {
     if (dbContext == null)
     {
         throw new ArgumentNullException(nameof(dbContext));
     }
     _dbContext = dbContext as CodingSoldierDbContext;
 }
예제 #4
0
        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);
        }