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();
        }
        public void AuthParserValidAuthHeaderParameters()
        {
            var    managersContext   = new ManagersContext();
            var    commonAuthManager = new PrivateObject(managersContext.CommonAuthManager);
            string authParameter     = null;
            Dictionary <string, string> authDictionary = null;

            object[] args = null;

            authParameter  = "ak=value";
            authDictionary = new Dictionary <string, string>();
            args           = new object[2] {
                authParameter, authDictionary
            };
            commonAuthManager.Invoke("ParseAuthParameter", args);
            Assert.IsTrue(authDictionary.Count == 1);
            Assert.AreEqual("value", authDictionary["ak"]);

            authParameter  = "ak=value|";
            authDictionary = new Dictionary <string, string>();
            args           = new object[2] {
                authParameter, authDictionary
            };
            commonAuthManager.Invoke("ParseAuthParameter", args);
            Assert.IsTrue(authDictionary.Count == 1);
            Assert.AreEqual("value", authDictionary["ak"]);

            authParameter  = "ak = value|";
            authDictionary = new Dictionary <string, string>();
            args           = new object[2] {
                authParameter, authDictionary
            };
            commonAuthManager.Invoke("ParseAuthParameter", args);
            Assert.IsTrue(authDictionary.Count == 1);
            Assert.AreEqual("value", authDictionary["ak"]);

            authParameter  = "ak = va=lue";
            authDictionary = new Dictionary <string, string>();
            args           = new object[2] {
                authParameter, authDictionary
            };
            commonAuthManager.Invoke("ParseAuthParameter", args);
            Assert.IsTrue(authDictionary.Count == 1);
            Assert.AreEqual("va=lue", authDictionary["ak"]);

            authParameter  = "ak=value|tk==value2";
            authDictionary = new Dictionary <string, string>();
            args           = new object[2] {
                authParameter, authDictionary
            };
            commonAuthManager.Invoke("ParseAuthParameter", args);
            Assert.IsTrue(authDictionary.Count == 2);
            Assert.AreEqual("value", authDictionary["ak"]);
            Assert.AreEqual("=value2", authDictionary["tk"]);
        }
        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>
 /// Initializes a new instance of the <see cref="SessionsController"/> class
 /// </summary>
 /// <param name="managersContext">managers context</param>
 /// <param name="principalsContext">principals context</param>
 public SessionsController(ManagersContext managersContext, PrincipalsContext principalsContext)
     : base(
         managersContext.Log,
         managersContext.IdentitiesManager,
         managersContext.SessionTokenManager,
         managersContext.UsersManager,
         managersContext.AppsManager,
         managersContext.ApplicationMetrics)
 {
     this.appPrincipal  = principalsContext.AppPrincipal;
     this.userPrincipal = principalsContext.UserPrincipal;
     this.guid          = Guid.NewGuid();
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TopicsController"/> class
 /// </summary>
 /// <param name="managersContext">managers context</param>
 /// <param name="principalsContext">principals context</param>
 public TopicsController(ManagersContext managersContext, PrincipalsContext principalsContext)
     : base(
         managersContext.Log,
         managersContext.UsersManager,
         managersContext.TopicsManager,
         managersContext.AppsManager,
         managersContext.PopularTopicsManager,
         managersContext.ViewsManager,
         managersContext.TopicNamesManager,
         managersContext.HandleGenerator)
 {
     this.appPrincipal  = principalsContext.AppPrincipal;
     this.userPrincipal = principalsContext.UserPrincipal;
     this.guid          = Guid.NewGuid();
 }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MyLinkedAccountsController"/> class
 /// </summary>
 /// <param name="managersContext">managers context</param>
 /// <param name="principalsContext">principals context</param>
 public MyLinkedAccountsController(ManagersContext managersContext, PrincipalsContext principalsContext)
     : base(
         managersContext.Log,
         managersContext.IdentitiesManager,
         managersContext.UsersManager,
         managersContext.AppsManager,
         managersContext.ViewsManager,
         managersContext.SessionTokenManager)
 {
     this.appPrincipal    = principalsContext.AppPrincipal;
     this.userPrincipal   = principalsContext.UserPrincipal;
     this.guid            = Guid.NewGuid();
     this.handleGenerator = managersContext.HandleGenerator;
     this.log             = managersContext.Log;
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MyFollowingController"/> class
 /// </summary>
 /// <param name="managersContext">managers context</param>
 /// <param name="principalsContext">principals context</param>
 /// <param name="authHeader">authentication header</param>
 public MyFollowingController(ManagersContext managersContext, PrincipalsContext principalsContext, string authHeader)
     : base(
         managersContext.Log,
         managersContext.RelationshipsManager,
         managersContext.UsersManager,
         managersContext.TopicsManager,
         managersContext.ActivitiesManager,
         managersContext.ViewsManager,
         managersContext.AuthManager,
         managersContext.HandleGenerator)
 {
     this.appPrincipal  = principalsContext.AppPrincipal;
     this.userPrincipal = principalsContext.UserPrincipal;
     this.guid          = Guid.NewGuid();
     this.authHeader    = authHeader;
 }
        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);
        }
        /// <summary>
        /// Construct the principals context from an app key only. A user principal will be constructed by default
        /// </summary>
        /// <param name="managersContext">managers context</param>
        /// <param name="appKey">app key</param>
        /// <param name="identityProviderType">identity provider type (defaults to Twitter)</param>
        /// <param name="userPrincipal">user principal</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public static async Task <PrincipalsContext> ConstructPrincipalsContext(ManagersContext managersContext, string appKey, IdentityProviderType identityProviderType = IdentityProviderType.Twitter, UserPrincipal userPrincipal = null)
        {
            // Read app profile
            var appLookupEntity = await managersContext.AppsManager.ReadAppByAppKey(appKey);

            if (appLookupEntity == null)
            {
                throw new InvalidOperationException("No app key found in our tables.");
            }

            // App principal is ready to be created
            var appPrincipal = new AppPrincipal(appLookupEntity.AppHandle, appKey);

            // Create user principal if the one passed in is null.
            if (userPrincipal == null)
            {
                string userHandle = managersContext.HandleGenerator.GenerateShortHandle();
                string accountId  = managersContext.HandleGenerator.GenerateShortHandle();
                userPrincipal = new UserPrincipal(managersContext.Log, userHandle, identityProviderType, accountId);
            }

            return(new PrincipalsContext(appPrincipal, userPrincipal));
        }
        public void AuthParserInvalidAuthHeaderParameters()
        {
            var    managersContext   = new ManagersContext();
            var    commonAuthManager = new PrivateObject(managersContext.CommonAuthManager);
            string authParameter     = null;
            Dictionary <string, string> authDictionary = null;

            object[] args = null;

            try
            {
                authParameter  = (string)null;
                authDictionary = new Dictionary <string, string>();
                args           = new object[2] {
                    authParameter, authDictionary
                };
                commonAuthManager.Invoke("ParseAuthParameter", args);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("Auth header parameter is null or empty."));
            }

            try
            {
                authParameter  = string.Empty;
                authDictionary = new Dictionary <string, string>();
                args           = new object[2] {
                    authParameter, authDictionary
                };
                commonAuthManager.Invoke("ParseAuthParameter", args);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("Auth header parameter is null or empty."));
            }

            try
            {
                authParameter  = " ";
                authDictionary = new Dictionary <string, string>();
                args           = new object[2] {
                    authParameter, authDictionary
                };
                commonAuthManager.Invoke("ParseAuthParameter", args);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("Auth header parameter is null or empty."));
            }

            try
            {
                authParameter  = "3uvFaCx05pp";
                authDictionary = new Dictionary <string, string>();
                args           = new object[2] {
                    authParameter, authDictionary
                };
                commonAuthManager.Invoke("ParseAuthParameter", args);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("Auth header parameter is malformed. It includes a string delimited by '|' but lacking a '=' separator."));
            }

            try
            {
                authParameter  = "|";
                authDictionary = new Dictionary <string, string>();
                args           = new object[2] {
                    authParameter, authDictionary
                };
                commonAuthManager.Invoke("ParseAuthParameter", args);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("Auth header parameter is null or empty."));
            }

            try
            {
                authParameter  = "||";
                authDictionary = new Dictionary <string, string>();
                args           = new object[2] {
                    authParameter, authDictionary
                };
                commonAuthManager.Invoke("ParseAuthParameter", args);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("Auth header parameter is null or empty."));
            }

            try
            {
                authParameter  = "=||=";
                authDictionary = new Dictionary <string, string>();
                args           = new object[2] {
                    authParameter, authDictionary
                };
                commonAuthManager.Invoke("ParseAuthParameter", args);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("Auth header parameter is malformed. It includes a string delimited by '|' but lacking a '=' separator."));
            }

            authParameter  = "=|=";
            authDictionary = new Dictionary <string, string>();
            args           = new object[2] {
                authParameter, authDictionary
            };
            commonAuthManager.Invoke("ParseAuthParameter", args);
            Assert.IsTrue(authDictionary.Count == 0);
        }
        /// <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));
        }