예제 #1
0
        public async Task ReturnsExpectedDisplayName(string emailAddress, string baseUrl, string route, string requestUri, string responseContent, string expectedName)
        {
            _serviceEndpointsProvider.GetBaseUrl().Returns(baseUrl);

            _serviceEndpointsProvider.GetProfileRoute(emailAddress).Returns(route);

            var request = new HttpRequestMessage(HttpMethod.Get, requestUri);

            _requestBuilder.BuildRequestMessage(HttpMethod.Get, requestUri).Returns(request);

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(responseContent)
            };

            _httpClient.SendAsync(request).Returns(response);

            var displayName = await _profileProvider.GetDisplayName(emailAddress);

            _serviceEndpointsProvider.Received().GetBaseUrl();

            _serviceEndpointsProvider.Received().GetProfileRoute(emailAddress);

            _requestBuilder.Received().BuildRequestMessage(HttpMethod.Get, requestUri);

            await _httpClient.Received().SendAsync(request);

            displayName.IsSuccess.ShouldBeTrue();

            displayName.Value.ShouldBe(expectedName);
        }
        public async Task CallsDecoratedGetDisplayName(string emailAddress)
        {
            _decoratedProfileProvider.GetDisplayName(emailAddress).Returns(Result.Ok("anyname"));

            var result = await _exceptionHandlingProfileProvider.GetDisplayName(emailAddress);

            result.IsSuccess.ShouldBeTrue();

            await _decoratedProfileProvider.Received().GetDisplayName(emailAddress);
        }
        public async Task ReturnsExpectedProfileInfo(string emailAddress, string expectedUrl, string expectedName)
        {
            _profileProvider.GetImageUrl(emailAddress).Returns(Result.Ok(expectedUrl));

            _profileProvider.GetDisplayName(emailAddress).Returns(Result.Ok(expectedName));

            var result = await _gravatarService.GetProfileInfo(emailAddress);

            await _profileProvider.Received().GetImageUrl(emailAddress);

            await _profileProvider.Received().GetDisplayName(emailAddress);

            result.AvatarUrl.ShouldBe(expectedUrl);
            result.DisplayName.ShouldBe(expectedName);
            result.ProfileIdentifier.EmailAddress.ShouldBe(emailAddress);
        }
예제 #4
0
 public async Task <Result <string> > GetDisplayName(string profileIdentifier)
 {
     try
     {
         return(await _decoratedProfileProvider.GetDisplayName(profileIdentifier));
     }
     catch (Exception e)
     {
         return(Result.Fail <string>(e.Message));
     }
 }
예제 #5
0
        public async Task <ProfileInfo> GetProfileInfo(string profileIdentifier)
        {
            var tasks = new List <Task <Result <string> > >
            {
                _profileProvider.GetImageUrl(profileIdentifier),
                _profileProvider.GetDisplayName(profileIdentifier)
            }
            .ToArray();

            var results = await Task.WhenAll(tasks);

            return(new ProfileInfo()
            {
                ProfileIdentifier = new ProfileIdentifier()
                {
                    EmailAddress = profileIdentifier
                },
                AvatarUrl = results[0].IsSuccess ? results[0].Value : string.Empty,
                DisplayName = results[1].IsSuccess ? results[1].Value : string.Empty,
            });
        }