/// <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 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 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, but a user principal whose user handle is null. /// </summary> /// <remarks> /// App principal is using TestConstants.AppKey /// User principal is using a null user handle and an MSA account with a randomly generated id /// </remarks> /// <returns>controllers context</returns> public static async Task <ControllersContext> ConstructControllersContextWithNullUserHandle() { var controllersContext = new ControllersContext(); controllersContext.ManagersContext = new ManagersContext(); controllersContext.PrincipalsContext = await PrincipalsContext.ConstructNullUserHandlePrincipalsContext(controllersContext.ManagersContext, TestConstants.AppKey, IdentityProviderType.Microsoft); 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); }
/// <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); }
/// <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(); }
/// <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(); }
/// <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; }
/// <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); }