예제 #1
0
        public void AddAuthHeader_WithBasicAuthentication_AddsCorrectAuthorisationHeader()
        {
            //Arrange
            var    rest          = new RestClient(ValidKey);
            ApiKey key           = ApiKey.Parse(ValidKey);
            var    request       = new AblyRequest("/test", HttpMethod.Get, Protocol.Json);
            var    expectedValue = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(key.ToString()));

            //Act
            rest.AddAuthHeader(request);

            //Assert
            var authHeader = request.Headers.First();

            Assert.Equal("Authorization", authHeader.Key);

            Assert.Equal(expectedValue, authHeader.Value);
        }
예제 #2
0
        public void SetupSampleStats()
        {
            var lastInterval = StatsAcceptanceTests.StartInterval;
            var interval1    = lastInterval - TimeSpan.FromMinutes(120);
            var interval2    = lastInterval - TimeSpan.FromMinutes(60);
            var interval3    = lastInterval;
            var json         = File.ReadAllText("StatsFixture.json");

            json = json.Replace("[[Interval1]]", interval1.ToString("yyyy-MM-dd:HH:mm"));
            json = json.Replace("[[Interval2]]", interval2.ToString("yyyy-MM-dd:HH:mm"));
            json = json.Replace("[[Interval3]]", interval3.ToString("yyyy-MM-dd:HH:mm"));

            RestClient     restClient = new RestClient(TestData.keys.First().keyStr);
            AblyHttpClient client     = new AblyHttpClient(TestsSetup.TestData.restHost, null, TestsSetup.TestData.tls, null);
            AblyRequest    request    = new AblyRequest("/stats", HttpMethod.Post);

            request.Headers.Add("Accept", "application/json");
            request.Headers.Add("Content-Type", "application/json");
            restClient.AddAuthHeader(request);
            request.RequestBody = json.GetBytes();

            var response = client.Execute(request);
        }