public async Task ConcurrentPostTopicTest()
        {
            int numTopics         = 2;
            var managersContext   = new ManagersContext();
            var principalsContext = await PrincipalsContext.ConstructPrincipalsContext(managersContext, TestConstants.AppKey);

            var usersController = new UsersController(managersContext, principalsContext);
            var topicController = new TopicsController(managersContext, principalsContext);

            // Create a user
            var postUserResponse = await usersController.PostUser();

            // Create a func out of the PostTopic method
            Func <Task <IHttpActionResult> > postTopicFunc = () => topicController.PostTopic(PublisherType.User);

            // Fire 2 calls in parallel
            var actionResultList = await ConcurrentCalls <IHttpActionResult> .FireInParallel(postTopicFunc, numTopics);

            // Delete the topics created
            for (int i = 0; i < numTopics; i += 1)
            {
                var topicHandle = (actionResultList[i] as CreatedNegotiatedContentResult <PostTopicResponse>).Content.TopicHandle;
                await topicController.DeleteTopic(topicHandle);
            }

            // Delete the user created
            await usersController.DeleteUser();
        }
        /// <summary>
        /// Construct the principals context from an app key only. The user principal will be constructed with a null user handle
        /// </summary>
        /// <param name="managersContext">managers context</param>
        /// <param name="appKey">app key</param>
        /// <param name="identityProviderType">identity provider type (defaults to Twitter)</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public static async Task <PrincipalsContext> ConstructNullUserHandlePrincipalsContext(ManagersContext managersContext, string appKey, IdentityProviderType identityProviderType = IdentityProviderType.Twitter)
        {
            string accountId     = managersContext.HandleGenerator.GenerateShortHandle();
            var    userPrincipal = new UserPrincipal(managersContext.Log, null, identityProviderType, accountId);

            return(await PrincipalsContext.ConstructPrincipalsContext(managersContext, appKey, identityProviderType, userPrincipal));
        }
        public async Task GetSuggestionsUsers()
        {
            var managersContext   = new ManagersContext();
            var principalsContext = await PrincipalsContext.ConstructPrincipalsContext(managersContext, TestConstants.AppKey);

            var myFollowingController = new MyFollowingController(managersContext, principalsContext, FBAccessToken);

            var actionResult = await myFollowingController.GetSuggestionsUsers();

            Assert.IsInstanceOfType(actionResult, typeof(NotImplementedResult));
        }
        public async Task GetSuggestionsUsersFacebookBadAccessToken()
        {
            var managersContext   = new ManagersContext();
            var principalsContext = await PrincipalsContext.ConstructPrincipalsContext(managersContext, TestConstants.AppKey);

            var myFollowingController = new MyFollowingController(managersContext, principalsContext, FBAccessToken);

            var actionResult = await myFollowingController.GetSuggestionsUsers();

            // Check that the controller returned bad request
            Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult));
        }
        public async Task GetSuggestionsUsersFacebookValidToken()
        {
            var managersContext   = new ManagersContext();
            var principalsContext = await PrincipalsContext.ConstructPrincipalsContext(managersContext, TestConstants.AppKey);

            var myFollowingController = new MyFollowingController(managersContext, principalsContext, FBAccessToken);

            var actionResult = await myFollowingController.GetSuggestionsUsers();

            // Check that the controller returned bad request
            Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <List <UserCompactView> >));
        }
        /// <summary>
        /// Constructs controllers context with proper app and user principal.
        /// </summary>
        /// <remarks>
        /// App principal is using TestConstants.AppKey
        /// User principal is using a randomly generated user handle and a Twitter account type with a randomly generated id
        /// </remarks>
        /// <returns>controllers context</returns>
        public static async Task <ControllersContext> ConstructControllersContext()
        {
            var controllersContext = new ControllersContext();

            controllersContext.ManagersContext   = new ManagersContext();
            controllersContext.PrincipalsContext = await PrincipalsContext.ConstructPrincipalsContext(controllersContext.ManagersContext, TestConstants.AppKey);

            controllersContext.UsersController            = new UsersController(controllersContext.ManagersContext, controllersContext.PrincipalsContext);
            controllersContext.SessionsController         = new SessionsController(controllersContext.ManagersContext, controllersContext.PrincipalsContext);
            controllersContext.MyLinkedAccountsController = new MyLinkedAccountsController(controllersContext.ManagersContext, controllersContext.PrincipalsContext);

            return(controllersContext);
        }
        public async Task CreateVerifyDeleteTopicUnitTest()
        {
            var managersContext   = new ManagersContext();
            var principalsContext = await PrincipalsContext.ConstructPrincipalsContext(managersContext, TestConstants.AppKey);

            var topicController = new TopicsController(managersContext, principalsContext);

            // Create topic and check creation was successful
            var resultPostTopic = await topicController.PostTopic(PublisherType.User);

            topicController.CheckPostUserResult201(resultPostTopic);

            // Get topic and check get was successful
            string topicHandle    = (resultPostTopic as CreatedNegotiatedContentResult <PostTopicResponse>).Content.TopicHandle;
            var    resultGetTopic = await topicController.GetTopic(topicHandle);

            Assert.AreEqual(topicHandle, (resultGetTopic as OkNegotiatedContentResult <TopicView>).Content.TopicHandle);

            // Delete topic
            var resultDeleteTopic = await topicController.DeleteTopic(topicHandle);
        }