Ejemplo n.º 1
0
        public void InsertUserTwice()
        {
            using (var fixture = new FixtureInit("http://localhost"))
            {
                //INIT
                var register = new UsersRepository(fixture.Setup.Context);

                //ACT / POST
                var user = new User()
                {
                    Email = "email",
                    //SecretPhrase = "sec",
                    //Password = "******"
                };

                register.Save(user);

                var newUser = new User()
                {
                    Email = "email",
                    //SecretPhrase = "sec",
                    //Password = "******"
                };

                register.Save(newUser);
            }
        }
Ejemplo n.º 2
0
        public void GetApiToken_WrongPassword_ReturnedTokenWillBeNull()
        {
            using (var fixture = new FixtureInit("http://localhost"))
            {
                // arrange
                var userRepository = new UsersRepository(fixture.Setup.Context);
                var hashService = new HashService();

                var service = new ApiService(userRepository, hashService);

                var email = "*****@*****.**";
                var password = "******";
                var passwordHash = hashService.CreateMD5Hash(password);
                var apiToken = hashService.CreateApiToken(email, password);

                userRepository.Save(
                    new User
                    {
                        Email = email,
                        PasswordHash = passwordHash,
                        ApiToken = apiToken,
                        Temp = false
                    }
                );

                // act
                var result = service.GetApiToken(email, password + "xx");

                // assert
                Assert.That(result, Is.Null);
            }
        }
Ejemplo n.º 3
0
        private static void SendEmailNotificationsToUsers(UsersRepository usersRepository, EmailService emailService)
        {
            var notTempUsers = usersRepository.Users.Where(u => u.Temp == false);

            foreach (var user in notTempUsers)
            {
                if (user.Email != "Admin")
                {
                    var message = CreateEmailMessageForUser(user);

                    try
                    {
                        emailService.SendEmail(message, "support");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to send email for {0}", user.Email);
                        Console.WriteLine("\tDetails: {0}", e.Message);
                        continue;
                    }


                    Console.WriteLine(String.Format("Sent email for {0}", user.Email));
                }
            }
        }
Ejemplo n.º 4
0
        private void SubmitUsersToRepository(UsersRepository register, int usersCount, int tempUsers)
        {
            for (int users = 0; users < usersCount; users++)
            {
                register.Save(new User { Email = users + "@a.com", Temp = false });
            }

            for (int temp = 0; temp < tempUsers; temp++)
            {
                register.Save(new User { Email = "temp" + temp + "@a.com", Temp = true });
            }
        }
Ejemplo n.º 5
0
        public void Smoke()
        {
            using (var fixture = new FixtureInit("http://localhost"))
            {
                // arrange
                var userRepository = new UsersRepository(fixture.Setup.Context);
                var hashService = new HashService();

                // act / post
                var service = new ApiService(userRepository, hashService);
                Assert.That(service, Is.Not.Null);
            }
        }
Ejemplo n.º 6
0
        private static void HashAllPasswords(UsersRepository usersRepository, HashService hash)
        {
            foreach (var user in usersRepository.Users.Where(u => u.Temp == false))
            {
                if (string.IsNullOrEmpty(user.PasswordHash))
                {
                    var passwordHash = hash.CreateMD5Hash(user.Password);
                    user.PasswordHash = passwordHash;

                    usersRepository.SaveUser(user);

                    Console.WriteLine(string.Format("Hashed password for {0}", user.Email));
                }
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Trackyt.net - upgrade for v.1.0.1.\nHash all user passwords.\n");

            try
            {
                // repositories
                var usersRepository = new UsersRepository();

                // services
                var hash = new HashService();

                HashAllPasswords(usersRepository, hash);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Ejemplo n.º 8
0
        public void InsertUser()
        {
            using (var fixture = new FixtureInit("http://localhost"))
            {
                //INIT
                var register = new UsersRepository(fixture.Setup.Context);

                //ACT
                var user = new User()
                {
                    Email = "email",
                    //SecretPhrase = "sec",
                    //Password = "******"
                };

                register.Save(user);

                //POST
                var actual = register.Users.WithEmail("email");
                Assert.That(actual, Is.Not.Null);
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Trackyt.net - upgrade for v.1.0.1.\nNotify all users about password remove.\n");

            try
            {
                // repositories
                var usersRepository = new UsersRepository();
                var credentialsRepository = new CredentialsRepository();

                // services
                var credentialService = new CredentialsService(credentialsRepository);
                var emailService = new EmailService(credentialService);

                SendEmailNotificationsToUsers(usersRepository, emailService);
            }
            catch (Exception e)
            {
                Console.WriteLine("User notification failed!");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Ejemplo n.º 10
0
        public void FindUserById()
        {
            using (var fixture = new FixtureInit("http://localhost"))
            {
                //INIT
                var register = new UsersRepository(fixture.Setup.Context);

                var user = new User()
                {
                    Email = "email",
                    //SecretPhrase = "sec",
                    //Password = "******"
                };

                register.Save(user);

                //ACT
                var foundUser = register.Users.WithId(user.Id);

                //POST
                Assert.That(foundUser, Is.Not.Null);
                Assert.That(foundUser.Id, Is.EqualTo(user.Id));
            }
        }
Ejemplo n.º 11
0
        public void WithTempExtension()
        {
            using (var fixture = new FixtureInit("http://localhost"))
            {
                //arrange
                var register = new UsersRepository(fixture.Setup.Context);
                SubmitUsersToRepository(register, 5, 1);

                //act
                var usersCount = register.Users.WithTemp(false).Count();
                var tempCount = register.Users.WithTemp(true).Count();

                //post
                Assert.That(usersCount, Is.EqualTo(6)); 
                Assert.That(tempCount, Is.EqualTo(1));
            }
        }