Ejemplo n.º 1
0
 public DbContextSeeder(IAddNewUser addNewUser,
                        IConfirmUserEmailByToken confirmUserEmailByToken,
                        IAddNewDomain addNewDomain,
                        IGetDomainByName getDomainByName,
                        ISetDomainOwner setDomainOwner,
                        IAddNewRole addNewRole,
                        IGetRoleByName getRoleByName,
                        IAddUserToDomain addUserToDomain)
 {
     this.addNewUser              = addNewUser;
     this.addNewDomain            = addNewDomain;
     this.confirmUserEmailByToken = confirmUserEmailByToken;
     this.getDomainByName         = getDomainByName;
     this.setDomainOwner          = setDomainOwner;
     this.addNewRole              = addNewRole;
     this.getRoleByName           = getRoleByName;
     this.addUserToDomain         = addUserToDomain;
 }
Ejemplo n.º 2
0
        public void SeedUsers(IAddNewUser addNewUser,
                              IConfirmUserEmailByToken confirmUserEmailByToken,
                              IGetDomainByName getDomainByName,
                              ISetDomainOwner setDomainOwner)
        {
            foreach (var user in users)
            {
                var domain = getDomainByName.Invoke("jan");
                var model  = new UserModel
                {
                    Email    = $"{user}@test.pl",
                    Password = "******",
                    Name     = user,
                    Domain   = domain
                };

                var dbUser = addNewUser.Invoke(model);

                if (dbUser == null)
                {
                    continue;
                }

                var token = dbUser.Tokens.FirstOrDefault().SecretToken;
                confirmUserEmailByToken.Invoke(token);

                var role = roles.Find(x => x.Name == "User");

                if (user != "owner")
                {
                    setDomainOwner.Invoke(dbUser.Id, domain.Id);
                    var domain2 = getDomainByName.Invoke("roland");
                    setDomainOwner.Invoke(dbUser.Id, domain2.Id);

                    role = roles.Find(x => x.Name == "Owner");
                }

                addUserToDomain.Invoke(dbUser.Id, domain.Id, role.Id);
            }
        }