public static void EnsureSeedData(this ScimDbContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            InsertSchemas(context);
        }
示例#2
0
        public StoresFixture()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkInMemoryDatabase()
                                  .BuildServiceProvider();
            var builder = new DbContextOptionsBuilder <ScimDbContext>();

            builder.UseInMemoryDatabase()
            .UseInternalServiceProvider(serviceProvider)
            .ConfigureWarnings(warnings => warnings.Ignore(InMemoryEventId.TransactionIgnoredWarning));
            var ctx = new ScimDbContext(builder.Options);

            ctx.EnsureSeedData();
            SchemaStore = new SchemaStore(ctx, new Transformers());
        }
        public static void EnsureSeedData(this ScimDbContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            InsertSchemas(context);
            InsertRepresentations(context);
            try
            {
                context.SaveChanges();
            }
            catch { }
        }
 private static void InsertSchemas(ScimDbContext context)
 {
     if (!context.Schemas.Any())
     {
         context.Schemas.Add(UserSchema);
         context.Schemas.Add(GroupSchema);
         try
         {
             context.SaveChanges();
         }
         catch
         {
             // Trace.WriteLine("duplicated keys");
         }
     }
 }
 public RepresentationStore(ScimDbContext context, ITransformers transformers)
 {
     _context      = context;
     _transformers = transformers;
 }
示例#6
0
 public ScimStore(ScimDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
 private static void InsertRepresentations(ScimDbContext context)
 {
     if (!context.Representations.Any())
     {
         context.Representations.AddRange(new[]
         {
             new Representation
             {
                 Id           = "7d79392f-8a02-494c-949e-723a4db8ed16",
                 Version      = "117ee9e4-e519-4ce6-b748-9691f70b43ce",
                 Created      = DateTime.UtcNow,
                 LastModified = DateTime.UtcNow,
                 ResourceType = Common.Constants.ResourceTypes.User,
                 Attributes   = new List <RepresentationAttribute>
                 {
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _externalId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _adrId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _localeId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _ageId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _genderId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _ethnicityId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _birthDateId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _locationId
                     }
                 }
             },
             new Representation
             {
                 Id           = "c41c9e28-a4f8-447d-b170-f99563257d15",
                 Version      = "b424ab6d-244d-4fa5-b4af-a27a23665996",
                 Created      = DateTime.UtcNow,
                 LastModified = DateTime.UtcNow,
                 ResourceType = Common.Constants.ResourceTypes.User,
                 Attributes   = new List <RepresentationAttribute>
                 {
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _externalId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _adrId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _localeId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _ageId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _genderId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _ethnicityId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _birthDateId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _locationId
                     }
                 }
             }
         });
     }
 }
示例#8
0
 public SchemaStore(ScimDbContext context, ITransformers transformers)
 {
     _context      = context;
     _transformers = transformers;
 }
 private static void InsertRepresentations(ScimDbContext context)
 {
     if (!context.Representations.Any())
     {
         context.Representations.AddRange(new[]
         {
             new Representation
             {
                 Id           = "7d79392f-8a02-494c-949e-723a4db8ed16",
                 Version      = "117ee9e4-e519-4ce6-b748-9691f70b43ce",
                 Created      = DateTime.UtcNow,
                 LastModified = DateTime.UtcNow,
                 ResourceType = SimpleIdentityServer.Scim.Common.Constants.ResourceTypes.User,
                 Attributes   = new List <RepresentationAttribute>
                 {
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = SimpleIdentityServer.Scim.Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _externalId,
                         Value             = "administrator"
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = SimpleIdentityServer.Scim.Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _adrId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = SimpleIdentityServer.Scim.Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _localeId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = SimpleIdentityServer.Scim.Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _ageId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = SimpleIdentityServer.Scim.Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _genderId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = SimpleIdentityServer.Scim.Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _ethnicityId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = SimpleIdentityServer.Scim.Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _birthDateId
                     },
                     new RepresentationAttribute
                     {
                         Id   = Guid.NewGuid().ToString(),
                         Type = SimpleIdentityServer.Scim.Common.Constants.SchemaAttributeTypes.String,
                         SchemaAttributeId = _locationId
                     }
                 }
             }
         });
     }
 }