Ejemplo n.º 1
0
        public async Task IssueNonBatch()
        {
            // instantiate the handler
            DelegatingHandler[]            handlers    = new DelegatingHandler[1];
            InstrumentedHttpMessageHandler testHandler = new InstrumentedHttpMessageHandler();

            handlers[0] = testHandler;

            // instantiate the client
            SocialPlusClient myClient = new SocialPlusClient(TestConstants.ServerApiBaseUrl, handlers);

            // request server build info
            HttpOperationResponse <GetBuildInfoResponse> buildsResponse = await myClient.Config.GetBuildInfoWithHttpMessagesAsync();

            VerifyBuildsResponse(buildsResponse);

            // login
            PostUserRequest postUserRequest = new PostUserRequest(InstanceId, "Bob", "Smith", "mybio", null);
            string          userHandle      = HandleGenerator.GenerateShortHandle();
            string          auth            = await TestUtilities.GetAADAuth(userHandle);

            HttpOperationResponse <PostUserResponse> postUserResponse = await myClient.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : auth);

            VerifyPostUserResponse(postUserResponse);

            // delete login
            auth = AuthHelper.CreateSocialPlusAuth(postUserResponse.Body.SessionToken);
            HttpOperationResponse <object> deleteUserResponse = await myClient.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            Assert.IsTrue(deleteUserResponse.Response.IsSuccessStatusCode);
        }
Ejemplo n.º 2
0
        public async Task IssueManyBatches()
        {
            // instantiate the handlers
            DelegatingHandler[] handlers = new DelegatingHandler[2];
            Uri batchURL = new Uri(TestConstants.ServerApiBaseUrl.OriginalString + "batch");
            BatchHttpMessageHandler        batchHandler = new BatchHttpMessageHandler(HttpMethod.Post, batchURL);
            InstrumentedHttpMessageHandler testHandler  = new InstrumentedHttpMessageHandler();

            handlers[0] = batchHandler; // this will be the inner handler
            handlers[1] = testHandler;  // this will be the outer handler

            // instantiate the client, passing in the handler
            SocialPlusClient myClient = new SocialPlusClient(TestConstants.ServerApiBaseUrl, handlers);

            // request server build info many times
            int numRequests = 50;
            List <Task <HttpOperationResponse <GetBuildInfoResponse> > > getBuildsTasks = new List <Task <HttpOperationResponse <GetBuildInfoResponse> > >();

            for (int i = 0; i < numRequests; i++)
            {
                getBuildsTasks.Add(myClient.Config.GetBuildInfoWithHttpMessagesAsync());
            }

            // issue the batch
            await batchHandler.IssueBatch();

            // verify server build info responses
            for (int i = 0; i < numRequests; i++)
            {
                HttpOperationResponse <GetBuildInfoResponse> buildsResponse = await getBuildsTasks[i];
                VerifyBuildsResponse(buildsResponse);
            }
        }