Example #1
0
        public void cannot_get_agent_profile_when_unauthorized()
        {
            // Arrange
            var request = new GetAgentProfileRequest()
            {
                Agent = new Agent()
                {
                    Name = AGENT_NAME,
                    MBox = new Uri(AGENT_MBOX)
                },
                ProfileId = PROFILE_ID
            };

            this._mockHttp
            .When(HttpMethod.Get, this.GetApiUrl("agents/profile"))
            .WithQueryString("agent", AGENT_QS)
            .WithQueryString("profileId", PROFILE_ID)
            .Respond(HttpStatusCode.Forbidden);

            // Act
            Func <Task> action = async() =>
            {
                await this._client.AgentProfiles.Get(request);
            };

            // Assert
            action.ShouldThrow <ForbiddenException>();
        }
Example #2
0
        public async Task can_get_agent_profile_with_string_document()
        {
            // Arrange
            var request = new GetAgentProfileRequest()
            {
                Agent = new Agent()
                {
                    Name = AGENT_NAME,
                    MBox = new Uri(AGENT_MBOX)
                },
                ProfileId = PROFILE_ID
            };

            this._mockHttp
            .When(HttpMethod.Get, this.GetApiUrl("agents/profile"))
            .WithQueryString("agent", AGENT_QS)
            .WithQueryString("profileId", PROFILE_ID)
            .Respond(this.GetAgentProfileResponseMessage());

            // Act
            AgentProfileDocument <string> agentProfile = await this._client.AgentProfiles.Get <string>(request);

            // Assert
            agentProfile.Should().NotBeNull();
            agentProfile.ETag.Should().Be(ETAG);
            agentProfile.LastModified.Should().Be(LAST_MODIFIED);
            agentProfile.Content.Should().NotBeNullOrEmpty();
        }
Example #3
0
        async Task <AgentProfileDocument> IAgentProfilesApi.Get(GetAgentProfileRequest request)
        {
            var options = new RequestOptions(ENDPOINT);

            this.CompleteOptions(options, request);

            HttpResponseMessage response = await this._client.GetJson(options);

            JToken content = await response.Content.ReadAsAsync <JToken>(new[] { new StrictJsonMediaTypeFormatter() });

            var document = new AgentProfileDocument();

            document.ETag         = response.Headers.ETag?.Tag;
            document.LastModified = response.Content.Headers.LastModified;
            document.Content      = content;

            return(document);
        }
Example #4
0
        async Task <AgentProfileDocument <T> > IAgentProfilesApi.Get <T>(GetAgentProfileRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            request.Validate();

            var options = new RequestOptions(ENDPOINT);

            this.CompleteOptions(options, request);

            HttpResponseMessage response = await this._client.GetJson(options);

            T content = await response.Content.ReadAsAsync <T>(new[] { new StrictJsonMediaTypeFormatter() });

            var document = new AgentProfileDocument <T>();

            document.ETag         = response.Headers.ETag?.Tag;
            document.LastModified = response.Content.Headers.LastModified;
            document.Content      = content;

            return(document);
        }
Example #5
0
 private void CompleteOptions(RequestOptions options, GetAgentProfileRequest request)
 {
     this.CompleteOptionsBase(options, request);
 }