public TestableUserAccountBehavior(Mock<HttpContextBase> httpContext, Mock<IUserAccountService> service)
     : base(httpContext.Object, service.Object)
 {
     Service = service;
     HttpContext = httpContext;
     User = new UserAccount { Username = "******" };
     InsideBehavior = new MockActionBehavior();
 }
Esempio n. 2
0
        public void FixtureSetup()
        {
            DocumentStore = new EmbeddableDocumentStore { RunInMemory = true, UseEmbeddedHttpServer = true }.Initialize();
            Session = DocumentStore.OpenSession();
            DefaultUser = new UserAccount { Username = "******", Password = "******", EmailAddress = "*****@*****.**" };

            Session.Store(DefaultUser, DefaultUser.DocumentKey);
            Session.SaveChanges();
        }
 public void IncrementsPostCount()
 {
     var author = new UserAccount { Username = "******", EmailHash = "testhash" };
     var thread = new DiscussionThread("title", "body", "test,tags".Split(','), author);
     thread.PostCount.ShouldEqual(0);
     thread.AddPost("anotherUser");
     thread.PostCount.ShouldEqual(1);
     thread.LastActivity.ShouldBeWithinOneSecondFromNow();
     thread.LastActivityUsername.ShouldEqual("anotherUser");
 }
            public void FirstTriesToRetrieveFromHttpContext()
            {
                var service = TestableUserAccountService.Build();
                var userAccount = new UserAccount { Username = "******" };
                var htlPrincipal = new HTLPrincipal(userAccount);

                service.HttpContext.SetupGet(x => x.User).Returns(htlPrincipal);

                service.GetCurrent().ShouldEqual(userAccount);
            }
        public void GetsFromServiceAndSets()
        {
            var binder = TestableUserAccountPropertyBinder.Build();
            var account = new UserAccount();
            binder.Service.Setup(x => x.GetCurrent()).Returns(account);

            binder.Bind(typeof(UserAccountBindingModel).GetProperty("UserAccount"), binder.Context.Object);

            binder.Model.UserAccount.ShouldEqual(account);
        }
        public void GetsFromServiceAndSetsPrincipal()
        {
            var behavior = TestableUserAccountBehavior.Build();
            var account = new UserAccount { Username = "******" };
            behavior.Service.Setup(x => x.GetCurrent()).Returns(account);

            behavior.Invoke();

            behavior.HttpContext.VerifySet(x => x.User = account.Principal);
            behavior.MockInsideBehavior.VerifyInvoked();
        }
