public void Cannot_Register_with_null_client()
        {
            var sut = new TwitterUserTracker();
            var ex  = Record.Exception(() => sut.Register(Guid.NewGuid(), null));

            ex.Should().BeOfType <ArgumentNullException>();
        }
        public void Cannot_Register_with_invalid_Guid()
        {
            var client = A.Fake <ITwitterAuthenticatedClient>();
            var sut    = new TwitterUserTracker();
            var ex     = Record.Exception(() => sut.Register(new Guid(), client));

            ex.Should().BeOfType <ArgumentOutOfRangeException>();
        }
        public void Can_register_multiple_sessions_from_the_same_user()
        {
            const long TwitterUserId   = 123L;
            var        sessionid       = Guid.NewGuid();
            var        secondSessionId = Guid.NewGuid();

            var client = A.Fake <ITwitterAuthenticatedClient>();

            A.CallTo(() => client.UserId).Returns(TwitterUserId);
            var sut = new TwitterUserTracker();

            sut.Register(sessionid, client);
            sut.Register(secondSessionId, client);

            var result = sut.GetAuthenticatedTwitterClientForUser(TwitterUserId);

            result.Should().NotBeNull();
            result.UserId.Should().Be(TwitterUserId);
        }
        public void When_registered_Can_retrieve_TwitterClient_from_UserId()
        {
            const long TwitterUserId = 123L;
            var        sessionid     = Guid.NewGuid();

            var client = A.Fake <ITwitterAuthenticatedClient>();

            A.CallTo(() => client.UserId).Returns(TwitterUserId);
            var sut = new TwitterUserTracker();

            sut.Register(sessionid, client);

            var result = sut.GetAuthenticatedTwitterClientForUser(TwitterUserId);

            result.Should().NotBeNull();
            result.UserId.Should().Be(TwitterUserId);
        }
        public void When_registered_Can_retrieve_UserIdentity_from_Session_Id()
        {
            const long TwitterUserId = 123L;
            var        sessionid     = Guid.NewGuid();

            var client = A.Fake <ITwitterAuthenticatedClient>();

            A.CallTo(() => client.UserId).Returns(TwitterUserId);

            var context = new NancyContext();
            var sut     = new TwitterUserTracker();

            sut.Register(sessionid, client);

            var user = sut.GetUserFromIdentifier(sessionid, context);

            user.Should().NotBeNull();
            user.Should().BeOfType <TwitterUser>();
            user.As <TwitterUser>().TwitterUserId.Should().Be(TwitterUserId);
        }