Пример #1
1
        private static void CreateTestDataIn(Database db)
        {
            var createRole = new CreateRole
            {
                Name = "Admin",
                Permissions = new[] {"View Users", "Edit Users", "Deactivate Users"}
            };
            db.CreateRole(createRole);
            db.CreateUser(new CreateUser {FullName = "Dan Barua", UserName = "******", RoleId = createRole.Id.GetValueOrDefault()});
            db.CreateUser(new CreateUser {FullName = "Jonathon Channon", UserName = "******", RoleId = createRole.Id.GetValueOrDefault()});

            // let's generate some random data!
            var fixture = new Fixture {RepeatCount = 100};

            var roles = fixture.CreateMany<CreateRole>().ToList();
            var users = fixture.CreateMany<CreateUser>().ToList();
            foreach (var r in roles)
            {
                db.CreateRole(r);
            }

            var roleCount = roles.Count();
            foreach (var u in users)
            {
                u.RoleId = roles.Skip(new Random().Next(0, roleCount)).Take(1).First().Id.GetValueOrDefault();
                // select random id from roles
                db.CreateUser(u);
            }
        }
Пример #2
0
 public void CreateRole(CreateRole command)
 {
     var role = new RoleDetails()
                    {
                        Id = Guid.NewGuid(),
                        Name = command.Name,
                        Permissions = command.Permissions,
                        Created = DateTime.Now
                    };
     roleDatabase.Add(role);
     command.Id = role.Id;
 }