Exemplo n.º 1
0
        public void OAuth_given_valid_data_should_return_valid_HttpHeaderModel()
        {
            // Arrange
            var consumerKey    = "ConsumerKey";
            var consumerSecret = "ConsumerSecret";
            var accessToken    = "AccessToken";
            var tokenSecret    = "TokenSecret";
            var timeStamp      = "1579220112";
            var nonce          = "ShPKxisPFC0";

            var expected = new HttpHeaderModel()
            {
                Name  = "Authorization",
                Value = $"OAuth oauth_consumer_key=\"{consumerKey}\",oauth_token=\"{accessToken}\",oauth_signature_method=\"PLAINTEXT\",oauth_timestamp=\"{timeStamp}\",oauth_nonce=\"{nonce}\",oauth_version=\"1.0\",oauth_signature=\"{consumerSecret}%26{tokenSecret}\""
            };
            var oAuthModel = new OAuthModel()
            {
                ConsumerKey    = consumerKey,
                ConsumerSecret = consumerSecret,
                AccessToken    = accessToken,
                TokenSecret    = tokenSecret,
                TimeStamp      = timeStamp,
                Nonce          = nonce
            };
            IHttpHeaderService classUnderTest = new HttpHeaderService();

            // Act
            var actual = classUnderTest.OAuth(oAuthModel);

            // Assert
            actual.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 2
0
        public void BasicAuth_given_valid_data_should_return_valid_HttpHeaderModel()
        {
            // Arrange
            var encodedAuthorization = "dXNlcm5hbWU6cGFzc3dvcmQ=";
            var expected             = new HttpHeaderModel()
            {
                Name  = "Authorization",
                Value = $"Basic {encodedAuthorization}"
            };
            IHttpHeaderService classUnderTest = new HttpHeaderService();

            // Act
            var actual = classUnderTest.BasicAuth(encodedAuthorization);

            // Assert
            actual.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 3
0
 public void SetHeader(HttpHeaderModel httpHeaderModel)
 {
     _request.Headers.Add(httpHeaderModel.Name, httpHeaderModel.Value);
 }
Exemplo n.º 4
0
 public HttpService(OAuthModel authModel, IHttpHeaderService httpHeaderService, IJsonConvertService jsonConvertService)
 {
     _httpHeaderModel    = httpHeaderService.OAuth(authModel);
     _jsonConvertService = jsonConvertService;
 }