コード例 #1
0
 public TestableUserAccountBehavior(Mock<HttpContextBase> httpContext, Mock<IUserAccountService> service)
     : base(httpContext.Object, service.Object)
 {
     Service = service;
     HttpContext = httpContext;
     User = new UserAccount { Username = "******" };
     InsideBehavior = new MockActionBehavior();
 }
コード例 #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();
        }
コード例 #3
0
 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");
 }
コード例 #4
0
            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);
            }
コード例 #5
0
        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);
        }
コード例 #6
0
        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();
        }
コード例 #7
0
ファイル: Post.cs プロジェクト: marcusswope/Hit-That-Line
 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();
 }
コード例 #8
0
 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;
 }
コード例 #9
0
 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();
 }
コード例 #10
0
            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);
            }
コード例 #11
0
            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);
            }
コード例 #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");
 }
コード例 #13
0
            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);
            }
コード例 #14
0
            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));
            }
コード例 #15
0
            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);
            }
コード例 #16
0
 public void Login(UserAccount account)
 {
     _cookieStorage.Set(UserAccount.LoginCookieName, account.DocumentKey);
     _httpContext.User = account.Principal;
 }
コード例 #17
0
 public HTLPrincipal(UserAccount account)
     : base(new GenericIdentity(account.Username), account.Roles.ToArray())
 {
     _account = account;
 }