public static void AddRoles(AuthorizeDbContext context)
        {
            var roles = new Role[]
            {
                new Role {
                    Id = 1, Name = RoleNames.DAA, Description = "Data Collections Admin"
                },
                new Role {
                    Id = 2, Name = RoleNames.DCS, Description = "Data Collections Support"
                },
                new Role {
                    Id = 3, Name = RoleNames.BI, Description = "Reports and BI"
                },
                new Role {
                    Id = 4, Name = RoleNames.DCI, Description = "Data Collections Information Officer"
                },
            };

            foreach (var role in roles)
            {
                context.Roles.Add(role);
            }

            context.SaveChanges();
        }
        public AuthorizeDbContext GetContext()
        {
            if (_context == null)
            {
                _context = new AuthorizeDbContext();
            }

            return(_context);
        }
Beispiel #3
0
        public void GetAllRoleFeatures_Test_Null()
        {
            var options = new DbContextOptionsBuilder <AuthorizeDbContext>()
                          .UseInMemoryDatabase("GetAllRoleFeatures_Test_Null")
                          .Options;

            var context    = new AuthorizeDbContext(options);
            var repository = new AuthorizeRepository(context);

            var roleFeatures = repository.GetAllRoleFeatures();

            roleFeatures.Count().Should().Be(0);
            context.RoleFeatures.FirstOrDefault().Should().BeNull();
        }
        public static void Initialize(AuthorizeDbContext context)
        {
            context.Database.EnsureCreated();

            // Look for any roles
            if (context.Roles.Any())
            {
                return;   // DB has been seeded
            }

            AddRoles(context);
            AddFeatures(context);
            AddRoleFeatures(context);
        }
        public void AddRoleFeatures_Test()
        {
            var options = new DbContextOptionsBuilder <AuthorizeDbContext>()
                          .UseInMemoryDatabase("AddRoleFeatures_Test")
                          .Options;

            using (var context = new AuthorizeDbContext(options))
            {
                AuthorizationDataSeeder.AddRoleFeatures(context);
            }

            using (var context = new AuthorizeDbContext(options))
            {
                context.RoleFeatures.Count().Should().Be(2);
            }
        }
        public static void AddRoleFeatures(AuthorizeDbContext context)
        {
            var roleFeatures = new RoleFeature[]
            {
                new RoleFeature {
                    FeatureId = 1, RoleId = 1
                },
                new RoleFeature {
                    FeatureId = 2, RoleId = 1
                },
            };

            foreach (var rp in roleFeatures)
            {
                context.RoleFeatures.Add(rp);
            }

            context.SaveChanges();
        }
        public static void AddFeatures(AuthorizeDbContext context)
        {
            var features = new Feature[]
            {
                new Feature()
                {
                    Id = 1, Name = FeatureNames.FileSubmission, Description = "File Submission"
                },
                new Feature()
                {
                    Id = 2, Name = FeatureNames.ReportViewing, Description = "Reports Viewer"
                }
            };

            foreach (var p in features)
            {
                context.Features.Add(p);
            }

            context.SaveChanges();
        }
        public void RoleFeatureTest()
        {
            var options = new DbContextOptionsBuilder <AuthorizeDbContext>()
                          .UseInMemoryDatabase("Test_Database_RoleFeature")
                          .Options;

            using (var context = new AuthorizeDbContext(options))
            {
                var feature = new Feature {
                    Id = 1, Name = "test feature", Description = "test desc"
                };
                context.Features.Add(feature);

                var role = new Role {
                    Id = 1, Name = "test role", Description = "test desc"
                };
                context.Roles.Add(role);

                context.RoleFeatures.Add(new RoleFeature {
                    Id = 1, FeatureId = 1, Role = role, Feature = feature
                });
                context.SaveChanges();
            }

            using (var context = new AuthorizeDbContext(options))
            {
                context.RoleFeatures.Count().Should().Be(1);
                var roleFeature = context.RoleFeatures
                                  .Include(x => x.Role)
                                  .Include(x => x.Feature)
                                  .First();

                roleFeature.RoleId.Should().Be(1);
                roleFeature.FeatureId.Should().Be(1);
                roleFeature.Feature.Should().NotBeNull();
                roleFeature.Role.Should().NotBeNull();
            }
        }
Beispiel #9
0
        public void GetAllRoleFeatures_Test_Success()
        {
            var options = new DbContextOptionsBuilder <AuthorizeDbContext>()
                          .UseInMemoryDatabase("GetAllRoleFeatures_Test_Success")
                          .Options;

            using (var context = new AuthorizeDbContext(options))
            {
                var feature = new Feature {
                    Id = 1, Name = "test feature", Description = "test desc"
                };
                context.Features.Add(feature);

                var role = new Role {
                    Id = 1, Name = "test role", Description = "test desc"
                };
                context.Roles.Add(role);

                context.RoleFeatures.Add(new RoleFeature {
                    Id = 1, FeatureId = 1, Role = role, Feature = feature
                });
                context.SaveChanges();
            }

            var repository = new AuthorizeRepository(new AuthorizeDbContext(options));

            var roleFeatures = repository.GetAllRoleFeatures();

            roleFeatures.Count().Should().Be(1);

            var roleFeature = roleFeatures.FirstOrDefault();

            roleFeature.Should().NotBeNull();
            roleFeature.RoleId.Should().Be(1);
            roleFeature.FeatureId.Should().Be(1);
            roleFeature.Feature.Should().NotBeNull();
            roleFeature.Role.Should().NotBeNull();
        }
        public void FeatureTest()
        {
            var options = new DbContextOptionsBuilder <AuthorizeDbContext>()
                          .UseInMemoryDatabase("Test_Database_Feature")
                          .Options;

            using (var context = new AuthorizeDbContext(options))
            {
                context.Features.Add(new Feature {
                    Id = 1, Name = "test feature", Description = "test desc"
                });
                context.SaveChanges();
            }

            using (var context = new AuthorizeDbContext(options))
            {
                context.Features.Count().Should().Be(1);
                var feature = context.Features.First();

                feature.Id.Should().Be(1);
                feature.Description.Should().Be("test desc");
                feature.Name.Should().Be("test feature");
            }
        }
Beispiel #11
0
 public GenericRepository(AuthorizeDbContext context)
 {
     _DbContext = context;
     _DbSet     = context.Set <T>();
 }
 public GenericRepository(IContextAdapter adapter)
 {
     _DbContext = adapter.GetContext();
     _DbSet     = _DbContext.Set <T>();
 }
Beispiel #13
0
 public AuthorizeRepository(AuthorizeDbContext context)
 {
     _context = context;
 }
 public UnitOfWork(AuthorizeDbContext context)
 {
     _context = context;
 }