コード例 #1
0
        public async Task FindByNameAsync_Invalid_ReturnsNull(string roleId)
        {
            using var c = new UserManagerContext(_roles);

            var result = await c.RoleManager.FindByNameAsync(roleId.ToStringInvariant()).ConfigureAwait(false);

            Assert.Null(result);
        }
コード例 #2
0
        public async Task FindByIdAsync_NoRoleDefined_ReturnsNull()
        {
            using var c = new UserManagerContext(null);

            var result = await c.RoleManager.FindByIdAsync("Admin").ConfigureAwait(false);

            Assert.Null(result);
        }
コード例 #3
0
        public async Task FindByNameAsync_UpperCaseEmailWithPassword_ReturnsIdentity(string email)
        {
            using var c = new UserManagerContext(_roles, _output);

            var result = await c.UserManager.FindByNameAsync(email.ToUpperInvariant()).ConfigureAwait(false);

            Assert.NotNull(result);
        }
コード例 #4
0
        public async Task FindByIdAsync_WithPassword_ReturnsIdentity(int contactId)
        {
            using var c = new UserManagerContext(_roles, _output);

            var result = await c.UserManager.FindByIdAsync(contactId.ToStringInvariant()).ConfigureAwait(false);

            Assert.NotNull(result);
        }
コード例 #5
0
        public async Task FindByNameAsync_EmailNoPassword_ReturnsNull(string email)
        {
            using var c = new UserManagerContext(_roles, _output);

            var result = await c.UserManager.FindByNameAsync(email).ConfigureAwait(false);

            Assert.Null(result);
        }
コード例 #6
0
        public async Task FindByIdAsync_InvalidInt_ThrowsException(string contactId)
        {
            using var c = new UserManagerContext(_roles, _output);

            Task <OntraportIdentityUser> Act() => c.UserManager.FindByIdAsync(contactId.ToStringInvariant());

            await Assert.ThrowsAsync <ArgumentException>(Act);
        }
コード例 #7
0
        public async Task FindByNameAsync_Valid_ReturnsRoleWithProperCase(string roleId, string expected)
        {
            using var c = new UserManagerContext(_roles);

            var result = await c.RoleManager.FindByNameAsync(roleId.ToStringInvariant()).ConfigureAwait(false);

            Assert.NotNull(result);
            Assert.Equal(expected, result.Name, StringComparer.InvariantCulture);
        }
コード例 #8
0
        public async Task AddToRoleAsync_Invalid_IsInRole(string role)
        {
            const string NewEmail = "*****@*****.**";

            using var c = new UserManagerContext(_roles, _output);
            var user = await c.FindOrCreateUserAsync(NewEmail, Password);

            Task Act() => c.UserManager.AddToRoleAsync(user, role);

            await Assert.ThrowsAsync <ArgumentException>(Act);
        }
コード例 #9
0
        public async Task UpdateAsync_ExistingEmail_ReturnsFailure()
        {
            const string NewEmail = "*****@*****.**";

            using var c = new UserManagerContext(_roles, _output);
            var user = await c.FindOrCreateUserAsync(NewEmail, Password);

            await c.UserManager.ChangePasswordAsync(user, Password, Password);

            var result = await c.UserManager.UpdateAsync(user);

            Assert.True(result.Succeeded);
        }
コード例 #10
0
        public async Task AddToRoleAsync_Valid_IsInRole(string role)
        {
            const string NewEmail = "*****@*****.**";

            using var c = new UserManagerContext(_roles, _output);
            var user = await c.FindOrCreateUserAsync(NewEmail, Password);

            var result = await c.UserManager.AddToRoleAsync(user, role);

            Assert.True(await c.UserManager.IsInRoleAsync(user, role));
            await c.UserManager.DeleteAsync(user);

            Assert.True(result.Succeeded);
        }
コード例 #11
0
        public async Task DeleteAsync_ValidId_LeaveContactAndRemovePassword()
        {
            const string NewEmail = "*****@*****.**";

            using var c = new UserManagerContext(_roles, _output);
            var user = await c.FindOrCreateUserAsync(NewEmail, Password);

            var result = await c.UserManager.DeleteAsync(user);

            Assert.True(result.Succeeded);
            var exist = await c.OntraportContacts.SelectAsync(user.Id);

            Assert.NotNull(exist);
            Assert.Empty(exist.IdentityPasswordHash);
        }
コード例 #12
0
        public async Task CreateAsync_ExistingEmail_ReturnsFailure()
        {
            const string NewEmail = "*****@*****.**";

            using var c = new UserManagerContext(_roles, _output);

            var user = new OntraportIdentityUser()
            {
                UserName = NewEmail,
                Email    = NewEmail
            };
            var result = await c.UserManager.CreateAsync(user, Password);

            Assert.False(result.Succeeded);
        }
コード例 #13
0
        public async Task DeleteAsync_InvalidId_ThrowsException()
        {
            const string NewEmail = "*****@*****.**";

            using var c = new UserManagerContext(_roles, _output);
            var user = new OntraportIdentityUser()
            {
                Id       = int.MaxValue,
                UserName = NewEmail,
                Email    = NewEmail
            };

            Task <IdentityResult> Act() => c.UserManager.DeleteAsync(user);

            await Assert.ThrowsAsync <HttpRequestException>(Act);
        }
コード例 #14
0
        public async Task GetRolesAsync_TwoRoles_ReturnsBoth()
        {
            const string NewEmail = "*****@*****.**";

            using var c = new UserManagerContext(_roles, _output);
            var user = await c.FindOrCreateUserAsync(NewEmail, Password);

            await c.UserManager.AddToRoleAsync(user, _roles[0]);

            await c.UserManager.AddToRoleAsync(user, _roles[1]);

            var result = await c.UserManager.GetRolesAsync(user);

            Assert.Contains(_roles[0], result);
            Assert.Contains(_roles[1], result);
            await c.UserManager.DeleteAsync(user);
        }
コード例 #15
0
        public async Task CreateAsync_NewEmail_IdReturned()
        {
            const string NewEmail = "*****@*****.**";

            using var c = new UserManagerContext(_roles, _output);
            var exist = await c.UserManager.FindByNameAsync(NewEmail);

            if (exist != null)
            {
                await c.UserManager.DeleteAsync(exist);
            }

            var user = new OntraportIdentityUser()
            {
                UserName = NewEmail,
                Email    = NewEmail
            };
            var result = await c.UserManager.CreateAsync(user, Password);

            Assert.True(result.Succeeded);
            Assert.True(user.Id > 0);
        }