Ejemplo n.º 1
0
        public async Task UserProvidersDelete()
        {
            //Get Services
            var serviceProvider = GetServices();
            var dbContext       = serviceProvider.GetRequiredService <AdminDbContext>();
            var identityService = serviceProvider.GetRequiredService <IIdentityService>();

            // Get controller
            var controller = PrepareIdentityController(serviceProvider);
            var userDto    = IdentityDtoMock.GenerateRandomUser(0);
            await identityService.CreateUserAsync(userDto);

            var userId = await dbContext.Users.Where(x => x.UserName == userDto.UserName).Select(x => x.Id).SingleOrDefaultAsync();

            var randomProviderKey   = Guid.NewGuid().ToString();
            var randomProviderLogin = Guid.NewGuid().ToString();

            var provider = IdentityMock.GenerateRandomUserProviders(randomProviderKey, randomProviderLogin, userId);

            await dbContext.UserLogins.AddAsync(provider);

            await dbContext.SaveChangesAsync();

            var providersDto = IdentityDtoMock.GenerateRandomUserProviders(randomProviderKey, randomProviderLogin, userId);
            var result       = await controller.UserProvidersDelete(providersDto);

            // Assert
            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            viewResult.ActionName.Should().Be("UserProviders");

            var userProvider = await dbContext.UserLogins.Where(x => x.ProviderKey == randomProviderKey).SingleOrDefaultAsync();

            userProvider.Should().BeNull();
        }
Ejemplo n.º 2
0
        public async Task DeleteUserProviderAsync()
        {
            using (var context = new AdminIdentityDbContext(_dbContextOptions))
            {
                var testUserManager = GetTestUserManager(context);
                var testRoleManager = GetTestRoleManager(context);

                var mapper = GetMapper();

                var identityRepository        = GetIdentityRepository(context, testUserManager, testRoleManager, mapper);
                var localizerIdentityResource = new IdentityServiceResources();
                var identityService           = GetIdentityService(identityRepository, localizerIdentityResource, mapper);

                //Generate random new user
                var userDto = IdentityDtoMock <string> .GenerateRandomUser();

                await identityService.CreateUserAsync(userDto);

                //Get new user
                var user = await context.Users.Where(x => x.UserName == userDto.UserName).SingleOrDefaultAsync();

                userDto.Id = user.Id;

                var newUserDto = await identityService.GetUserAsync(userDto.Id.ToString());

                //Assert new user
                userDto.Should().BeEquivalentTo(newUserDto);

                var userProvider = IdentityMock.GenerateRandomUserProviders(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
                                                                            newUserDto.Id);

                //Add new user login
                await context.UserLogins.AddAsync(userProvider);

                await context.SaveChangesAsync();

                //Get added user provider
                var addedUserProvider = await context.UserLogins.Where(x => x.ProviderKey == userProvider.ProviderKey && x.LoginProvider == userProvider.LoginProvider).SingleOrDefaultAsync();

                addedUserProvider.Should().NotBeNull();

                var userProviderDto = IdentityDtoMock <string> .GenerateRandomUserProviders(userProvider.ProviderKey, userProvider.LoginProvider,
                                                                                            userProvider.UserId);

                await identityService.DeleteUserProvidersAsync(userProviderDto);

                //Get deleted user provider
                var deletedUserProvider = await context.UserLogins.Where(x => x.ProviderKey == userProvider.ProviderKey && x.LoginProvider == userProvider.LoginProvider).SingleOrDefaultAsync();

                deletedUserProvider.Should().BeNull();
            }
        }
Ejemplo n.º 3
0
        public async Task DeleteUserProviderAsync()
        {
            using (var context = new AdminIdentityDbContext(_dbContextOptions))
            {
                var identityService = GetIdentityService(context);

                //Generate random new user
                var userDto = IdentityDtoMock <string> .GenerateRandomUser();

                await identityService.CreateUserAsync(userDto);

                //Get new user
                var user = await context.Users.Where(x => x.Email == userDto.Email).SingleOrDefaultAsync();

                userDto.Id = user.Id;

                var newUserDto = await identityService.GetUserAsync(userDto.Id.ToString());

                //Assert new user
                userDto.ShouldBeEquivalentTo(newUserDto);

                var userProvider = IdentityMock.GenerateRandomUserProviders(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
                                                                            newUserDto.Id);

                //Add new user login
                await context.UserLogins.AddAsync(userProvider);

                await context.SaveChangesAsync();

                //Get added user provider
                var addedUserProvider = await context.UserLogins.Where(x => x.ProviderKey == userProvider.ProviderKey && x.LoginProvider == userProvider.LoginProvider).SingleOrDefaultAsync();

                addedUserProvider.Should().NotBeNull();

                var userProviderDto = IdentityDtoMock <string> .GenerateRandomUserProviders(userProvider.ProviderKey, userProvider.LoginProvider,
                                                                                            userProvider.UserId);

                await identityService.DeleteUserProvidersAsync(userProviderDto);

                //Get deleted user provider
                var deletedUserProvider = await context.UserLogins.Where(x => x.ProviderKey == userProvider.ProviderKey && x.LoginProvider == userProvider.LoginProvider).SingleOrDefaultAsync();

                deletedUserProvider.Should().BeNull();
            }
        }
Ejemplo n.º 4
0
        private RoleManager <UserIdentityRole> GetTestRoleManager(AdminIdentityDbContext context)
        {
            var testRoleManager = IdentityMock.TestRoleManager(new RoleStore <UserIdentityRole, AdminIdentityDbContext, string, UserIdentityUserRole, UserIdentityRoleClaim>(context, new IdentityErrorDescriber()));

            return(testRoleManager);
        }
Ejemplo n.º 5
0
        private UserManager <UserIdentity> GetTestUserManager(AdminIdentityDbContext context)
        {
            var testUserManager = IdentityMock.TestUserManager(new UserStore <UserIdentity, UserIdentityRole, AdminIdentityDbContext, string, UserIdentityUserClaim, UserIdentityUserRole, UserIdentityUserLogin, UserIdentityUserToken, UserIdentityRoleClaim>(context, new IdentityErrorDescriber()));

            return(testUserManager);
        }