示例#1
0
        public async Task Initialize()
        {
            ApplicationDbFactory = new ApplicationDbFactory("InMemoryDatabase");
            await ApplicationDbFactory.Create().Database.EnsureDeletedAsync();

            await ApplicationDbFactory.Create().Database.EnsureCreatedAsync();

            ApplicationDbFactory.Create().ResetValueGenerators();
            ApplicationUserRepository = new UserRepository(ApplicationDbFactory.Create(), ApplicationUserValidator);
            FollowerRepository        = new FollowerRepository(ApplicationDbFactory.Create(), FollowerValidator);
            CredentialRepository      = new CredentialRepository(ApplicationDbFactory.Create(), CredentialValidator);
            CredentialTypeRepository  = new CredentialTypeRepository(ApplicationDbFactory.Create(), CredentialTypeValidator);
            RoleRepository            = new RoleRepository(ApplicationDbFactory.Create(), RoleValidator);
            UserRoleRepository        = new UserRoleRepository(ApplicationDbFactory.Create(), UserRoleValidator);
            RolePermissionRepository  = new RolePermissionRepository(ApplicationDbFactory.Create(), RolePermissionValidator);
            PermissionRepository      = new PermissionRepository(ApplicationDbFactory.Create(), PermissionValidator);
            HttpContextAccessor       = new HttpContextAccessor(); // NOTE: Don't actually use it, when using Startup it will inject the HttpContext. (here it will always be null)
            UserManager = new UserManager(ApplicationUserRepository, CredentialTypeRepository, CredentialRepository, RoleRepository, UserRoleRepository, RolePermissionRepository, PermissionRepository, HttpContextAccessor, Hasher, SaltGenerator);
            UserService = new UserService(UserManager, ApplicationUserRepository, FollowerRepository);

            // A Credential type is required for a user to be able to login or register.
            await CredentialTypeRepository.CreateAsync(new CredentialType
            {
                Code     = "Email",
                Name     = "Email",
                Position = 1
            });
        }
示例#2
0
        public async Task InitializeAsync()
        {
            ApplicationDbFactory = new ApplicationDbFactory("InMemoryDatabase");
            await ApplicationDbFactory.Create().Database.EnsureDeletedAsync();

            await ApplicationDbFactory.Create().Database.EnsureCreatedAsync();

            ApplicationDbFactory.Create().ResetValueGenerators();

            ApplicationUserRepository = new UserRepository(ApplicationDbFactory.Create(), ApplicationUserValidator);
            FollowerRepository        = new FollowerRepository(ApplicationDbFactory.Create(), FollowerValidator);
            CredentialRepository      = new CredentialRepository(ApplicationDbFactory.Create(), CredentialValidator);
            CredentialTypeRepository  = new CredentialTypeRepository(ApplicationDbFactory.Create(), CredentialTypeValidator);
            RoleRepository            = new RoleRepository(ApplicationDbFactory.Create(), RoleValidator);
            UserRoleRepository        = new UserRoleRepository(ApplicationDbFactory.Create(), UserRoleValidator);
            RolePermissionRepository  = new RolePermissionRepository(ApplicationDbFactory.Create(), RolePermissionValidator);
            PermissionRepository      = new PermissionRepository(ApplicationDbFactory.Create(), PermissionValidator);
            HttpContextAccessor       = new HttpContextAccessor(); // NOTE: Don't actually use it, when using Startup it will inject the HttpContext. (here it will always be null)

            UserManager     = new UserManager(ApplicationUserRepository, CredentialTypeRepository, CredentialRepository, RoleRepository, UserRoleRepository, RolePermissionRepository, PermissionRepository, HttpContextAccessor, Hasher, SaltGenerator);
            UserService     = new UserService(UserManager, ApplicationUserRepository, FollowerRepository);
            FollowerService = new FollowerService(FollowerRepository, ApplicationUserRepository);

            // A Credential type is required for a user to be able to login or register.
            await CredentialTypeRepository.CreateAsync(new CredentialType
            {
                Code     = "Email",
                Name     = "Email",
                Position = 1
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });
        }
