AddUser() public method

public AddUser ( string userName, string email, string password ) : JabbR.Models.ChatUser
userName string
email string
password string
return JabbR.Models.ChatUser
Exemplo n.º 1
0
            public void ThrowsIfNameIsNullOrEmpty()
            {
                var repository = new InMemoryRepository();
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                Assert.Throws<InvalidOperationException>(() => service.AddUser(null, "email", password: null));
                Assert.Throws<InvalidOperationException>(() => service.AddUser(String.Empty, "email", password: null));
            }
Exemplo n.º 2
0
            public void ThrowsIfPasswordIsTooShort()
            {
                var repository = new InMemoryRepository();
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                Assert.Throws<InvalidOperationException>(() => service.AddUser("SomeUser", "email", password: "******"));
            }
Exemplo n.º 3
0
            public void ThrowsIfNameIsInValid()
            {
                var repository = new InMemoryRepository();
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                Assert.Throws<InvalidOperationException>(() => service.AddUser("some in valid name", "email", password: null));
            }
Exemplo n.º 4
0
            public void UnicodeNameIsValid()
            {
                // Fix issue #370
                var repository = new InMemoryRepository();
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);
                var user = service.AddUser("ТарасБуга", "email", "password");

                Assert.Equal("ТарасБуга", user.Name);
            }
Exemplo n.º 5
0
            public void ThrowsIfNameInUse()
            {
                var repository = new InMemoryRepository();
                repository.Add(new ChatUser()
                {
                    Name = "taken"
                });
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                Assert.Throws<InvalidOperationException>(() => service.AddUser("taken", "email", password: null));
            }
Exemplo n.º 6
0
            public void AddsUserToRepository()
            {
                var crypto = new Mock<ICryptoService>();
                crypto.Setup(c => c.CreateSalt()).Returns("salted");
                var repository = new InMemoryRepository();
                var service = new MembershipService(repository, crypto.Object);

                service.AddUser("SomeUser", "email", password: "******");

                var user = repository.GetUserByName("SomeUser");
                Assert.NotNull(user);
                Assert.Equal("email", user.Email);
                Assert.Equal("SomeUser", user.Name);
                Assert.Equal("salted", user.Salt);
                Assert.Equal("8f5793009fe15c2227e3528d0507413a83dff10635d3a6acf1ba3229a03380d8", user.HashedPassword);
            }
Exemplo n.º 7
0
            public void AddsNumberToUserNameIfTaken()
            {
                var repository = new InMemoryRepository();
                repository.Add(new ChatUser
                {
                    Name = "david",
                    Id = "1"
                });

                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                var claims = new List<Claim>();
                claims.Add(new Claim(ClaimTypes.Name, "david"));
                claims.Add(new Claim(ClaimTypes.AuthenticationMethod, "provider"));
                claims.Add(new Claim(ClaimTypes.NameIdentifier, "identity"));
                var claimsIdentity = new ClaimsIdentity(claims);
                var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

                service.AddUser(claimsPrincipal);

                var user = repository.GetUserByIdentity("provider", "identity");
                Assert.NotNull(user);
                Assert.Equal("david1", user.Name);
                Assert.Null(user.Identity);
                Assert.Null(user.Email);
                Assert.Null(user.Hash);
                Assert.Equal(1, user.Identities.Count);
                Assert.Equal("identity", user.Identities.First().Identity);
            }
Exemplo n.º 8
0
            public void AddsAuthUserToRepository()
            {
                var repository = new InMemoryRepository();
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                var claims = new List<Claim>();
                claims.Add(new Claim(ClaimTypes.Name, "SomeUser"));
                claims.Add(new Claim(ClaimTypes.AuthenticationMethod, "provider"));
                claims.Add(new Claim(ClaimTypes.NameIdentifier, "identity"));
                claims.Add(new Claim(ClaimTypes.Email, "email"));
                var claimsIdentity = new ClaimsIdentity(claims);
                var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

                service.AddUser(claimsPrincipal);

                var user = repository.GetUserByIdentity("provider", "identity");
                Assert.NotNull(user);
                Assert.Equal("SomeUser", user.Name);
                Assert.Null(user.Identity);
                Assert.Null(user.Email);
                Assert.Equal("0c83f57c786a0b4a39efab23731c7ebc", user.Hash);
                Assert.Equal(1, user.Identities.Count);
                Assert.Equal("email", user.Identities.First().Email);
            }
Exemplo n.º 9
0
            public void AddsNumberToUserNameIfTaken()
            {
                var repository = new InMemoryRepository();
                repository.Add(new ChatUser
                {
                    Name = "david",
                    Id = "1"
                });

                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                service.AddUser("david", "provider", "identity", email: null);

                var user = repository.GetUserByIdentity("provider", "identity");
                Assert.NotNull(user);
                Assert.Equal("david1", user.Name);
                Assert.Null(user.Identity);
                Assert.Null(user.Email);
                Assert.Null(user.Hash);
                Assert.Equal(1, user.Identities.Count);
                Assert.Equal("identity", user.Identities.First().Identity);
            }
Exemplo n.º 10
0
            public void AddsAuthUserToRepository()
            {
                var repository = new InMemoryRepository();
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                service.AddUser("SomeUser", "provider", "identity", "email");

                var user = repository.GetUserByIdentity("provider", "identity");
                Assert.NotNull(user);
                Assert.Equal("SomeUser", user.Name);
                Assert.Null(user.Identity);
                Assert.Null(user.Email);
                Assert.Equal("0c83f57c786a0b4a39efab23731c7ebc", user.Hash);
                Assert.Equal(1, user.Identities.Count);
                Assert.Equal("email", user.Identities.First().Email);
            }