Exemple #1
0
        public void ExistingUserAuthenticatingShouldUseExistingUser()
        {
            var authenticatedUser = new AuthenticatedUser(Guid.NewGuid(), "user1", "email1", "picture", new List<AuthenticationProvider>()
            {
                new AuthenticationProvider(Guid.NewGuid(), "Facebook", "12345"),
            });

            var authenticatedClient = new AuthenticatedClient("Facebook")
            {
                UserInformation = new UserInformation()
                {
                    Id = "12345",
                    Name = "user1",
                    Email = "email",
                    Picture = "picture",
                }
            };
            SaveEntities(authenticatedUser);

            var sut = new UserMapper(() => Session);
            AuthenticatedUser actual = sut.MapUser(authenticatedClient);

            actual.ShouldEqual(authenticatedUser);

            int count = Session.QueryOver<AuthenticatedUser>()
                .RowCount();

            Assert.That(count, Is.EqualTo(1));
        }
Exemple #2
0
        public AuthenticatedUser MapUser(IAuthenticatedClient client)
        {
            ISession session = getSession();
            AuthenticatedUser user = session.QueryOver<AuthenticatedUser>()
                .JoinQueryOver<AuthenticationProvider>(x => x.AuthenticationProviders)
                .Where(y => y.Name == client.ProviderName)
                .Where(y => y.UserId == client.UserInformation.Id)
                .SingleOrDefault();

            if (user != null) return user;

            user = new AuthenticatedUser(SequentialGuid.NewGuid(), client.UserInformation.Name, client.UserInformation.Email, client.UserInformation.Picture,
                new List<AuthenticationProvider>()
                {
                    new AuthenticationProvider(SequentialGuid.NewGuid(), client.ProviderName, client.UserInformation.Id),
                });

            session.Save(user);
            return user;
        }
Exemple #3
0
        public void NewUserAuthenticatingShouldCreateNewUser()
        {
            var authenticatedUser = new AuthenticatedUser(Guid.NewGuid(), "user1", "Email1", "picture", new List<AuthenticationProvider>()
            {
                new AuthenticationProvider(Guid.NewGuid(), "Facebook", "12345"),
            });

            var authenticatedClient = new AuthenticatedClient("Facebook")
            {
                UserInformation = new UserInformation()
                {
                    Id = "12345",
                    Name = "user1",
                    Email = "email",
                    Picture = "picture",
                }
            };

            OpenTransaction();
            var sut = new UserMapper(() => Session);
            AuthenticatedUser actual = sut.MapUser(authenticatedClient);
            CommitTransaction();

            actual.ShouldEqual(authenticatedUser);

            int count = Session.QueryOver<AuthenticatedUser>()
                .RowCount();

            Assert.That(count, Is.EqualTo(1));

            AuthenticatedUser userInDb = Session.QueryOver<AuthenticatedUser>()
                .Where(x => x.UserName == authenticatedUser.UserName)
                .SingleOrDefault();

            userInDb.ShouldEqual(authenticatedUser);

        }