public void Registration_fails_with_duplicate_emails()
        {
            var store = new UserRegistrationStore();
            var svc = new UserRegistrationService(store);

            svc.Register("*****@*****.**", "password");

            Assert.Throws<DbUpdateException>(() => svc.Register("*****@*****.**", "other"));
        }
        public void End_to_end_failed_login()
        {
            var store = new UserRegistrationStore();
            var svc = new UserRegistrationService(store);

            svc.Register("*****@*****.**", "password");

            Assert.Equal(Guid.Empty, svc.Login("*****@*****.**", "wrong"));
            Assert.Equal(Guid.Empty, svc.Login("*****@*****.**", "password"));
        }
        public void Password_is_saved()
        {
            var store = new UserRegistrationStore();
            var reg = new UserRegistration("*****@*****.**", "password");

            store.Save(reg);

            var stored = store.Users.FirstOrDefault(x => x.Id == reg.Id);

            Assert.NotNull(stored);
            Assert.True(stored.PasswordMatches("password"));
        }
        public void Password_is_hashed()
        {
            var store = new UserRegistrationStore();
            var reg = new UserRegistration("*****@*****.**", "password");

            store.Save(reg);

            var stored = store.Users.FirstOrDefault(x => x.Id == reg.Id);

            Assert.NotNull(stored);
            Assert.False(Encoding.UTF8.GetBytes("password").SequenceEqual(stored.Password));
        }
        public void End_to_end_success()
        {
            var store = new UserRegistrationStore();
            var svc = new UserRegistrationService(store);

            svc.Register("*****@*****.**", "password");

            var id = svc.Login("*****@*****.**", "password");
            Assert.NotEqual(Guid.Empty, id);

            var user = store.Users.FirstOrDefault(x => x.Id == id);
            Assert.Equal("*****@*****.**", user.Email);
        }
        public void UserRegistration_is_saved()
        {
            var store = new UserRegistrationStore();
            var reg = new UserRegistration("*****@*****.**", "password");

            store.Save(reg);

            var stored = store.Users.FirstOrDefault(x => x.Id == reg.Id);

            Assert.NotNull(stored);
            Assert.Equal("*****@*****.**", reg.Email);
        }
 public void Dispose()
 {
     // Clean up test data
     var store = new UserRegistrationStore().Database.ExecuteSqlCommand("delete from UserRegistrations");
 }