示例#1
0
            public void FirstTimeUserLogin()
            {
                var repository = new InMemoryRepository();
                var service = new IdentityLinker(repository, new ChatService(new Mock<ICache>().Object, repository, new Mock<ICryptoService>().Object));

                var context = FakeHttpContext();
                context.Request.Cookies.Add(new HttpCookie("jabbr.state", null));  // user is not logged in

                // act
                service.LinkIdentity(context, "userid100000", "foo", "*****@*****.**");

                // assert a new user is created with the right props
                var newUser = repository.GetUserByIdentity("userid100000");
                Assert.NotNull(newUser);
                Assert.Equal("userid100000", newUser.Identity);
                Assert.Equal("foo", newUser.Name);
                Assert.Equal("*****@*****.**", newUser.Email);
            }
示例#2
0
            public void ExistingUserLoginUpdatesEmailAndGravatar()
            {
                var repository = new InMemoryRepository();
                var service = new IdentityLinker(repository, new ChatService(new Mock<ICache>().Object, repository, new Mock<ICryptoService>().Object));

                var context = FakeHttpContext();
                // user is not logged in
                context.Request.Cookies.Add(new HttpCookie("jabbr.state", null));
                // user at least logged in once
                repository.Add(new ChatUser { Identity = "userid100000", Name = "foo", Email = "*****@*****.**" });

                // act (update email)
                service.LinkIdentity(context, "userid100000", "foo", "*****@*****.**");

                // assert a new user is created with the right props
                var newUser = repository.GetUserByIdentity("userid100000");
                Assert.NotNull(newUser);
                Assert.Equal("userid100000", newUser.Identity);
                Assert.Equal("foo", newUser.Name);
                Assert.Equal("*****@*****.**", newUser.Email);
            }
示例#3
0
            public void ExistingUserWithAnotherIdentityLogin()
            {
                var repository = new InMemoryRepository();
                var service = new IdentityLinker(repository, new ChatService(new Mock<ICache>().Object, repository, new Mock<ICryptoService>().Object));

                var context = FakeHttpContext();

                var state = JsonConvert.SerializeObject(new { userId = "existinguser" });
                // user is logged in
                context.Request.Cookies.Add(new HttpCookie("jabbr.state", state));
                // user already logged with another login mechanism
                repository.Add(new ChatUser { Id = "existinguser", Identity = "userid100000", Name = "foo", Email = "*****@*****.**" });

                // act
                service.LinkIdentity(context, "userid100000-CHANGED", "foo-CHANGED", "*****@*****.**");

                // assert a new user is created with the right props
                var migratedUSer = repository.GetUserById("existinguser");
                Assert.NotNull(migratedUSer);
                Assert.Equal("userid100000-CHANGED", migratedUSer.Identity);
                Assert.Equal("foo", migratedUSer.Name); // name not updated
                Assert.Equal("*****@*****.**", migratedUSer.Email);
            }