public void Initialize() {
            session.BeginTransaction();
            userRepository = new UserRepository();
            identityService = new IdentityService<User>(userRepository);

            password = "******";
            
            user = new User
            {
                Name = "John Doe",
                BirthDate = new DateTime(1982, 8, 1),
                Email = "*****@*****.**",
                Username = "******",
                Address = new Address { City = "São paulo", StreetName = "name", Number = "123B", State = "SP", ZipCode = "03423-234" }
            };

            user2 = new User
            {
                Name = "Fulano",
                BirthDate = DateTime.Now,
                Email = "*****@*****.**",
                Password = "******",
                Username = "******",
                Address = new Address { City = "São paulo", StreetName = "name", Number = "123B", State = "SP", ZipCode = "03423-234" }
            };
        }
		public void Initialize()
		{
			var context = ContextFactory.GetContext();
			this.WebLogs = new GenericRepository<WebLog>(context);

			var owner = new User { Name = "user" };
			this.WebLogs.SaveOrUpdate(new WebLog { CreatedAt = DateTime.Today, Title = "Blog 1", Collaborators = new[] { owner } });
			this.WebLogs.SaveOrUpdate(new WebLog { CreatedAt = DateTime.Today, Title = "Blog 2", Collaborators = new[] { owner } });

			this.WebLogs.SaveChanges();
		}
        public void Initialize()
        {


            var session = ApplicationManager.SessionFactory.OpenSession();
            var user = new User { Username="******", Name = "my name", Email = "*****@*****.**", Password = "******", Address = new Address { City = "São paulo", StreetName="name", Number="123B", State="SP", ZipCode="03423-234" } };
            user.AddBlog(new WebLog { Title = "My blog", Creator=user });
            session.Save(user);
            session.Flush();
            session.Close();

            session = ApplicationManager.SessionFactory.OpenSession();
            ThreadStaticSessionContext.Bind(session);
        }
예제 #4
0
        public ActionResult InsertPosts()
        {
            var user = new User { ID = 32, Name="oi" };
            for (Int32 i = 0; i < 5; i++) {
                webLogs[i] = new WebLog { ID = i + 32, Title = "titulo " + i, CreatedAt=DateTime.Now, Collaborators = new[] { user } };
                this.webLogRepository.SaveOrUpdate(webLogs[i]);
            }

            for (Int32 i = 0; i < 100; i++)
            {
                CreateRandomPost(i);
            }
            this.webLogRepository.SaveChanges();
            return Content("Posts inseridos");
        }