Esempio n. 7
0
 public Post(string markDownText, string discussionThreadId, UserAccount userAccount)
 {
     MarkdownText = markDownText;
     DisplayText = markDownText.Transform();
     ThreadId = discussionThreadId;
     Username = userAccount.Username;
     CreatedOn = DateTime.UtcNow;
     LastActivity = DateTime.UtcNow;
     UpVotes = 1;
     calculateScore();
 }
 public UserAccount CreateNew(RegisterCommand command)
 {
     var account = new UserAccount
                       {
                           EmailAddress = command.EmailAddress,
                           EmailHash = createEmailhash(command.EmailAddress),
                           Password = command.Password,
                           Username = command.Username
                       };
     account.Roles.Add(UserAccount.BasicUserRole);
     _session.Store(account, UserAccount.Key(account.Username));
     Login(account);
     return account;
 }
 public DiscussionThread(string title, string body, IEnumerable<string> tags, UserAccount author)
 {
     Id = "threads/";
     Title = title;
     MarkdownBody = body;
     DisplayBody = body.Transform();
     CreatedOn = DateTime.UtcNow;
     LastActivity = DateTime.UtcNow;
     UpVotes = 1;
     Tags = tags.ToList();
     AuthorUsername = author.Username;
     AuthorProfilePictureUrl = author.ProfilePictureUrl;
     calculateScore();
 }
            public void InitializesPropertiesCorrectly()
            {
                var title = "New Thread";
                var body = "This is a body. And this is **really important**.";
                var author = new UserAccount { Username = "******", EmailHash = "testhash" };
                var thread = new DiscussionThread(title, body, "test,tags".Split(','), author);

                thread.Id.ShouldEqual("threads/");
                thread.Title.ShouldEqual(title);
                thread.MarkdownBody.ShouldEqual(body);
                thread.DisplayBody.ShouldEqual("<p>This is a body. And this is <strong>really important</strong>.</p>\n");
                thread.CreatedOn.ShouldBeWithinOneSecondFromNow();
                thread.LastActivity.ShouldBeWithinOneSecondFromNow();
                thread.UpVotes.ShouldEqual(1);
                thread.Score.ShouldBeGreaterThan(0);
                thread.Tags[0].ShouldEqual("test");
                thread.Tags[1].ShouldEqual("tags");
                thread.AuthorProfilePictureUrl.ShouldEqual(author.ProfilePictureUrl);
                thread.AuthorUsername.ShouldEqual(author.Username);
            }
            public void IncrementsVoteCountAndRecalculatesTheScore()
            {
                var author = new UserAccount { Username = "******", EmailHash = "testhash" };
                var thread = new DiscussionThread("title", "body", "test,tags".Split(','), author);
                var originalScore = thread.Score;
                thread.UpVotes.ShouldEqual(1);
                thread.DownVotes.ShouldEqual(0);

                thread.VoteUp();
                thread.UpVotes.ShouldEqual(2);
                thread.DownVotes.ShouldEqual(0);
                thread.Score.ShouldBeGreaterThan(originalScore);

                thread.VoteDown();
                thread.UpVotes.ShouldEqual(2);
                thread.DownVotes.ShouldEqual(1);
                thread.Score.ShouldEqual(originalScore);

                thread.NetVotes.ShouldEqual(1);
            }
Esempio n. 12
0
 public void ReturnsGravatarUrlWithEmailHash()
 {
     var account = new UserAccount { EmailHash = "someHash" };
     account.ProfilePictureUrl.ShouldEqual("http://www.gravatar.com/avatar/someHash?d=identicon&r=pg&s=60");
 }
            public void ThenTriesToGetFromCookieValue()
            {
                var service = TestableUserAccountService.Build();
                var account = new UserAccount { Username = "******" };

                service.Cookies.Setup(x => x.Contains(UserAccount.LoginCookieName)).Returns(true);
                service.Cookies.Setup(x => x.Get(UserAccount.LoginCookieName, true)).Returns(account.DocumentKey);
                service.Session.Setup(x => x.Load<UserAccount>(account.DocumentKey)).Returns(account);

                service.GetCurrent().ShouldEqual(account);
                service.HttpContext.VerifySet(x => x.User = account.Principal);
            }
            public void RemovesCookieIfNotFound()
            {
                var service = TestableUserAccountService.Build();
                var account = new UserAccount { Username = "******" };

                service.Cookies.Setup(x => x.Contains(UserAccount.LoginCookieName)).Returns(true);
                service.Cookies.Setup(x => x.Get(UserAccount.LoginCookieName, true)).Returns(account.DocumentKey);
                service.Session.Setup(x => x.Load<UserAccount>(account.DocumentKey)).Returns(null as UserAccount);

                service.GetCurrent().ShouldEqual(null);
                service.HttpContext.VerifySet(x => x.User = account.Principal, Times.Never());
                service.Cookies.Verify(x => x.Remove(UserAccount.LoginCookieName));
            }
            public void SetsCookieAndPrincipal()
            {
                var service = TestableUserAccountService.Build();
                var account = new UserAccount { Username = "******" };

                service.Login(account);

                service.Cookies.Verify(x => x.Set(UserAccount.LoginCookieName, account.DocumentKey));
                service.HttpContext.VerifySet(x => x.User = account.Principal);
            }
 public void Login(UserAccount account)
 {
     _cookieStorage.Set(UserAccount.LoginCookieName, account.DocumentKey);
     _httpContext.User = account.Principal;
 }
Esempio n. 17
0
 public HTLPrincipal(UserAccount account)
     : base(new GenericIdentity(account.Username), account.Roles.ToArray())
 {
     _account = account;
 }