示例#3
0
        public async Task Initialize()
        {
            ApplicationDbFactory = new ApplicationDbFactory("InMemoryDatabase");
            await ApplicationDbFactory.Create().Database.EnsureDeletedAsync();

            await ApplicationDbFactory.Create().Database.EnsureCreatedAsync();

            ApplicationDbFactory.Create().ResetValueGenerators();

            MemeRepository            = new MemeRepository(ApplicationDbFactory.Create(), MemeValidator);
            ApplicationUserRepository = new UserRepository(ApplicationDbFactory.Create(), ApplicationUserValidator);
            FollowerRepository        = new FollowerRepository(ApplicationDbFactory.Create(), FollowerValidator);
            CredentialRepository      = new CredentialRepository(ApplicationDbFactory.Create(), CredentialValidator);
            CredentialTypeRepository  = new CredentialTypeRepository(ApplicationDbFactory.Create(), CredentialTypeValidator);
            RoleRepository            = new RoleRepository(ApplicationDbFactory.Create(), RoleValidator);
            UserRoleRepository        = new UserRoleRepository(ApplicationDbFactory.Create(), UserRoleValidator);
            RolePermissionRepository  = new RolePermissionRepository(ApplicationDbFactory.Create(), RolePermissionValidator);
            PermissionRepository      = new PermissionRepository(ApplicationDbFactory.Create(), PermissionValidator);
            CommentRepository         = new CommentRepository(ApplicationDbFactory.Create(), CommentValidator);
            HttpContextAccessor       = new HttpContextAccessor(); // NOTE: Don't actually use it, when using Startup it will inject the HttpContext. (here it will always be null)

            UserManager    = new UserManager(ApplicationUserRepository, CredentialTypeRepository, CredentialRepository, RoleRepository, UserRoleRepository, RolePermissionRepository, PermissionRepository, HttpContextAccessor, Hasher, SaltGenerator);
            UserService    = new UserService(UserManager, ApplicationUserRepository, FollowerRepository);
            CommentService = new CommentService(CommentRepository, MemeRepository);

            // A Credential type is required for a user to be able to login or register.
            await CredentialTypeRepository.CreateAsync(new CredentialType
            {
                Code     = "Email",
                Name     = "Email",
                Position = 1
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            Meme meme = new Meme
            {
                Id       = "a0Q558q",
                ImageUrl = "https://images-cdn.9gag.com/photo/a0Q558q_700b.jpg",
                VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0Q558q_460sv.mp4",
                PageUrl  = "http://9gag.com/gag/a0Q558q",
                Title    = "Old but Gold"
            };
            await MemeRepository.CreateAsync(meme);
        }
示例#4
0
        public User Validate(string loginTypeCode, string identifier, string secret)
        {
            CredentialType credentialType = new CredentialTypeRepository(storage).One(loginTypeCode);

            if (credentialType == null)
            {
                return(null);
            }

            Credential credential = new CredentialRepository(storage).One(credentialType.Id, identifier, secret);

            if (credential == null)
            {
                return(null);
            }

            return(new UserRepository(storage).One(credential.UserId));
        }
        public async Task InitializeAsync()
        {
            ApplicationDbFactory = new ApplicationDbFactory("InMemoryDatabase");
            await ApplicationDbFactory.Create().Database.EnsureDeletedAsync();

            await ApplicationDbFactory.Create().Database.EnsureCreatedAsync();

            ApplicationDbFactory.Create().ResetValueGenerators();

            MemeRepository            = new MemeRepository(ApplicationDbFactory.Create(), MemeValidator);
            SharedMemeRepository      = new SharedMemeRepository(ApplicationDbFactory.Create(), SharedMemeValidator);
            ApplicationUserRepository = new UserRepository(ApplicationDbFactory.Create(), ApplicationUserValidator);
            FollowerRepository        = new FollowerRepository(ApplicationDbFactory.Create(), FollowerValidator);
            CredentialRepository      = new CredentialRepository(ApplicationDbFactory.Create(), CredentialValidator);
            CredentialTypeRepository  = new CredentialTypeRepository(ApplicationDbFactory.Create(), CredentialTypeValidator);
            RoleRepository            = new RoleRepository(ApplicationDbFactory.Create(), RoleValidator);
            UserRoleRepository        = new UserRoleRepository(ApplicationDbFactory.Create(), UserRoleValidator);
            RolePermissionRepository  = new RolePermissionRepository(ApplicationDbFactory.Create(), RolePermissionValidator);
            PermissionRepository      = new PermissionRepository(ApplicationDbFactory.Create(), PermissionValidator);
            CommentRepository         = new CommentRepository(ApplicationDbFactory.Create(), CommentValidator);
            HttpContextAccessor       = new HttpContextAccessor(); // NOTE: Don't actually use it, when using Startup it will inject the HttpContext. (here it will always be null)

            UserManager        = new UserManager(ApplicationUserRepository, CredentialTypeRepository, CredentialRepository, RoleRepository, UserRoleRepository, RolePermissionRepository, PermissionRepository, HttpContextAccessor, Hasher, SaltGenerator);
            UserService        = new UserService(UserManager, ApplicationUserRepository, FollowerRepository);
            FollowerService    = new FollowerService(FollowerRepository, ApplicationUserRepository);
            MemeSharingService = new MemeSharingService(SharedMemeRepository, ApplicationUserRepository);

            // NOTE: A CredentialType is required for a user to be able to login or register.
            await CredentialTypeRepository.CreateAsync(new CredentialType
            {
                Code     = "Email",
                Name     = "Email",
                Position = 1
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            FollowerDto followerDto1 = new FollowerDto
            {
                UserId         = 1,
                FollowerUserId = 2
            };
            FollowerDto followerDto2 = new FollowerDto
            {
                UserId         = 2,
                FollowerUserId = 1
            };
            await FollowerService.FollowUserAsync(followerDto1);

            await FollowerService.FollowUserAsync(followerDto2);

            Meme meme1 = new Meme
            {
                Id       = "a0Q558q",
                ImageUrl = "https://images-cdn.9gag.com/photo/a0Q558q_700b.jpg",
                VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0Q558q_460sv.mp4",
                PageUrl  = "http://9gag.com/gag/a0Q558q",
                Title    = "Old but Gold"
            };
            await MemeRepository.CreateAsync(meme1);

            Meme meme2 = new Meme
            {
                Id       = "a0QQZoL",
                ImageUrl = "https://images-cdn.9gag.com/photo/a0QQZoL_700b.jpg",
                VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0QQZoL_460sv.mp4",
                PageUrl  = "http://9gag.com/gag/a0QQZoL",
                Title    = "Austin was listed for a heart transplant, and the doctor said he would deliver the news a heart was available dressed as Chewbacca."
            };
            await MemeRepository.CreateAsync(meme2);
        }