예제 #5
0
        public void Initialize()
        {
            var context = new EntityFrameworkRepositoryContext(new BlogContext());
            WebLogs = new GenericRepository<WebLog>(context);

            var title = Guid.NewGuid().ToString();

            var user = new User { Name = "user " + title };
            var webLog = new WebLog { Title = webLogID, CreatedAt = DateTime.Now };
            var post = new Post { Title = postID, Text = "oi", CreatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now, PublishedAt = DateTime.Now };

            webLog.Collaborators.Add(user);
            user.AddBlog(webLog);
            webLog.Posts.Add(post);
            post.WebLog = webLog;

            WebLogs.SaveOrUpdate(webLog);
        }
		public void SelectWithLambdaExpressions()
		{
            var title = Guid.NewGuid().ToString();
            var user = new User { Name = "user " + title };
            var webLog = new WebLog { Title = "weblog " + title, CreatedAt = DateTime.Now };
            var post = new Post { Title = title, Text = "oi", CreatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now, PublishedAt = DateTime.Now };

            webLog.Collaborators.Add(user);
            user.AddBlog(webLog);
            webLog.Posts.Add(post);
            post.WebLog = webLog;

            webLogRepository.SaveOrUpdate(webLog);
            webLogRepository.SaveChanges();

            var posts = (from w in webLogRepository.Query()
                            from p in w.Posts
                            where p.Title == title
                            select p).ToList(); 
            Assert.AreEqual(1, posts.Count);
		}
        public ActionResult Register(RegisterModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return View(viewModel);
            }

            User user = new User();
            user.Name = viewModel.Name;
            user.Username = viewModel.Username;
            user.Email = viewModel.Email;

            if (viewModel.Password != viewModel.ConfirmPassword)
            {
                ModelState.AddModelError("PASSWORD_AND_CONFIRM_DONT_MATCH", "");
            }
            else
            {
                var result = this.identityService.Register(user, u => u.Username, u => u.Email, u => u.Password, viewModel.Password);

                if (result == RegisterStatus.Success)
                {
                    // TODO: encapsulate this in a service
                    System.Web.Security.FormsAuthentication.RedirectFromLoginPage(user.Username, false); // user log on
                    return RedirectToAction("Index", "Home");
                }

                if (result == RegisterStatus.UsernameAlreadyExists)
                {
                    ModelState.AddModelError("USER_ALREADY_EXISTS", "");
                }

                if (result == RegisterStatus.EmailAlreadyExists)
                {
                    ModelState.AddModelError("EMAIL_ALREADY_EXISTS", "");
                }
            }

            return View(viewModel);
        }
        public void Register_with_valid_data_inserts_user_into_database_and_returns_success()
        {
            var password = "******";
            var user = new User
            {
                Name = "John Doe",
                BirthDate = new DateTime(1982, 8, 1),
                Email = "*****@*****.**",
                Username = "******",
                Address = new Address { City = "São paulo", StreetName="name", Number="123B", State="SP", ZipCode="03423-234" }
            };

            try
            {
                Assert.AreEqual(RegisterStatus.Success, identityService.Register(user, u => u.Username, u => u.Email, u => u.Password, password));
            }
            catch(Exception e)
            {
                session.Transaction.Rollback();
                throw;
            }
        }
 public void Register_with_null_data_throws_argumentnullexception()
 {
     user = new User();
     identityService.Register(user, u => u.Username, u => u.Email, u => u.Password, password);
 }
        public void Register_with_existing_username_returns_ExistingUsername_state()
        {
            var user = new User
            {
                Name = "John Doe",
                BirthDate = new DateTime(1982, 8, 1),
                Email = "*****@*****.**",
                Password = "******",
                Username = "******",
                Address = new Address { City = "São paulo", StreetName = "name", Number = "123B", State = "SP", ZipCode = "03423-234" }
            };

            userRepository.SaveOrUpdate(user);
            var user2 = new User
            {
                Name = "Fulano",
                BirthDate = DateTime.Now,
                Email = "*****@*****.**",
                Password = "******",
                Username = "******",
                Address = new Address { City = "São paulo", StreetName = "name", Number = "123B", State = "SP", ZipCode = "03423-234" }
            };

            try
            {
                Assert.AreEqual(RegisterStatus.UsernameAlreadyExists, identityService.Register(user2, u => u.Username, u => u.Email, u => u.Password, "minhasenha"));
            }
            catch (Exception e)
            {
                session.Transaction.Rollback();
                throw;
            }
        }
        public void GenerateValidationKey_for_existing_email_generates_key_and_returns_it() 
        {
            var password = "******";
            var user = new User
            {
                Name = "John Doe",
                BirthDate = new DateTime(1982, 8, 1),
                Email = "*****@*****.**",
                Username = "******",
                Address = new Address { City = "São paulo", StreetName = "name", Number = "123B", State = "SP", ZipCode = "03423-234" }
            };

            try
            {
                Assert.AreEqual(RegisterStatus.Success, identityService.Register(user, u => u.Username, u => u.Email, u => u.Password, password));
            }
            catch (Exception e)
            {
                session.Transaction.Rollback();
                throw;
            }

            Assert.IsNotNull(identityService.GenerateValidationKey("*****@*****.**"));
        }
        public void User_changing_password_with_incorrect_current_password_returns_IncorrectCurrentPassword() 
        {
            var password = "******";
            var user = new User
            {
                Name = "John Doe",
                BirthDate = new DateTime(1982, 8, 1),
                Email = "*****@*****.**",
                Username = "******",
                Address = new Address { City = "São paulo", StreetName = "name", Number = "123B", State = "SP", ZipCode = "03423-234" }
            };

            try
            {
                Assert.AreEqual(RegisterStatus.Success, identityService.Register(user, u => u.Username, u => u.Email, u => u.Password, password));
            }
            catch (Exception e)
            {
                session.Transaction.Rollback();
                throw;
            }

            Assert.AreEqual(PasswordChangeStatus.InvalidCurrentPassword, identityService.ChangePassword("john_doe", "wrongPassword", "newPassword"));
        }
        public void Validate_non_existing_user_returns_false()
        {
            var password = "******";
            var user = new User
            {
                Name = "John Doe",
                BirthDate = new DateTime(1982, 8, 1),
                Email = "*****@*****.**",
                Username = "******",
                Address = new Address { City = "São paulo", StreetName = "name", Number = "123B", State = "SP", ZipCode = "03423-234" }
            };

            try
            {
                Assert.AreEqual(RegisterStatus.Success, identityService.Register(user, u => u.Username, u => u.Email, u => u.Password, password));
            }
            catch (Exception e)
            {
                session.Transaction.Rollback();
                throw;
            }

            Assert.IsFalse(identityService.Validate("huckleberry finn", "something"));
        }
        public void Register_with_null_data_throws_argumentnullexception()
        {
            var password = "******";
            var user = new User();

            try
            {
                identityService.Register(user, u => u.Username, u => u.Email, u => u.Password, password);

                Assert.Fail();
            }
            catch (ArgumentNullException e)
            {
                Assert.IsInstanceOfType(e, typeof(ArgumentNullException));
            }
            catch 
            {
                session.Transaction.Rollback();
                throw;
            }
        }